Spaces:
Runtime error
Runtime error
fix url redirect
Browse files- frontend/src/lib/App.svelte +1 -1
- frontend/src/lib/Buttons/RoomsSelector.svelte +4 -4
- frontend/src/lib/PaintCanvas.svelte +1 -1
- frontend/src/lib/PaintFrame.svelte +1 -1
- frontend/src/lib/PromptModal.svelte +1 -1
- frontend/src/lib/constants.ts +1 -1
- frontend/src/lib/liveblocks/useMyPresence.ts +4 -3
- frontend/src/lib/liveblocks/useUpdateMyPresence.ts +1 -1
- frontend/src/routes/+page.svelte +13 -6
frontend/src/lib/App.svelte
CHANGED
@@ -15,7 +15,7 @@
|
|
15 |
import { base64ToBlob, uploadImage } from '$lib/utils';
|
16 |
import { nanoid } from 'nanoid';
|
17 |
|
18 |
-
const myPresence = useMyPresence();
|
19 |
const others = useOthers();
|
20 |
|
21 |
function getKey(position: { x: number; y: number }): PromptImgKey {
|
|
|
15 |
import { base64ToBlob, uploadImage } from '$lib/utils';
|
16 |
import { nanoid } from 'nanoid';
|
17 |
|
18 |
+
const myPresence = useMyPresence({ addToHistory: true });
|
19 |
const others = useOthers();
|
20 |
|
21 |
function getKey(position: { x: number; y: number }): PromptImgKey {
|
frontend/src/lib/Buttons/RoomsSelector.svelte
CHANGED
@@ -20,7 +20,7 @@
|
|
20 |
$: loadingRooms = $rooms.length > 0;
|
21 |
|
22 |
function clickHandler(event: Event) {
|
23 |
-
if (!boxEl.contains(event.target as Node)) {
|
24 |
collapsed = true;
|
25 |
}
|
26 |
}
|
@@ -59,7 +59,7 @@
|
|
59 |
<People />
|
60 |
<span> players </span>
|
61 |
</li>
|
62 |
-
{#each $rooms as room}
|
63 |
<li>
|
64 |
<!-- svelte-ignore a11y-invalid-attribute -->
|
65 |
<a
|
@@ -73,7 +73,7 @@
|
|
73 |
<Pin />
|
74 |
{/if}
|
75 |
</span>
|
76 |
-
<span>room {room.
|
77 |
<span />
|
78 |
<span />
|
79 |
<span>{room.users_count} / {MAX_CAPACITY}</span>
|
@@ -93,7 +93,7 @@
|
|
93 |
<div class="grid-row gap-2">
|
94 |
<Room />
|
95 |
<span>
|
96 |
-
room {selectedRoom?.
|
97 |
</span>
|
98 |
<span />
|
99 |
<People />
|
|
|
20 |
$: loadingRooms = $rooms.length > 0;
|
21 |
|
22 |
function clickHandler(event: Event) {
|
23 |
+
if (boxEl && !boxEl.contains(event.target as Node)) {
|
24 |
collapsed = true;
|
25 |
}
|
26 |
}
|
|
|
59 |
<People />
|
60 |
<span> players </span>
|
61 |
</li>
|
62 |
+
{#each $rooms as room, i}
|
63 |
<li>
|
64 |
<!-- svelte-ignore a11y-invalid-attribute -->
|
65 |
<a
|
|
|
73 |
<Pin />
|
74 |
{/if}
|
75 |
</span>
|
76 |
+
<span>room {room.room_id.split('-')[3]} </span>
|
77 |
<span />
|
78 |
<span />
|
79 |
<span>{room.users_count} / {MAX_CAPACITY}</span>
|
|
|
93 |
<div class="grid-row gap-2">
|
94 |
<Room />
|
95 |
<span>
|
96 |
+
room {selectedRoom?.room_id.split('-')[3]}
|
97 |
</span>
|
98 |
<span />
|
99 |
<People />
|
frontend/src/lib/PaintCanvas.svelte
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
import type { PromptImgObject } from '$lib/types';
|
11 |
import { CANVAS_SIZE, FRAME_SIZE, GRID_SIZE } from '$lib/constants';
|
12 |
|
13 |
-
const myPresence = useMyPresence();
|
14 |
const promptImgStorage = useObject('promptImgStorage');
|
15 |
|
16 |
const height = CANVAS_SIZE.height;
|
|
|
10 |
import type { PromptImgObject } from '$lib/types';
|
11 |
import { CANVAS_SIZE, FRAME_SIZE, GRID_SIZE } from '$lib/constants';
|
12 |
|
13 |
+
const myPresence = useMyPresence({ addToHistory: true });
|
14 |
const promptImgStorage = useObject('promptImgStorage');
|
15 |
|
16 |
const height = CANVAS_SIZE.height;
|
frontend/src/lib/PaintFrame.svelte
CHANGED
@@ -13,7 +13,7 @@
|
|
13 |
import { canvasEl, maskEl, loadingState } from '$lib/store';
|
14 |
|
15 |
import { Status } from './types';
|
16 |
-
const myPresence = useMyPresence();
|
17 |
|
18 |
const dispatch = createEventDispatcher();
|
19 |
|
|
|
13 |
import { canvasEl, maskEl, loadingState } from '$lib/store';
|
14 |
|
15 |
import { Status } from './types';
|
16 |
+
const myPresence = useMyPresence({ addToHistory: true });
|
17 |
|
18 |
const dispatch = createEventDispatcher();
|
19 |
|
frontend/src/lib/PromptModal.svelte
CHANGED
@@ -8,7 +8,7 @@
|
|
8 |
let prompt: string;
|
9 |
let inputEl: HTMLInputElement;
|
10 |
let boxEl: HTMLDivElement;
|
11 |
-
const myPresence =
|
12 |
|
13 |
const onKeyup = (e: KeyboardEvent) => {
|
14 |
if (e.key === 'Escape') {
|
|
|
8 |
let prompt: string;
|
9 |
let inputEl: HTMLInputElement;
|
10 |
let boxEl: HTMLDivElement;
|
11 |
+
const myPresence = useMyPresence({ addToHistory: true });
|
12 |
|
13 |
const onKeyup = (e: KeyboardEvent) => {
|
14 |
if (e.key === 'Escape') {
|
frontend/src/lib/constants.ts
CHANGED
@@ -14,7 +14,7 @@ export const COLORS = [
|
|
14 |
export const EMOJIS = ['π', 'π', 'π', 'π', 'π¦', 'π', 'π', 'π', 'π¦', 'π¦', 'π·', 'π¦', 'π’', 'π', 'π¦', 'π¦', 'π¦', 'π', 'π¦', 'π ', 'π', 'π‘', 'π¬', 'π¦', 'π³', 'π', 'π', 'π
', 'π', 'π¦', 'π¦', 'π¦§', 'π', 'π¦', 'π¦', 'πͺ', 'π«', 'π¦', 'π', 'π', 'π', 'π', 'π',
|
15 |
'π', 'π', 'π', 'π', 'π©', 'π', 'π', 'π¦', 'π¦
', 'π¦', 'π¦’', 'π¦', 'π¦', 'π¦', 'π¦', 'π', 'π', 'πΏ', 'π', 'πΏ', 'π¦', 'π¦', 'π»', 'π»', 'π¨', 'πΌ', 'π΅', 'π', 'π', 'π', 'π', 'π', 'π²', 'π¦', 'π¦', 'π', 'π’', 'π¦', 'π', 'π¦', 'π§', 'π¦
', 'π¦', 'π¦', 'π¦']
|
16 |
|
17 |
-
export const MAX_CAPACITY =
|
18 |
|
19 |
export const CANVAS_SIZE = {
|
20 |
width: 512 * 8,
|
|
|
14 |
export const EMOJIS = ['π', 'π', 'π', 'π', 'π¦', 'π', 'π', 'π', 'π¦', 'π¦', 'π·', 'π¦', 'π’', 'π', 'π¦', 'π¦', 'π¦', 'π', 'π¦', 'π ', 'π', 'π‘', 'π¬', 'π¦', 'π³', 'π', 'π', 'π
', 'π', 'π¦', 'π¦', 'π¦§', 'π', 'π¦', 'π¦', 'πͺ', 'π«', 'π¦', 'π', 'π', 'π', 'π', 'π',
|
15 |
'π', 'π', 'π', 'π', 'π©', 'π', 'π', 'π¦', 'π¦
', 'π¦', 'π¦’', 'π¦', 'π¦', 'π¦', 'π¦', 'π', 'π', 'πΏ', 'π', 'πΏ', 'π¦', 'π¦', 'π»', 'π»', 'π¨', 'πΌ', 'π΅', 'π', 'π', 'π', 'π', 'π', 'π²', 'π¦', 'π¦', 'π', 'π’', 'π¦', 'π', 'π¦', 'π§', 'π¦
', 'π¦', 'π¦', 'π¦']
|
16 |
|
17 |
+
export const MAX_CAPACITY = 10;
|
18 |
|
19 |
export const CANVAS_SIZE = {
|
20 |
width: 512 * 8,
|
frontend/src/lib/liveblocks/useMyPresence.ts
CHANGED
@@ -20,12 +20,13 @@ import { useRoom } from "./useRoom";
|
|
20 |
* it takes an object and works like `useUpdateMyPresence` in Liveblocks
|
21 |
*/
|
22 |
|
23 |
-
export function useMyPresence(
|
24 |
const room = useRoom();
|
25 |
const { subscribe, set } = writable<Presence>();
|
26 |
|
27 |
-
function update(newPresence
|
28 |
-
|
|
|
29 |
}
|
30 |
|
31 |
const unsubscribePresence = room.subscribe("my-presence", (presence) => {
|
|
|
20 |
* it takes an object and works like `useUpdateMyPresence` in Liveblocks
|
21 |
*/
|
22 |
|
23 |
+
export function useMyPresence(_options: { addToHistory: boolean } = {}) {
|
24 |
const room = useRoom();
|
25 |
const { subscribe, set } = writable<Presence>();
|
26 |
|
27 |
+
function update(newPresence, options?: { addToHistory: boolean }
|
28 |
+
) {
|
29 |
+
room.updatePresence(newPresence, { ..._options, ...options });
|
30 |
}
|
31 |
|
32 |
const unsubscribePresence = room.subscribe("my-presence", (presence) => {
|
frontend/src/lib/liveblocks/useUpdateMyPresence.ts
CHANGED
@@ -15,6 +15,6 @@ import { useMyPresence } from "./useMyPresence";
|
|
15 |
*/
|
16 |
|
17 |
export function useUpdateMyPresence(): (val: any) => void {
|
18 |
-
const presence = useMyPresence();
|
19 |
return (updatedPresence) => presence.update(updatedPresence);
|
20 |
}
|
|
|
15 |
*/
|
16 |
|
17 |
export function useUpdateMyPresence(): (val: any) => void {
|
18 |
+
const presence = useMyPresence({ addToHistory: true });
|
19 |
return (updatedPresence) => presence.update(updatedPresence);
|
20 |
}
|
frontend/src/routes/+page.svelte
CHANGED
@@ -32,15 +32,22 @@
|
|
32 |
const roomidParam = new URLSearchParams(window.location.search).get('roomid');
|
33 |
const res = await fetch(PUBLIC_API_BASE + '/rooms');
|
34 |
const rooms: RoomResponse[] = await res.json();
|
|
|
35 |
|
|
|
36 |
if (roomidParam) {
|
37 |
-
const room = rooms.find((room) => room.room_id === roomidParam);
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
40 |
}
|
41 |
-
}
|
42 |
-
|
43 |
-
selectedRoomID.set(
|
|
|
|
|
44 |
}
|
45 |
loading = false;
|
46 |
return { rooms };
|
|
|
32 |
const roomidParam = new URLSearchParams(window.location.search).get('roomid');
|
33 |
const res = await fetch(PUBLIC_API_BASE + '/rooms');
|
34 |
const rooms: RoomResponse[] = await res.json();
|
35 |
+
const emptyRoom = rooms.find((room) => room.users_count < MAX_CAPACITY) || null;
|
36 |
|
37 |
+
let roomAvailable = false;
|
38 |
if (roomidParam) {
|
39 |
+
const room = rooms.find((room) => room.room_id === roomidParam) || null;
|
40 |
+
roomAvailable = room ? room.users_count < MAX_CAPACITY : false;
|
41 |
+
if (room && roomAvailable) {
|
42 |
+
$selectedRoomID = room.room_id;
|
43 |
+
const state = { roomid: room.room_id };
|
44 |
+
window.history.replaceState(null, '', '?' + new URLSearchParams(state).toString());
|
45 |
}
|
46 |
+
}
|
47 |
+
if (emptyRoom && !roomAvailable) {
|
48 |
+
selectedRoomID.set(emptyRoom.room_id);
|
49 |
+
const state = { roomid: emptyRoom.room_id };
|
50 |
+
window.history.replaceState(null, '', '?' + new URLSearchParams(state).toString());
|
51 |
}
|
52 |
loading = false;
|
53 |
return { rooms };
|