Skip to content

Commit

Permalink
feat: params on scout route
Browse files Browse the repository at this point in the history
  • Loading branch information
azaleacolburn committed Nov 19, 2024
1 parent 63b0eeb commit 986b6dc
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="flex flex-col items-center justify-evenly h-dvh text-text_white">
<h1 class="text-center text-5xl font-bold">hiiii :3</h1>
<a class="text-center text-2xl rounded bg-btn_grey px-4 py-2 font-bold" href="/scout">
<a class="text-center text-2xl rounded bg-btn_grey px-4 py-2 font-bold" href="/queue">
scout
</a>
</div>
12 changes: 10 additions & 2 deletions src/routes/queue/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { io } from 'socket.io-client';
const socket = io();
socket.on('messageFromServer', (message) => {
console.log(message);
socket.on('connect', () => {
console.log(socket.id);
socket.emit('join_queue');
});
socket.on('time_to_scout', ([team_key, color]: [string, 'red' | 'blue']) => {
goto(`/scout/${team_key}_${color}`);
});
</script>

<h1>In Queue</h1>
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
import { type TeamMatch, type AutoActionData } from '$lib/types';
import Timeline from '$lib/components/Timeline.svelte';
import ActionInputs from './ActionInputs.svelte';
import { browser } from '$app/environment';
import type { PageData } from './$types';
const {
match_key,
team_key = '1540',
scout_id
}: { match_key: string; team_key: string; scout_id: string } = $props();
const { data }: { data: PageData } = $props();
const scout_id = browser ? localStorage.getItem('scout_id')! : '';
let actions: AutoActionData[] = $state([]);
let timelineExtended = $state(false);
const match: TeamMatch = $state({
id: 0,
scout_id,
team_key,
match_key,
scout_id: scout_id,
team_key: data.team_key,
match_key: data.match_key,
skill: 3,
notes: '',
broke: false,
Expand All @@ -27,7 +26,7 @@
</script>

<div class="grid grid-row-10 text-zinc-50 p-2 h-svh place-items-center">
<h1 class="row-span-1 text-center font-bold pb-2 h-5">Team {team_key}</h1>
<h1 class="row-span-1 text-center font-bold pb-2 h-5">Team {data.team_key}</h1>
{#if timelineExtended}
<div class="row-span-8">
<Timeline bind:actions />
Expand Down
16 changes: 16 additions & 0 deletions src/routes/scout/[team_data]/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { PageLoad } from './$types';
import { error } from '@sveltejs/kit';

export const load: PageLoad = ({ params }) => {
const [match_key, team_key, color]: [string, string, 'red' | 'blue'] | undefined =
params.team_data?.split('_') as [string, string, 'red' | 'blue'];

// TODO: Check if this does anything
if (!team_key) return error(400, 'Bad query parameters');
console.log('match_key: ' + color);
return {
match_key: match_key,
team_key: team_key,
color: color
};
};
File renamed without changes.
12 changes: 7 additions & 5 deletions ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const webSocketServer = {
socket.join('scout_queue');
return;
}
socket.emit('time_to_scout', team_data);
socket.emit('time_to_scout', [curr_match_key, ...team_data]);
});

socket.on('leave_queue', (_) => {
Expand All @@ -32,12 +32,14 @@ const webSocketServer = {
if (!socket.rooms.has('admin_room')) return;

const scout_queue: Set<string> = io.of('/').adapter.rooms.get('scout_queue')!;
scout_queue
.values()
.forEach((sid) => io.to(sid).emit('time_to_scout', teams.pop()));
for (const sid of scout_queue.values()) {
const team_data = teams.pop();
if (!team_data) break;

io.to(sid).emit('time_to_scout', [match_key, ...team_data]);
}
robotQueue.push(...teams);

// TODO: Decide if we care about this
// Update all connected sockets with new match info (for cosmetic purposes)
io.emit('new_match', match_key);
curr_match_key = match_key;
Expand Down

0 comments on commit 986b6dc

Please sign in to comment.