Skip to content

Commit

Permalink
define interval before checkTime
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceau committed Feb 14, 2024
1 parent ac50dd3 commit cb3754a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/renderer/pages/home/sidebar/slippi_store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,25 @@ export const SlippiStore = React.memo(function SlippiStore() {

React.useEffect(() => {
const endDate = SHOP_CLOSES_AT;

// eslint-disable-next-line prefer-const
let interval: number | undefined;
const checkTime = () => {
const now = new Date();
const duration = intervalToDuration({ start: now, end: endDate });

if (isBefore(endDate, now)) {
setShopOpen(false);
setCountdown("");
clearInterval(interval);
window.clearInterval(interval);
} else {
setCountdown(formatDuration(duration, { format: ["days", "hours", "minutes"], locale: shortEnLocale }));
}
};
checkTime();

const interval = setInterval(checkTime, 60 * 1000);
return () => clearInterval(interval);
interval = window.setInterval(checkTime, 60 * 1000);
return () => window.clearInterval(interval);
}, []);

return <InternalSlippiStore shopOpen={shopOpen} countdown={countdown} />;
Expand Down

0 comments on commit cb3754a

Please sign in to comment.