import { commands, GameSettings } from "@/bindings"; import { sharedSwrConfig } from "@/lib/hooks"; import React from "react"; import useSWR from "swr"; // Temp settings for now. const settings: GameSettings = { random_seed: 21341234, hiding_time_seconds: 10, ping_start: "Instant", ping_minutes_interval: 1, powerup_start: "Instant", powerup_chance: 60, powerup_minutes_cooldown: 1, powerup_locations: [ { lat: 0, long: 0, heading: null } ] }; export default function MenuScreen() { const [roomCode, setRoomCode] = React.useState(""); const [newName, setName] = React.useState(""); const { data: profile, mutate: setProfile } = useSWR( "fetch-profile", commands.getProfile, sharedSwrConfig ); const { data: gameHistory } = useSWR( "list-game-history", commands.listGameHistories, sharedSwrConfig ); const onStartGame = async (code: string | null) => { if (code) { try { const validCode = await commands.checkRoomCode(code); if (!validCode) { window.alert("Invalid Join Code"); return; } } catch (e) { window.alert(`Failed to connect to Server ${e}`); return; } } await commands.startLobby(code, settings); }; const onSaveProfile = async () => { await commands.updateProfile({ ...profile, display_name: newName }); setProfile({ ...profile, display_name: newName }); }; return ( <> {profile.pfp_base64 && ( {`${profile.display_name}'s )}

Welcome, {profile.display_name}


Play

setRoomCode(e.target.value)} />

Edit Profile

setName(e.target.value)} />

Previous Games

); }