chore: more stuff and minor features
parent
44f2076fba
commit
2c84fc74b4
@ -0,0 +1,60 @@
|
|||||||
|
import { requestJSON } from '@/client/utils'
|
||||||
|
import type { RoomData } from '@/db/model'
|
||||||
|
import type { ActionAnswer, ActionJolly } from '@/ggwp'
|
||||||
|
import { useEffect, useState } from 'preact/hooks'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
roomId: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const ActionCardAnswer = ({ action }: { action: ActionAnswer }) => {
|
||||||
|
return (
|
||||||
|
<div class="card tint-blue stack-h center">
|
||||||
|
<strong>{action.question}</strong>
|
||||||
|
<div>{action.team}</div>
|
||||||
|
<div>{action.outcome}</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ActionCardJolly = ({ action }: { action: ActionJolly }) => {
|
||||||
|
return (
|
||||||
|
<div class="card tint-blue stack-h center">
|
||||||
|
<strong>{action.team}</strong>
|
||||||
|
<div>{action.groupId}</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ActionRegistry = ({ roomId }: Props) => {
|
||||||
|
const [room, setRoom] = useState<RoomData | null>(null)
|
||||||
|
useEffect(() => {
|
||||||
|
requestJSON(`/api/room/${roomId}`).then(room => {
|
||||||
|
setRoom(room)
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
if (!room) {
|
||||||
|
return <div>Loading...</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
if (room.actions.length === 0) {
|
||||||
|
return <p>Ancora nessuna azione</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{room.actions.map(action =>
|
||||||
|
action.type === 'answer' ? (
|
||||||
|
<ActionCardAnswer action={action} />
|
||||||
|
) : action.type === 'jolly' ? (
|
||||||
|
<ActionCardJolly action={action} />
|
||||||
|
) : (
|
||||||
|
<div class="card tint-red">
|
||||||
|
Unknown action type: <code>{JSON.stringify(action)}</code>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
import { LiveLeaderboard } from '@/components/LiveLeaderboard'
|
||||||
|
import { SubmitAction } from '@/components/SubmitAction'
|
||||||
|
import { ActionRegistry } from '@/components/ActionRegistry'
|
||||||
|
import { useRef, useState } from 'preact/hooks'
|
||||||
|
|
||||||
|
export const AdminPage = ({ room }: { room: string }) => {
|
||||||
|
const listeners = useRef<Record<string, (teamQuestion: { team: string; question: string }) => void>>({})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h1>Admin</h1>
|
||||||
|
<h2>{room}</h2>
|
||||||
|
<LiveLeaderboard
|
||||||
|
roomId={room}
|
||||||
|
selectTeamQuestion={teamQuestion =>
|
||||||
|
Object.values(listeners.current).forEach(listener => listener(teamQuestion))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<h2>Azioni</h2>
|
||||||
|
<SubmitAction roomId={room} onTeamQuestionIndex={(key, listener) => (listeners.current[key] = listener)} />
|
||||||
|
|
||||||
|
<h2>Registro Azioni</h2>
|
||||||
|
<ActionRegistry roomId={room} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in New Issue