From 1d3996d6dc94c0f1c0c22a3b4554bfe23d95a0e4 Mon Sep 17 00:00:00 2001
From: mat <github@matdoes.dev>
Date: Sat, 9 Apr 2022 18:58:58 -0500
Subject: Show a message when a member isn't in any leaderboards

---
 src/lib/sections/Leaderboards.svelte | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

(limited to 'src/lib/sections/Leaderboards.svelte')

diff --git a/src/lib/sections/Leaderboards.svelte b/src/lib/sections/Leaderboards.svelte
index 7cbea23..7e32958 100644
--- a/src/lib/sections/Leaderboards.svelte
+++ b/src/lib/sections/Leaderboards.svelte
@@ -2,6 +2,7 @@
 	import { API_URL } from '$lib/api'
 
 	import type { CleanMemberProfile } from '$lib/APITypes'
+	import Emoji from '$lib/Emoji.svelte'
 	import { cleanId, formatNumberFromUnit } from '$lib/utils'
 
 	export let data: CleanMemberProfile
@@ -10,18 +11,22 @@
 {#await fetch(`${API_URL}player/${data.member.uuid}/${data.profile.uuid}/leaderboards`).then( r => r.json() )}
 	Loading...
 {:then leaderboards}
-	<ul>
-		{#each leaderboards as leaderboard}
-			<li class="leaderboard-item">
-				<a href="/leaderboard/{leaderboard.name}" class="leaderboard-item-anchor">
-					{leaderboard.positionIndex + 1}) <b>{cleanId(leaderboard.name)}</b>: {formatNumberFromUnit(
-						leaderboard.value,
-						leaderboard.unit ?? null
-					)}
-				</a>
-			</li>
-		{/each}
-	</ul>
+	{#if leaderboards.length > 0}
+		<ul>
+			{#each leaderboards as leaderboard}
+				<li class="leaderboard-item">
+					<a href="/leaderboard/{leaderboard.name}" class="leaderboard-item-anchor">
+						{leaderboard.positionIndex + 1}) <b>{cleanId(leaderboard.name)}</b>: {formatNumberFromUnit(
+							leaderboard.value,
+							leaderboard.unit ?? null
+						)}
+					</a>
+				</li>
+			{/each}
+		</ul>
+	{:else}
+		<p>This player isn't in any leaderboards. <Emoji value="😦" /></p>
+	{/if}
 {/await}
 
 <style>
@@ -35,4 +40,7 @@
 		padding-left: 0;
 		margin-top: 0.5em;
 	}
+	p {
+		margin: 0.5rem 0;
+	}
 </style>
-- 
cgit 

