"use client" import { Status } from "@rahoot/common/types/game/status" import background from "@rahoot/web/assets/background.webp" import Button from "@rahoot/web/components/Button" import Loader from "@rahoot/web/components/Loader" import { useEvent, useSocket } from "@rahoot/web/contexts/socketProvider" import { usePlayerStore } from "@rahoot/web/stores/player" import { useQuestionStore } from "@rahoot/web/stores/question" import { MANAGER_SKIP_BTN } from "@rahoot/web/utils/constants" import clsx from "clsx" import Image from "next/image" import { PropsWithChildren, useEffect, useState } from "react" type Props = PropsWithChildren & { statusName: Status | undefined onNext?: () => void onPause?: () => void paused?: boolean showPause?: boolean onEnd?: () => void players?: { id: string; username: string; connected: boolean }[] manager?: boolean } const GameWrapper = ({ children, statusName, onNext, onPause, paused, showPause, onEnd, players, manager, }: Props) => { const { isConnected } = useSocket() const { player } = usePlayerStore() const { questionStates, setQuestionStates } = useQuestionStore() const [isDisabled, setIsDisabled] = useState(false) const next = statusName ? MANAGER_SKIP_BTN[statusName] : null useEvent("game:updateQuestion", ({ current, total }) => { setQuestionStates({ current, total, }) }) useEffect(() => { setIsDisabled(false) }, [statusName]) const handleNext = () => { setIsDisabled(true) onNext?.() } return (
background
{!isConnected && !statusName ? (

Connecting...

) : ( <>
{questionStates && (
{`${questionStates.current} / ${questionStates.total}`}
)} {manager && next && ( )} {manager && showPause && ( )} {manager && onEnd && ( )}
{manager && players && players.length > 0 && (
Players ({players.length})
{players.map((p) => ( {p.username || p.id} {p.connected ? "" : "(disc.)"} ))}
)} {children} {!manager && (

{player?.username}

{player?.points}
)} )}
) } export default GameWrapper