How can I make a countdown that starts at opening TW and shows a (save-) button only for 10 minutes after that

I am making a sort of doodle-app to ask who in my foodcoop is taking turn on the tasks that are to be done there.
To take this threat a little further I have a new idea to ensure (or at least to make less probable) that users do not overwrite other edits made meanwhile:
How can I make a countdown that starts at opening TW and shows a (save-) button only for 10 minutes after that.
Are there any good starting-points for this.

PS: I just remembered tiddlytools;
I just have to find a way to trigger It's About Time! — TiddlyTools: "Small Tools for Big Ideas!" (tm) as a startup action.

yes “Its about time” has a timer/ticker that can be started.

I have a similar interest for a similar purpose but the opposite, if someone opens a wiki and it was not reserved previously it allows save (and checkout) for 30 seconds only, then after that you need to reload to check it is still available.

It should just be a matter of having a startup time and checking if the ticker is greater than the desired amount.

First, import these 3 tiddlers from It's About Time! — TiddlyTools: "Small Tools for Big Ideas!" (tm)

  • TiddlyTools/Time/Ticker
  • TiddlyTools/Time/action-timeout.js
  • TiddlyTools/Time/CountDown

Then, create a tiddler (e.g. “AutoHideSaverButton”), tagged with $:/tags/StartupAction/Browser containing:

\define done()
<$action-setfield
   $tiddler="$:/config/PageControlButtons/Visibility/$:/core/ui/Buttons/save-wiki"
   text="hide"/>
\end

<$action-setfield
   $tiddler="$:/temp/time/CountDown/AutoHideSaverButton"
   done=<<done>> text="600" hours="00" mins="10" secs="00" go="go"/>

{{||TiddlyTools/Time/CountDown}}

Notes:

  • After installing the above tiddlers, you will need to save-and-reload the file so that the action-timeout.js widget will be defined and the “startup” tiddlers can be invoked.

  • TiddlyTools/Time/Ticker is tagged with $:/tags/StartupAction/Browser so it is invoked at startup. It uses an <$action-timeout interval=1000 .../> widget (defined in TiddlyTools/Time/action-timeout.js) to invoke the <<countdown_tick>> macro (defined in TiddlyTools/Time/CountDown) once-per-second. This macro finds all tiddlers with a prefix of $:/temp/time/CountDown and updates the fields of those tiddlers to track the current time remaining for each active countdown timer. When a countdown timer reaches “0”, the <<countdown_tick>> macro then invokes the “done” handler for that timer.

  • AutoHideSaverButton is tagged with $:/tags/StartupAction/Browser so it is invoked at startup. It defines a custom “done” handler that will set the TWCore “save-wiki” button “Visibility” configuration to “hide”. It also creates the $:/temp/time/CountDown/AutoHideSaverButton tiddler with field values set for a 600 second (10 minute) countdown timer and sets the go field to “go”, so that the countdown timer is automatically started as soon as the tiddler is created.

  • The result is that 10 minutes after loading the file, the “done” handler defined in AutoHideSaverButton is triggered, and the “save-wiki” button automatically disappears from the sidebar. Once it is hidden, you can manually re-enable the save-wiki button by viewing the $:/ControlPanel > Appearance > Toolbars > Page Toolbar settings and selecting the “save wiki” checkbox.

  • Transcluding {{||TiddlyTools/Time/CountDown}} in the AutoHideSaverButton tiddler is optional, and provides an interactive form that can be used to manually pause or stop the current countdown timer.

Let me know how it goes…

enjoy,
-e

4 Likes

Hello Eric,
Tiddlytime is a great set of tools. Thanks a lot!

I finished by calling a modal which allows to save for ten seconds and then requires a reload.

Hi @EricShulman,
thanks a lot again, I have one remainig issue. On my android, the counddown timer only works, if the phone and the firefox-tab are active.
Is there an alternative in your package that also works if the phone was in standby-mode meanwhile?
For my usecase this is important, because it is used to avoid that old versions are saved.

TiddlyTools/Time/CountDown uses a once-per-second interrupt-driven “ticker” to repeatedly subtract “1” from the remaining countdown time, until it reaches 0 and invokes the desired action(s). As you’ve noted, on Android devices, this interrupt-driven ticker is only triggered when the phone and the browser app are active. Thus, the countdown is effectively “paused” when the phone is in standby mode. Unfortunately, changing this behavior would require an extensive re-write of the CountDown logic.

Fortunately, there may be an alternative, by using TiddlyTools/Time/Alarms instead of TiddlyTools/Time/Countdown. Unlike the CountDown code, the Alarms code works by comparing a defined alarm date and time with the current date and time, so it doesn’t need to “tick” once-per-second in order to detect when the desired action(s) should be invoked.

Give this a try:

First, import the following tiddlers from It's About Time! — TiddlyTools: "Small Tools for Big Ideas!" (tm)

  • TiddlyTools/Time/Ticker
  • TiddlyTools/Time/action-timeout.js
  • TiddlyTools/Time/ParseDate
  • TiddlyTools/Time/Alarms

(Note: you can delete the TiddlyTools/Time/CountDown and the AutoHideSaverButton tiddler you had previously created, as they will no longer be used.)

Next, create a tiddler (e.g., AutoHideSaverStartup), tagged with $:/tags/StartupAction/Browser containing:

<$action-setfield
   $tiddler="AutoHideSaver"
   $timestamp="no" 
   alarms={{{ [<now "YYYY-0MM-0DD;0hh:0mm:0ss">parsedate[number]add[600000]parsedate:number[YYYY-0MM-0DD;0hh:0mm:0ss]addprefix[once;]addsuffix[;AutoHideSaver]] }}}/>

Then, create a tiddler (e.g., AutoHideSaver), containing:

<$action-setfield
   $tiddler="$:/config/PageControlButtons/Visibility/$:/core/ui/Buttons/save-wiki"
   text="hide"/>
<$action-setfield $tiddler="AutoHideSaver" $timestamp="no"  $field=alarms/>
{{||TiddlyTools/Time/Alarms}}

Notes:

  • The AutoHideSaverStartup tiddler is invoked at startup, and sets the alarms field of the AutoHideSaver tiddler.
  • The desired alarm date and time is automatically computed by getting the current formatted date and time, converting it to a “unix time” decimal number, adding 10 minutes (600000 milliseconds), and then converting it back to a formatted date and time. A prefix of “once;” and a suffix of “;AutoHideSaver” are then added to produce an alarm definition usng the format required by the TiddlyTools/Time/Alarms macro code: once;YYYY-MM-DD;hh:mm:ss;ActionTiddlerTitle
  • The AutoHideSaver tiddler contains two actions that will be invoked when the alarm is triggered:
    • The first action hides the “save-wiki” button
    • The second action deletes the alarm definition that was set at startup (and is “expired” when the alarm is triggered). Note the use of $timestamp="no", which prevents the AutoHideSaver tiddler’s “modified” timestamp from being updated. This is optional, and just keeps the AutoHideSaver tiddler from moving to the top of the “Recent Changes” sidebar list.
  • Transcluding {{||TiddlyTools/Time/Alarms}} in the AutoHideSaver tiddler is also optional, and provides an interactive form that can be used to manually edit, suspend, or delete the current alarm.

-e

1 Like