'use client' import { BackButton } from '@/app/components/BackButton' import { DiscordButton } from '@/app/components/DiscordButton' import { useEffect, useState } from 'react' import { BirdColor, CustomIconEntry } from '../chatroom/page' import axios from 'axios' import { GetIconForUser } from '@/util/bd' interface LeaderboardEntry { id: number username: string value: number icon: number overlay: number birdColor: BirdColor overlayColor: BirdColor customIcon: string | null } export default function BerryDashLeaderboards () { const [selected, setSelected] = useState(-1) const [selectedBerryOption, setSelectedBerryOption] = useState(0) const [gettingEntries, setGettingEntries] = useState(false) const [entries, setEntries] = useState([]) const [customIconCache, setCustomIconCache] = useState([]) const Refresh = async () => { setGettingEntries(true) try { const result = await axios.get( '/api/berrydash/leaderboard/' + (selected == 0 ? 'score' : selected == 1 ? 'berry?berry=' + selectedBerryOption : selected == 2 ? 'coin' : selected == 3 ? 'legacy' : 'total') ) if (result.data.success) { setEntries(result.data.data) } } catch { setEntries([]) } setGettingEntries(false) } useEffect(() => { document.title = 'Lncvrt Games - Berry Dash Leaderboards' }, []) useEffect(() => { if (selected != -1) Refresh() }, [selected]) useEffect(() => { const all = customIconCache.map(icon => icon.id) const allFromMessages = Array.from( new Set( entries .filter(icon => icon.customIcon != null) .map(icon => icon.customIcon as string) ) ) const notInAllIds = allFromMessages .filter(id => !all.includes(id)) .map(id => `"${id}"`) .join(',') if (notInAllIds.length != 0) { ;(async () => { const result = await axios.get( `/api/berrydash/icon-marketplace/icon?ids=[${notInAllIds}]` ) if (result.data.success) { const add: CustomIconEntry[] = [] for (const item of result.data.data) { add.push({ data: item.data, id: item.id }) } setCustomIconCache(prev => [ ...prev, ...result.data.data.map((item: CustomIconEntry) => ({ data: item.data, id: item.id })) ]) } })() } }, [entries]) return (
{selected == -1 ? ( ) : ( { if (gettingEntries) return setEntries([]) setSelectedBerryOption(0) setSelected(-1) }} /> )}

Berry Dash Leaderboards

{selected == -1 ? ( <>

Select a Leaderboard

) : ( <>
{entries.map((item, index) => { return (
i.id === item.customIcon) ? 'data:image/png;base64,' + customIconCache.find(i => i.id === item.customIcon) ?.data : 'https://games-r2.lncvrt.xyz/game-assets/berrydash/other/loading.png' } width={48} height={48} />

{item.username} (#{index + 1})

{selected != 2 ? 'Berries' : 'Coins'}:{' '} {item.value.toLocaleString('en-US')}

) })}
)}
) }