Skip to content

Commit

Permalink
Show the remaining time in document title
Browse files Browse the repository at this point in the history
  • Loading branch information
Malanius committed Feb 21, 2020
1 parent 8b15dbb commit 461beab
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Timer.re
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ let formatTime = seconds => {
minString ++ ":" ++ secondsString;
};

let updateTitle: string => unit = [%bs.raw
{|
(remaining) => {document.title = "⏰ " + remaining + " ⏰"}
|}
];

[@react.component]
let make = () => {
let (state, dispatch) =
Expand All @@ -35,7 +41,11 @@ let make = () => {
| Reset => {...state, seconds: 30}
| Tick =>
state.isTicking && state.seconds > 0
? {...state, seconds: state.seconds - 1} : state
? {
updateTitle(formatTime(state.seconds - 1));
{...state, seconds: state.seconds - 1};
}
: state
},
{isTicking: false, seconds: 30},
);
Expand Down

0 comments on commit 461beab

Please sign in to comment.