forked from Berry-Dash/launcher
Leaderboards formatting
This commit is contained in:
@@ -10,6 +10,7 @@ import { invoke } from '@tauri-apps/api/core'
|
|||||||
export default function Leaderboards () {
|
export default function Leaderboards () {
|
||||||
const [leaderboardData, setLeaderboardData] = useState<LeaderboardEntry[]>([])
|
const [leaderboardData, setLeaderboardData] = useState<LeaderboardEntry[]>([])
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
const formatter = new Intl.NumberFormat('en-US')
|
||||||
|
|
||||||
async function refresh () {
|
async function refresh () {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
@@ -36,9 +37,11 @@ export default function Leaderboards () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function downloadLeaderboard () {
|
function downloadLeaderboard () {
|
||||||
let content = 'Username,Score\n'
|
let content = '"Username","Score","ScoreFormatted"\n'
|
||||||
leaderboardData.forEach(entry => {
|
leaderboardData.forEach(entry => {
|
||||||
content += `${entry.username},${entry.value}\n`
|
content += `"${entry.username}","${entry.value}","${formatter.format(
|
||||||
|
BigInt(entry.value)
|
||||||
|
)}"\n`
|
||||||
})
|
})
|
||||||
while (content.endsWith('\n')) {
|
while (content.endsWith('\n')) {
|
||||||
content = content.slice(0, -1)
|
content = content.slice(0, -1)
|
||||||
@@ -79,7 +82,7 @@ export default function Leaderboards () {
|
|||||||
<p>
|
<p>
|
||||||
#{i + 1} {entry.username}
|
#{i + 1} {entry.username}
|
||||||
</p>
|
</p>
|
||||||
<p className='score'>{entry.value}</p>
|
<p className='score'>{formatter.format(BigInt(entry.value))}</p>
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
) : loading ? (
|
) : loading ? (
|
||||||
|
|||||||
Reference in New Issue
Block a user