diff --git a/src/components/LiveLeaderboard.tsx b/src/components/LiveLeaderboard.tsx index 04316d1..c536c02 100644 --- a/src/components/LiveLeaderboard.tsx +++ b/src/components/LiveLeaderboard.tsx @@ -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(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 ( <>

- — {room.id} (pag. {page + 1}/3) + — {room.id} + {pagesCount > 1 ? ` (pagina ${page + 1}/${pagesCount})` : ''}

diff --git a/src/db/index.ts b/src/db/index.ts index a6c3f42..8bd3f2c 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -57,8 +57,6 @@ export function createRoom(id: string, teams: string[], questions: Question[]): } export function updateRoom(id: string, data: RoomData): void { - emitRoomUpdate(id, data) - db.prepare<[string, string]>( ` UPDATE rooms @@ -66,6 +64,8 @@ export function updateRoom(id: string, data: RoomData): void { WHERE id = ?; ` ).run(JSON.stringify(data), id) + + emitRoomUpdate(id, data) } export function deleteRoom(id: string): void { diff --git a/src/ggwp/index.ts b/src/ggwp/index.ts index fbcbbf0..c266872 100644 --- a/src/ggwp/index.ts +++ b/src/ggwp/index.ts @@ -163,11 +163,11 @@ export function computeScoreboardState(game: Game, rawActions: Action[]): Scoreb .map(question => getCorrectnessMultiplier(question.outcome)) .reduce((a, b) => a + b, 0) - if (2 <= N && N < 4) { + if (2 <= N && N < 3.5) { teamBonus = 5 - } else if (4 <= N && N < 6) { + } else if (3.5 <= N && N < 5.5) { teamBonus = 10 - } else if (6 <= N) { + } else if (5.5 <= N) { teamBonus = 30 }