🆕 (Re) Introducing the Stopwatch Component

Hello All,

Ben here from the Glide engineering team. Excited to introduce a new pages stopwatch component. It will be located in the Advanced section, and is behind an experiment flag.

In its current MVP state, it is super simple and only tracks the seconds elapsed.

Most importantly, and the reason AI was not able to re-create this component was that it can remember when the watch started even when the app is closed. That means you can leave, return to the watch and the time will continue where you left off – unless you stopped it first, of course.

What other features should we consider in the future? We can’t field all the requests, but would love to hear what other folks are/were doing with the stopwatch. We are of course considering the previous discussion from last year here: ⏱ Stopwatch in Glide Apps

Here’s a sneak peek - the progress bar is a custom AI component.

Cheers,
Ben & The Glide Engineering Team

9 Likes

This is a nice to have!

Thanks for this re-addition!

It’s very cool … I built something that did the reverse for an app. A countdown timer essentially, with notifications when time was up. Would be nice if the component could both count up (time elapsed) and down (time left on a timer).

1 Like

Looks great @benipsen this will be super helpful.

One little feature I know a number have been waiting for is the option to sort groups on tables and lists as well as sorting the data. This would allow us to maintain the correct/desired order of both the groups and the data.

Here’s my take on it using a custom AI component for a stopwatch, which also includes a countdown timer. There should be only three columns in the table (RowID, JSON, and one experimental to extract duration from the json). The template app seems to be holding on to old columns and I can’t get them to remove when I publish. They aren’t in my copy, but they still exist in the template. Ignore the old unused columns because they were for a previous version of this I did a while back.

At this point making any use of the data would require extracting data out of the JSON object. Both the Stopwatch and Countdown timer could also be controlled outside of the component by manipulating the appropriate JSON.

3 Likes

Where can I find the ‘advance section’ and locate the stopwatch component?

Does this mean there will be a column that stores seconds remaining and is updated every second?

@ohad you need to enable it in your team Preview settings.

@Simon_Hill Yes it does update the table every second with the accumulated seconds. From what I can tell, it only updates the column if the screen with the stopwatch is in view, although the stopwatch will continue to run until stopped.

Is it just me or does the native stopwatch seem slow. It ticks off a second every 10 seconds.

PS, I modified my template that I linked above. I added a project time tracking tab to track time while working on a project with a running history. It’s something I recently added to a personal project of mine. I also simplified the AI prompts so they are easier to copy into other projects.

4 Likes

Is it just me or the native stopwatch isn’t accurate?

It’s accurate for the first second after you open the screen that has the stopwatch. It does count accurately behind the scenes, but the column only updates while the stopwatch is visible. However it’s terribly slow while visible. Leaving the screen and coming back while it’s running catches it back up, but goes back to counting 1 second every 10 seconds.

If you leave and re-enter the screen every second, it will be accurate.

I used your ai stopwatch! It is so much better!

1 Like

Thanks everyone for the feedback.

In the template linked by @Jeff_Hager it is definitely slow and does appear to nearly count the tenths as the seconds. There were some late changes to the feature preview that are likely to have introduced that problem. We’ll have a look.

4 Likes

Let us know for updates :star_struck:

1 Like

If anybody is interested, I’ve republished my template linked above. I made changes specifically to the stopwatch/countdown. I fixed a few bugs, cleaned up and simplified the look of the component, added parameters to show or hide each tab, added a parameter to change decimal precision for milliseconds, and added an optional audio parameter to play a sound when the countdown reaches zero.

3 Likes

How did you go about generating the HTML/JavaScript for this?
I’m interested in the Countdown aspect of it, but I would want to customise it significantly. How would I best approach that? (without trying to reverse engineer the code).

A majority of it was done just chatting with the AI. Unfortunately I don’t have any of the specific prompts anymore.

I started with the stopwatch. Knowing how the stopwatch worked in classic apps, I prompted it to function exactly the same, but forced it to use a single JSON object instead of two separate fields. The AI decided how the object would be laid out.

To keep things simple, I instructed it to use Unix time to store the datetime. With that, any start/end times and durations are stored in milliseconds.

I asked the AI to create an empty JSON object if it’s null. That part is important if it’s linked to a column that is empty initially. That way it will build the object as needed.

The countdown was a little more work. I don’t think it was terribly complicated, but I had less of a plan going into it compared to the stopwatch. A lot of back and forth with the AI to debug, fix, and try things. There’s a little more involved with the addition of the dropdowns. I didn’t really have a plan as far as how the JSON would be laid out for that, but the AI did pretty good at coming up with it. A lot of the JSON built out automatically as I asked for different features. It did help that it had the context of the stopwatch to build off of.

Things can be pulled out of the JSON object using Query JSON. I included one example in the table that uses JSONnata to convert the stopwatch duration from milliseconds to seconds. Could be converted to whatever you want.

The component could be modified to force the JSON to update at regular intervals, or to update another column with a value at regular intervals.

The JSON can also be manipulated outside of the component to start, stop, set, reset anything within the component.

Eventually I hit a point where the component would be maxed out. (There must be some kind of size limit before the component gets corrupt and pieces of it stop working. I seem to find that limit a lot.) That led to a lot of trial and error with my prompts to get it to do what I wanted without breaking. A lot of trying to make the logic more efficient, or just giving up and switching directions.

For the final stretch, I dug into the code. I grabbed the html code for the component, popped it into notepad++, and made changes directly in the code. Then I copied it back into an empty AI component, telling it to “recreate exactly” (provided it actually respects that request).

So ultimately it was a combination of using the AI for most things and directly tweaking the code to fine tune it. About the only thing I’m not happy with yet is the font. I insist on it being a monospaced font, but sometimes monospaced fonts just don’t look that good.

I think if you wanted to use mine as a base, you can ask the AI to remove the stopwatch feature and the tabs feature, along with anything else you don’t want. Then ask for any changes from there. The final iteration was created via the code, but you can still use the AI to modify it further.

If you have specifics in mind, I could try to help.

3 Likes

Thanks for that. So sounds like lots of trial and error. The end result is pretty slick though, so perhaps worth the effort. To be honest, I’m not a big fan of the AI component. I find it frustrating to work with - probably because I don’t have the patience/motivation to learn how to prompt it effectively. It also seems quite unstable and a little unpredictable, and because of that I’m very reluctant to introduce it into any App where there is a low tolerance for failure. So to date I’ve only used it a handful of times in mostly personal/hobby Apps.

Which brings me to the specific use case I have in mind here. I’m thinking it could be used as a shot clock timer for 9 ball/pool. I recently built a scoring App for a league that I’m involved in, and when we play tournaments we sometimes operate with a 40 second shot clock. Currently, people use the stopwatch on their Phones, but I was thinking it might be nice to have something integrated into the scoring App.

Specific changes I’d want to make:

  • get rid of hours, minutes, milliseconds. I just need seconds.
  • make the number display as big as possible
  • just a single button to reset and restart the countdown
  • a configurable starting point (by default it would be 40 seconds, but sometimes we might want to increase or decrease that)

Anyway, I might have a fiddle with it and see how far I can get before the urge to throw something at my laptop overcomes me :smiley:

1 Like

@Darren_Murphy If I can help you with AI Prompting:

The AI doesn’t remember the history. The AI component only knows the current state and the new instructions. So by adding instructions in the code (asking the AI to add comments in all prompts you send), the current state will always contain more context and information. That way, the AI will not redo the same errors. I learned that by playing for so many hours with components.glide.info

Also, the data variables are created in the first Prompt and wont be changed automatically.
Secondly, action seems to not be creatable by the ai component (maybe just a bug) so I always create the actions first then send the prompt (in one shot of course).

1 Like

Yes, thanks. I saw you make similar comments on Slack, and I’ve been keeping that in mind.

1 Like