This commit is contained in:
2023-01-31 16:36:37 -06:00
parent 4ad1f7c217
commit cef5fc9879
25 changed files with 8257 additions and 0 deletions

53
src/Contestant.tsx Normal file
View File

@@ -0,0 +1,53 @@
import { useEffect } from "react";
import { useParams } from "react-router-dom";
import { debounce } from "lodash";
import { socket } from "./socket";
import { useAppSelector } from "./hooks";
import { selectCanBuzz, selectSignature } from "./store/contestantSlice";
const Contestant = () => {
const { room } = useParams();
const signature = useAppSelector(selectSignature);
const canBuzz = useAppSelector(selectCanBuzz);
useEffect(() => {
socket.emit("contestant-join", { room, signature });
}, []);
useEffect(() => {
if (parent.current) {
setWidth(parent.current.getBoundingClientRect().width);
}
}, [parent]);
const handleBuzz = debounce(
() => {
if (canBuzz) {
socket.emit("buzz");
}
},
1000,
{ leading: true, trailing: false }
);
return (
<div>
<svg viewBox={`0 0 100 100`}>
<circle
cx={50}
cy={50}
r={30}
fill={canBuzz ? "red" : "grey"}
stroke="black"
onClick={handleBuzz}
/>
<text x={50} y={50} textAnchor="middle">
Buzz
</text>
</svg>
</div>
);
};
export default Contestant;