diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index 31efdcf..12fc307 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -13,6 +13,49 @@ CANCELLED: { label: 'Cancelled', color: 'text-red-400' } }; + // Queue state + let queueStatus = $state<{ inQueue: boolean; queueSize: number } | null>(null); + let queueLoading = $state(false); + + async function fetchQueueStatus() { + try { + const res = await fetch('/api/queue'); + if (res.ok) queueStatus = await res.json(); + } catch {} + } + + async function joinQueue() { + queueLoading = true; + try { + const res = await fetch('/api/queue', { method: 'POST' }); + const data = await res.json(); + if (data.matched && data.match) { + window.location.href = `/matches/${data.match.id}`; + return; + } + await fetchQueueStatus(); + } catch {} + queueLoading = false; + } + + async function leaveQueue() { + queueLoading = true; + try { + await fetch('/api/queue', { method: 'DELETE' }); + await fetchQueueStatus(); + } catch {} + queueLoading = false; + } + + // Poll queue status while on dashboard + $effect(() => { + if (data.user) { + fetchQueueStatus(); + const interval = setInterval(fetchQueueStatus, 5000); + return () => clearInterval(interval); + } + }); + function timeAgo(date: string | Date) { const d = new Date(date); const diff = Date.now() - d.getTime(); @@ -130,6 +173,39 @@ {/if} + +
+
+
+

Ranked Queue

+

Find a match at your skill level

+
+ {#if queueStatus?.inQueue} +
+ + + In queue ({queueStatus.queueSize} searching) + + +
+ {:else} + + {/if} +
+
+