Handle data loading during SSR

This commit is contained in:
Laurent
2024-10-27 18:02:59 +01:00
parent 29ed897de5
commit 7ae4bb346d
11 changed files with 46 additions and 17 deletions

View File

@@ -26,9 +26,8 @@ function createStore(){
});
},
loadData: async () => {
if(scores.length !== 0) return;
let res = sort(await getLeaderboard());
load: (data : Score[]) => {
let res = sort(data);
set(res);
},
};

View File

@@ -0,0 +1,10 @@
const api_url = import.meta.env.VITE_SERVER_API_URL
// @ts-ignore
export const load = async ( {fetch} ) => {
const res = await fetch(`${api_url}/leaderboard`)
const leaderboard = await res.json()
return { leaderboard };
}

View File

@@ -1,11 +1,13 @@
<script>
import { onMount } from 'svelte';
import { scoreStore } from "$lib/stores/scoreStore.ts";
import LeaderBoard from "$lib/components/LeaderBoard.svelte";
import {scoreStore} from "$lib/stores/scoreStore.ts";
import {onMount} from "svelte";
let { data } = $props()
onMount(async () => {
await scoreStore.loadData();
});
scoreStore.load(data.leaderboard)
} )
</script>

View File

@@ -98,11 +98,12 @@
button
{
background-color: #f1ecec;
color: black;
width: 18vw;
height: 15vh;
border-radius: 10px;
background-color: #f1ecec;
border: 2px solid #A1674A;
box-shadow: 0 0 10px #343232;
}