Download leaderboards button and single instance enforcement

This commit is contained in:
2025-07-22 00:02:28 -07:00
parent 5f919b4d40
commit 42daffee84
4 changed files with 91 additions and 21 deletions

View File

@@ -5,6 +5,7 @@ import { LeaderboardEntry } from '../types/LeaderboardEntry'
import { app } from '@tauri-apps/api'
import { platform } from '@tauri-apps/plugin-os'
import { decrypt } from '../util/Encryption'
import { invoke } from '@tauri-apps/api/core'
export default function Leaderboards () {
const [leaderboardData, setLeaderboardData] = useState<LeaderboardEntry[]>([])
@@ -30,6 +31,17 @@ export default function Leaderboards () {
.finally(() => setLoading(false))
}
function downloadLeaderboard () {
let content = 'Username,Score\n'
leaderboardData.forEach(entry => {
content += `${entry.username},${entry.value}\n`
})
while (content.endsWith('\n')) {
content = content.slice(0, -1)
}
invoke('download_leaderboard', { content })
}
useEffect(() => {
refresh()
}, [])
@@ -38,13 +50,22 @@ export default function Leaderboards () {
<div className='mx-4 mt-4'>
<div className='flex justify-between items-center mb-4'>
<p className='text-3xl'>Leaderboards</p>
<button
className='button text-3xl'
onClick={refresh}
disabled={loading}
>
Refresh
</button>
<div className='flex gap-2'>
<button
className='button text-3xl'
onClick={downloadLeaderboard}
disabled={loading || leaderboardData.length === 0}
>
Download Leaderboards
</button>
<button
className='button text-3xl'
onClick={refresh}
disabled={loading}
>
Refresh
</button>
</div>
</div>
<div className='leaderboard-container'>
<div className='leaderboard-scroll'>