This repository has been archived on 2024-08-06. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
chellaris-sign-up-site/src/routes/admin/+page.ts

41 lines
No EOL
1.3 KiB
TypeScript

import { apiBaseUrl } from "$lib/components/consts";
import AdminSelectedEmpireStore from "$lib/stores/admin-page/EmpireStore";
import AdminSelectedGameStore from "$lib/stores/admin-page/GameStore";
import type { ChellarisGameInfo } from "$lib/types/chellaris";
import AdminSelectedGroupStore from '../../lib/stores/admin-page/GroupStore';
export async function load ({ fetch }) {
const gameList: { [key: number]: ChellarisGameInfo } = await (await fetch(apiBaseUrl + "/v3/games")).json();
let store: string | null;
if (typeof localStorage !== 'undefined') {
// Game Selection
store = localStorage.getItem('adminGameSelection');
if (typeof store === 'string') {
AdminSelectedGameStore.set(JSON.parse(store));
}
// Group Selection
store = localStorage.getItem('adminGroupSelection');
if (typeof store === 'string' && store != "\"\"") {
AdminSelectedGroupStore.set(JSON.parse(store));
}
else if (typeof store === 'string') {
AdminSelectedGroupStore.set({});
}
// Empire Selection
store = localStorage.getItem('adminEmpireSelection');
if (typeof store === 'string' && store != "\"\"") {
AdminSelectedEmpireStore.set(JSON.parse(store));
}
else if (typeof store === 'string') {
AdminSelectedEmpireStore.set({});
}
}
return { games: gameList };
}