From 461beabafa07cdc0392fd7fa6e5ec49cd89d92bd Mon Sep 17 00:00:00 2001 From: Malanius Privierre Date: Fri, 21 Feb 2020 13:21:06 +0100 Subject: [PATCH] Show the remaining time in document title --- src/Timer.re | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Timer.re b/src/Timer.re index fc19974..b57bdd5 100644 --- a/src/Timer.re +++ b/src/Timer.re @@ -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) = @@ -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}, );