|
@@ -2,6 +2,7 @@ import React from "react";
|
|
|
import styled from "styled-components";
|
|
|
import ms from "pretty-ms";
|
|
|
import useCountdown from "../../../hooks/useCountdown";
|
|
|
+import { clearTimerFromLocalStorage, saveTimerToLocalStorage } from "../../../domain/localStorageMethods";
|
|
|
|
|
|
const TimerSpan = styled.span`
|
|
|
padding: 1px;
|
|
@@ -13,9 +14,17 @@ const TimedOut = styled(TimerSpan)`
|
|
|
`
|
|
|
|
|
|
export default ({ seconds, onTimeout }) => {
|
|
|
- const [remaining] = useCountdown(seconds, onTimeout);
|
|
|
+ console.log(seconds);
|
|
|
+ const [remaining] = useCountdown(seconds, () => {
|
|
|
+ clearTimerFromLocalStorage();
|
|
|
+ onTimeout();
|
|
|
+ });
|
|
|
+ console.log(remaining);
|
|
|
+
|
|
|
+ if (remaining > 0) {
|
|
|
+ saveTimerToLocalStorage(remaining);
|
|
|
+ return <TimerSpan>Time: {ms(remaining * 1000)}</TimerSpan>;
|
|
|
+ }
|
|
|
|
|
|
- return remaining > 0
|
|
|
- ? <TimerSpan>Time: {ms(remaining * 1000)}</TimerSpan>
|
|
|
- : <TimedOut>Time's up!</TimedOut>
|
|
|
+ return <TimedOut>Time's up!</TimedOut>;
|
|
|
}
|