25 lines
738 B
TypeScript
25 lines
738 B
TypeScript
import type { RankingKind, RankingPage } from '~/types/game'
|
|
|
|
/** One world's ranking: a page of one kind. */
|
|
export function useRanking(worldId: number) {
|
|
const page = ref<RankingPage | null>(null)
|
|
const error = ref<string | null>(null)
|
|
const busy = ref(false)
|
|
const errorText = useErrorText()
|
|
|
|
/** Without a page, the server opens on the one with the own row. */
|
|
async function load(kind: RankingKind, at?: number) {
|
|
busy.value = true
|
|
error.value = null
|
|
try {
|
|
page.value = await ws.send<RankingPage>('ranking.index', { world_id: worldId, kind, page: at ?? null })
|
|
} catch (e) {
|
|
error.value = errorText(e)
|
|
} finally {
|
|
busy.value = false
|
|
}
|
|
}
|
|
|
|
return { page, error, busy, load }
|
|
}
|