|
|
|
@ -51,13 +51,23 @@ export const LiveLeaderboard = ({ roomId }: Props) => {
|
|
|
|
|
room.actions
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const url = new URL(window.location.href)
|
|
|
|
|
const pagesCount = parseInt(url.searchParams.get('pages') ?? '1')
|
|
|
|
|
const pageInterval = parseInt(url.searchParams.get('interval') ?? '5000')
|
|
|
|
|
|
|
|
|
|
const pageSize = Math.ceil(scoreboard.board.length / pagesCount)
|
|
|
|
|
|
|
|
|
|
const [page, setPage] = useState(0)
|
|
|
|
|
const timerRef = useRef<Timer | null>(null)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (pagesCount <= 1) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timerRef.current = setInterval(() => {
|
|
|
|
|
setPage(page => (page + 1) % 3)
|
|
|
|
|
}, 5000)
|
|
|
|
|
setPage(page => (page + 1) % pagesCount)
|
|
|
|
|
}, pageInterval)
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
if (timerRef.current) {
|
|
|
|
@ -69,13 +79,14 @@ export const LiveLeaderboard = ({ roomId }: Props) => {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<h3>
|
|
|
|
|
<Clock /> — {room.id} (pag. {page + 1}/3)
|
|
|
|
|
<Clock /> — {room.id}
|
|
|
|
|
{pagesCount > 1 ? ` (pagina ${page + 1}/${pagesCount})` : ''}
|
|
|
|
|
</h3>
|
|
|
|
|
<Leaderboard
|
|
|
|
|
questions={room.questions}
|
|
|
|
|
scoreboard={{
|
|
|
|
|
teamJollyGroup: scoreboard.teamJollyGroup,
|
|
|
|
|
board: scoreboard.board.slice(page * 20, (page + 1) * 20),
|
|
|
|
|
board: scoreboard.board.slice(page * pageSize, (page + 1) * pageSize),
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<div class="position-fixed bottom right stack-v center">
|
|
|
|
|