From 3ae7eadfea4a1ac224be29f9668defe4ee209047 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Wed, 7 Jul 2021 14:02:48 +0100 Subject: [PATCH] Makes home a room --- pages/index.tsx | 2 +- pages/room/[id].tsx | 7 ++++++- state/coop/coop-state.ts | 5 +++-- state/state.ts | 6 ------ state/storage.ts | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 507f772d8..d7671b5b9 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -11,7 +11,7 @@ export default function Home(): JSX.Element { tldraw - + ) } diff --git a/pages/room/[id].tsx b/pages/room/[id].tsx index f23cfe1db..afff1a4cf 100644 --- a/pages/room/[id].tsx +++ b/pages/room/[id].tsx @@ -8,6 +8,7 @@ const Editor = dynamic(() => import('components/editor'), { ssr: false }) export default function Room({ id }: { id: string }): JSX.Element { useEffect(() => { + coopState.send('JOINED_ROOM', { id }) return () => { coopState.send('LEFT_ROOM') } @@ -18,9 +19,13 @@ export default function Room({ id }: { id: string }): JSX.Element { export const getServerSideProps: GetServerSideProps = async (context) => { const session = await getSession(context) - const { id } = context.query + if (!session?.user) { + context.res.setHeader('Location', `/sponsorware`) + context.res.statusCode = 307 + } + return { props: { session, diff --git a/state/coop/coop-state.ts b/state/coop/coop-state.ts index 8fa2d2779..6f629fd32 100644 --- a/state/coop/coop-state.ts +++ b/state/coop/coop-state.ts @@ -21,14 +21,15 @@ const coopState = createState({ states: { offline: { on: { - JOINED_ROOM: { to: 'online' }, + OPENED_ROOM: { to: 'online' }, }, }, online: { - onEnter: ['createClient', 'setOthers'], + onEnter: ['createClient', 'connectToRoom'], on: { MOVED_CURSOR: 'updateCursor', JOINED_ROOM: 'setOthers', + OPENED_ROOM: 'connectToRoom', CHANGED_CONNECTION_STATUS: 'setStatus', OTHER_USER_ENTERED: 'addOtherUser', OTHER_USER_LEFT: 'removeOtherUser', diff --git a/state/state.ts b/state/state.ts index 0a90a130d..76dea97b2 100644 --- a/state/state.ts +++ b/state/state.ts @@ -1112,15 +1112,9 @@ const state = createState({ }, }, conditions: { - hasRoomId(data, payload: { roomId?: string }) { - return payload?.roomId !== undefined - }, isSimulating() { return logger.isSimulating }, - hasRoom(_, payload: { id?: string }) { - return payload.id !== undefined - }, isEditingShape(data, payload: { id: string }) { return payload.id === data.editingId }, diff --git a/state/storage.ts b/state/storage.ts index 66846c6a1..470fc0b3c 100644 --- a/state/storage.ts +++ b/state/storage.ts @@ -4,7 +4,7 @@ import state from './state' import { uniqueId } from 'utils/utils' import * as idb from 'idb-keyval' -const CURRENT_VERSION = 'code_slate_0.0.8' +const CURRENT_VERSION = 'code_slate_0.0.9' function storageId(fileId: string, label: string, id?: string) { return [CURRENT_VERSION, fileId, label, id].filter(Boolean).join('_')