This commit is contained in:
2025-07-21 19:11:06 -07:00
parent f3bc9a9570
commit b7d07f5b90

View File

@@ -4,33 +4,30 @@ import axios from 'axios'
import { LeaderboardEntry } from '../types/LeaderboardEntry' import { LeaderboardEntry } from '../types/LeaderboardEntry'
import { app } from '@tauri-apps/api' import { app } from '@tauri-apps/api'
import { platform } from '@tauri-apps/plugin-os' import { platform } from '@tauri-apps/plugin-os'
import { decrypt, encrypt } from '../util/Encryption' import { decrypt } from '../util/Encryption'
export default function Leaderboards () { export default function Leaderboards () {
const [leaderboardData, setLeaderboardData] = useState<LeaderboardEntry[]>([]) const [leaderboardData, setLeaderboardData] = useState<LeaderboardEntry[]>([])
const [loading, setLoading] = useState(true)
async function refresh () { async function refresh () {
setLoading(true)
setLeaderboardData([]) setLeaderboardData([])
const launcherVersion = await app.getVersion() const launcherVersion = await app.getVersion()
axios axios
.post( .get('https://berrydash.lncvrt.xyz/database/getTopPlayers.php', {
'https://berrydash.lncvrt.xyz/database/getTopPlayers.php', headers: {
{ Requester: 'BerryDashLauncher',
[encrypt('type')]: encrypt('0') LauncherVersion: launcherVersion,
}, ClientPlatform: platform()
{
headers: {
Requester: 'BerryDashLauncher',
LauncherVersion: launcherVersion,
ClientPlatform: platform()
}
} }
) })
.then(res => { .then(res => {
const decrypted = decrypt(res.data) const decrypted = decrypt(res.data)
setLeaderboardData(JSON.parse(decrypted)) setLeaderboardData(JSON.parse(decrypted))
}) })
.catch(e => console.error('Error fetching leaderboard data:', e)) .catch(e => console.error('Error fetching leaderboard data:', e))
.finally(() => setLoading(false))
} }
useEffect(() => { useEffect(() => {
@@ -41,7 +38,11 @@ export default function Leaderboards () {
<div className='mx-4 mt-4'> <div className='mx-4 mt-4'>
<div className='flex justify-between items-center mb-4'> <div className='flex justify-between items-center mb-4'>
<p className='text-3xl'>Leaderboards</p> <p className='text-3xl'>Leaderboards</p>
<button className='button text-3xl' onClick={refresh}> <button
className='button text-3xl'
onClick={refresh}
disabled={loading}
>
Refresh Refresh
</button> </button>
</div> </div>
@@ -56,10 +57,14 @@ export default function Leaderboards () {
<p className='score'>{entry.value}</p> <p className='score'>{entry.value}</p>
</div> </div>
)) ))
) : ( ) : loading ? (
<div className='flex justify-center items-center h-full'> <div className='flex justify-center items-center h-full'>
<p className='text-3xl'>Loading...</p> <p className='text-3xl'>Loading...</p>
</div> </div>
) : (
<div className='flex justify-center items-center h-full'>
<p className='text-3xl'>No data...</p>
</div>
)} )}
</div> </div>
</div> </div>