Initial commit.

This commit is contained in:
Greyson Parrelli
2026-07-22 23:07:29 -04:00
commit 612a4e6227
38 changed files with 6106 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import type { Session } from './types'
const SESSION_KEY = 'sapbg-session'
async function post(path: string, body: unknown): Promise<Session> {
const res = await fetch(path, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
})
const data = await res.json()
if (!res.ok) throw new Error(data.error ?? 'request failed')
return data as Session
}
export function createGame(name: string): Promise<Session> {
return post('/api/games', { name })
}
export function joinGame(code: string, name: string): Promise<Session> {
return post('/api/join', { code, name })
}
export function loadSession(): Session | null {
try {
const raw = localStorage.getItem(SESSION_KEY)
return raw ? (JSON.parse(raw) as Session) : null
} catch {
return null
}
}
export function saveSession(s: Session) {
localStorage.setItem(SESSION_KEY, JSON.stringify(s))
}
export function clearSession() {
localStorage.removeItem(SESSION_KEY)
}