Commit 41a297be authored by chechunchi's avatar chechunchi

add Timer Component

parent fd10aa4d
......@@ -14,7 +14,7 @@ import {
SortCardModal,
YesNoModal,
} from "./Message";
import { LifeBar, Mat, Menu } from "./PlayMat";
import { LifeBar, Mat, Menu, Timer } from "./PlayMat";
const NeosDuel = () => {
return (
......@@ -24,6 +24,7 @@ const NeosDuel = () => {
<Menu />
<LifeBar />
<Mat />
<Timer />
<CardModal />
<CardListModal />
<HintNotification />
......
import "./index.scss";
import React, { useEffect, useState } from "react";
import AnimatedNumbers from "react-animated-numbers";
import { useSnapshot } from "valtio";
import { matStore } from "@/stores";
export const Timer: React.FC = () => {
const [time, setTime] = useState(0);
const snap = useSnapshot(matStore);
useEffect(() => {
const interval = setInterval(() => {
if (time > 0) {
setTime((time) => time - 1);
}
}, 1000);
return () => clearInterval(interval);
}, []);
useEffect(() => {
setTime(snap.timeLimits.me);
}, [snap.timeLimits.me]);
useEffect(() => {
setTime(snap.timeLimits.op);
}, [snap.timeLimits.op]);
return <div>{<AnimatedNumbers animateToNumber={time} />}</div>;
};
export * from "./LifeBar";
export * from "./Mat";
export * from "./Menu";
export * from "./Timer";
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment