radames commited on
Commit
012b226
1 Parent(s): 0ddef0e
frontend/src/routes/+layout.svelte ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ <script>
2
+ import '../app.css';
3
+ </script>
4
+
5
+ <slot />
frontend/src/routes/+page.svelte ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script context="module" lang="ts">
2
+ export const prerender = true;
3
+ </script>
4
+
5
+ <!--
6
+ The main code for this component is in src/PixelArtTogether.svelte
7
+ This file contains the Liveblocks providers, based on the
8
+ liveblocks-react library
9
+ https://liveblocks.io/docs/api-reference/liveblocks-react#LiveblocksProvider
10
+ -->
11
+ <script lang="ts">
12
+ import { onMount } from 'svelte';
13
+ import { createClient } from '@liveblocks/client';
14
+ import type { Client } from '@liveblocks/client';
15
+ import LiveblocksProvider from '$lib/liveblocks/LiveblocksProvider.svelte';
16
+ import RoomProvider from '$lib/liveblocks/RoomProvider.svelte';
17
+ import App from '$lib/App.svelte';
18
+ import type { PageData } from './$types';
19
+ import { PUBLIC_API_BASE } from '$env/static/public';
20
+ import { selectedRoomID } from '$lib/store';
21
+ export let data: PageData;
22
+
23
+ let rooms = data.rooms;
24
+ let loaded = false;
25
+ let client: Client;
26
+
27
+ $: roomId = rooms.find((room) => room.id === $selectedRoomID)?.room_id;
28
+
29
+ $:{
30
+ console.log("ROOM ID", $selectedRoomID);
31
+ }
32
+ onMount(() => {
33
+ // document.addEventListener('wheel', (e) => e.preventDefault(), { passive: false });
34
+ client = createClient({
35
+ authEndpoint: PUBLIC_API_BASE + '/auth'
36
+ });
37
+
38
+ loaded = true;
39
+ });
40
+ </script>
41
+
42
+ {#if loaded}
43
+ <LiveblocksProvider {client}>
44
+ {#if roomId}
45
+ <RoomProvider id={roomId}>
46
+ <App />
47
+ </RoomProvider>
48
+ {:else}
49
+ <div class="flex flex-col items-center justify-center h-full">
50
+ <h1 class="text-2xl font-bold">No room selected</h1>
51
+ <p class="text-gray-500">Please select a room in the URL</p>
52
+ </div>
53
+ {/if}
54
+ </LiveblocksProvider>
55
+ {/if}
frontend/src/routes/+page.ts ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { PUBLIC_API_BASE } from '$env/static/public';
2
+ import type { RoomResponse } from '$lib/types';
3
+ import { selectedRoomID } from '$lib/store';
4
+ import { MAX_CAPACITY } from '$lib/constants';
5
+ import type { PageLoad } from './$types';
6
+ export const prerender = true
7
+ export const ssr = false
8
+
9
+ export const load: PageLoad = async ({ url }) => {
10
+ const roomidParam = url.searchParams.get('roomid');
11
+ const res = await fetch(PUBLIC_API_BASE + '/rooms');
12
+ const rooms: RoomResponse[] = await res.json();
13
+
14
+ if (roomidParam) {
15
+ const room = rooms.find(room => room.room_id === roomidParam);
16
+ if (room) {
17
+ selectedRoomID.set(room.id);
18
+ }
19
+ } else {
20
+ const room = rooms.find(room => room.users_count < MAX_CAPACITY) || null;
21
+ selectedRoomID.set(room ? room.id : null);
22
+ }
23
+ return { rooms };
24
+ }