|
|
@ -1,8 +1,9 @@
|
|
|
|
import { requestJSON } from '@/client/utils'
|
|
|
|
import { requestJSON } from '@/client/utils'
|
|
|
|
import type { Room } from '@/db/model'
|
|
|
|
import type { Room } from '@/db/model'
|
|
|
|
import { useEffect, useState } from 'preact/hooks'
|
|
|
|
import { useEffect, useRef, useState } from 'preact/hooks'
|
|
|
|
import { Leaderboard } from './Leaderboard'
|
|
|
|
import { Leaderboard } from './Leaderboard'
|
|
|
|
import { computeScoreboardState } from '@/ggwp'
|
|
|
|
import { computeScoreboardState } from '@/ggwp'
|
|
|
|
|
|
|
|
import clsx from 'clsx'
|
|
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
type Props = {
|
|
|
|
roomId: string
|
|
|
|
roomId: string
|
|
|
@ -50,5 +51,48 @@ export const LiveLeaderboard = ({ roomId }: Props) => {
|
|
|
|
room.actions
|
|
|
|
room.actions
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return <Leaderboard questions={room.questions} scoreboard={scoreboard} />
|
|
|
|
const [autoscroll, setAutoscroll] = useState<false | 'up' | 'down'>(false)
|
|
|
|
|
|
|
|
const timerRef = useRef<Timer | null>(null)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
if (autoscroll !== false) {
|
|
|
|
|
|
|
|
timerRef.current = setInterval(() => {
|
|
|
|
|
|
|
|
console.log('scrolling')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.scrollBy({
|
|
|
|
|
|
|
|
top: autoscroll === 'down' ? 10 : -10,
|
|
|
|
|
|
|
|
behavior: 'smooth',
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (window.scrollY + window.innerHeight + 1 > document.body.scrollHeight) {
|
|
|
|
|
|
|
|
setAutoscroll('up')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (window.scrollY === 0) {
|
|
|
|
|
|
|
|
setAutoscroll('down')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 100)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
|
|
if (timerRef.current) {
|
|
|
|
|
|
|
|
clearInterval(timerRef.current)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, [autoscroll])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<>
|
|
|
|
|
|
|
|
<Leaderboard questions={room.questions} scoreboard={scoreboard} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="position-fixed bottom right">
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
|
|
|
class={clsx('square', autoscroll !== false && 'active')}
|
|
|
|
|
|
|
|
onClick={() => setAutoscroll(v => (v === false ? 'down' : false))}
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<div class="icon">swap_vert</div>
|
|
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</>
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|