Low hanging hook fruit

This commit is contained in:
zikaeroh 2020-05-25 16:52:46 -07:00
parent 3b0cf502ab
commit c1d47bf2f7
2 changed files with 4 additions and 4 deletions

View File

@ -9,7 +9,7 @@ const Context = React.createContext<ServerTime>(Object.seal({ setOffset: () => {
export const ServerTimeProvider = (props: React.PropsWithChildren<{}>) => {
const [offset, setOffset] = React.useState(0);
const value = React.useMemo(() => Object.seal({ setOffset, now: () => Date.now() + offset }), [offset, setOffset]);
const value = React.useMemo(() => Object.seal({ setOffset, now: () => Date.now() + offset }), [offset]);
return <Context.Provider value={value}>{props.children}</Context.Provider>;
};

View File

@ -84,6 +84,7 @@ const CenterText = ({ winner, timer, turn }: State) => {
const classes = useCenterStyles();
const [countdown, setCountdown] = React.useState<number | undefined>();
const { now } = useServerTime();
const deadline = timer?.turnEnd;
React.useEffect(() => {
const updateCountdown = () => {
@ -92,14 +93,13 @@ const CenterText = ({ winner, timer, turn }: State) => {
return;
}
if (!isDefined(timer)) {
if (deadline === undefined) {
if (countdown !== undefined) {
setCountdown(undefined);
}
return;
}
const deadline = timer.turnEnd;
const diff = deadline.getTime() - now();
const between = Math.floor(diff / 1000);
@ -120,7 +120,7 @@ const CenterText = ({ winner, timer, turn }: State) => {
}, 200);
return () => window.clearInterval(interval);
}, [countdown, setCountdown, winner, timer, now]);
}, [countdown, winner, deadline, now]);
const centerText = React.useMemo(() => {
const text = isDefined(winner) ? `${teamSpecs[winner].name} wins!` : `${teamSpecs[turn].name}'s turn`;