From 716fc7128224959021098845222e01a0b58f5be7 Mon Sep 17 00:00:00 2001 From: Neshura Date: Tue, 15 Aug 2023 22:51:13 +0200 Subject: [PATCH] Improved? Data loading --- src/routes/graphs/+layout.ts | 10 ++++++---- src/routes/graphs/excel-style/+page.svelte | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/routes/graphs/+layout.ts b/src/routes/graphs/+layout.ts index 3c5805f..aa99842 100644 --- a/src/routes/graphs/+layout.ts +++ b/src/routes/graphs/+layout.ts @@ -1,14 +1,15 @@ -import type { PageLoad } from "../$types"; import ChellarisDataStore from '$lib/stores/ChellarisData'; import SelectedGameStore from '$lib/stores/GameFilter'; -import { type ChellarisInfo, type ChellarisGame, type ChellarisGameGroup, createChellarisInfo, createChellarisGameGroup, createChellarisGame, createChellarisEmpire } from '../../lib/types/chellaris'; import SelectedGameGroupsStore from "$lib/stores/GameGroupFilter"; import GraphsTabStore from '$lib/stores/GraphsTab'; +import { createChellarisInfo, type ChellarisGame, createChellarisGame, createChellarisGameGroup, createChellarisEmpire } from "$lib/types/chellaris"; +import type { LayoutLoad } from "./$types"; -export const load: PageLoad = async () => { +export const load: LayoutLoad = async () => { + let store: string | null; const apiBaseUrl = 'https://www.chellaris.net/api/v2'; const chellarisData = createChellarisInfo(); - let store: string | null; + // Chellaris Data Code const games: {id: number, name: string}[] = await (await fetch(apiBaseUrl + '/games')).json(); @@ -97,4 +98,5 @@ export const load: PageLoad = async () => { SelectedGameGroupsStore.set(gameGroupSelectionMap); } } + return { chellarisData } } \ No newline at end of file diff --git a/src/routes/graphs/excel-style/+page.svelte b/src/routes/graphs/excel-style/+page.svelte index ce531b1..f2f1f0a 100644 --- a/src/routes/graphs/excel-style/+page.svelte +++ b/src/routes/graphs/excel-style/+page.svelte @@ -11,11 +11,13 @@ } from '$lib/types/chellaris'; import ChellarisDataStore from '$lib/stores/ChellarisData'; import GraphsTabStore from '$lib/stores/GraphsTab'; + import type { LayoutData } from '../$types'; + export let data: LayoutData; let selectedGameGroups: Array = []; let selectedGameGroupsMap: Map> = new Map(); let gameGroups: Map = new Map(); - let chellarisData: ChellarisInfo = createChellarisInfo(); + let chellarisData: ChellarisInfo = data.chellarisData; let selectedGameIdx: number; let selectedGame: ChellarisGame = createChellarisGame();; let pageData: {