Switched to path routing. Added data management.

This commit is contained in:
Pen Anderson 2026-03-03 19:55:35 -06:00
parent 8dc5d3ed01
commit 4bba0ed3a0
14 changed files with 256 additions and 46 deletions

View file

@ -23,16 +23,22 @@
let session = $state(null)
let loading = $state(true)
let route = $state(window.location.hash || '#/')
let route = $state(window.location.pathname)
let updateAvailable = $state(false)
let mobileNavOpen = $state(false)
// Check if this is a public page (no auth needed)
const kioskToken = $derived(window.location.hash.match(/^#\/v\/([A-Z0-9]+)/i)?.[1] ?? '')
const isVolunteerSignup = $derived(window.location.hash.startsWith('#/volunteer-signup'))
const isConfirmEmail = $derived(window.location.hash.startsWith('#/confirm/'))
const kioskToken = $derived(route.match(/^\/v\/([A-Z0-9]+)/i)?.[1] ?? '')
const isVolunteerSignup = $derived(route.startsWith('/volunteer-signup'))
const isConfirmEmail = $derived(route.startsWith('/confirm/'))
const isPublicPage = $derived(!!kioskToken || isVolunteerSignup || isConfirmEmail)
function navigate(path) {
history.pushState(null, '', path)
route = path
mobileNavOpen = false
}
async function checkVersion() {
try {
const res = await fetch('/api/version')
@ -56,8 +62,8 @@
startSSE()
startSyncLoop()
}
window.addEventListener('hashchange', () => {
route = window.location.hash || '#/'
window.addEventListener('popstate', () => {
route = window.location.pathname
mobileNavOpen = false
})
@ -67,17 +73,17 @@
function onLogin(s) {
session = s
window.location.hash = '#/'
navigate('/')
syncPull().then(() => { startSSE(); startSyncLoop() })
}
async function onLogout() {
await clearSession()
session = null
window.location.hash = '#/login'
navigate('/login')
}
const path = $derived(route.replace(/^#/, '') || '/')
const path = $derived(route || '/')
const role = $derived(session?.user?.role ?? '')
</script>
@ -107,7 +113,7 @@
{#if mobileNavOpen}
<div class="nav-overlay" onclick={() => mobileNavOpen = false} onkeydown={() => {}}></div>
{/if}
<Nav {session} {onLogout} active={path} open={mobileNavOpen} />
<Nav {session} {onLogout} {navigate} active={path} open={mobileNavOpen} />
<div class="main">
<header class="mobile-header">
<button class="hamburger" onclick={() => mobileNavOpen = !mobileNavOpen} aria-label="Menu">