import type {Player, SchematicType} from "../types/data.js"; import {PlayerSchema} from "../types/data.js"; import {cached, cachedFamily} from "./cached.js"; import type {Team} from "../types/team.js"; import {TeamSchema} from "../types/team.js"; import {get, writable} from "svelte/store"; import {permsRepo, tokenStore} from "../repo/repo.js"; import {z} from "zod"; export const schemTypes = cached([], () => { return fetch("https://steamwar.de/eventplanner-api/data/schematicTypes", {headers: {"X-SW-Auth": get(tokenStore)}}) .then(res => res.json()) }) export const players = cached([], async () => { const res = await fetch("https://steamwar.de/eventplanner-api/data/users", {headers: {"X-SW-Auth": get(tokenStore)}}); return z.array(PlayerSchema).parse(await res.json()); }) export const gamemodes = cached([], async () => { const res = await fetch("https://steamwar.de/eventplanner-api/data/gamemodes", {headers: {"X-SW-Auth": get(tokenStore)}}); return z.array(z.string()).parse(await res.json()); }) export const maps = cachedFamily([], async (gamemode) => { if (get(gamemodes).every(value => value !== gamemode)) return []; const res = await fetch(`https://steamwar.de/eventplanner-api/data/gamemodes/${gamemode}/maps`, {headers: {"X-SW-Auth": get(tokenStore)}}); if (!res.ok) { return []; } else { return res.json(); } }) export const groups = cached([], async () => { const res = await fetch("https://steamwar.de/eventplanner-api/data/groups", {headers: {"X-SW-Auth": get(tokenStore)}}); return z.array(z.string()).parse(await res.json()); }) export const teams = cached([], async () => { const res = await fetch("https://steamwar.de/eventplanner-api/team", {headers: {"X-SW-Auth": get(tokenStore)}}); return z.array(TeamSchema).parse(await res.json()); }) export const isWide = writable(window.innerWidth >= 640); window.addEventListener("resize", () => isWide.set(window.innerWidth >= 640));