Makes home a room

This commit is contained in:
Steve Ruiz 2021-07-07 14:02:48 +01:00
parent ad0ce1ba3a
commit 3ae7eadfea
5 changed files with 11 additions and 11 deletions

View file

@ -11,7 +11,7 @@ export default function Home(): JSX.Element {
<Head>
<title>tldraw</title>
</Head>
<Editor />
<Editor roomId="home" />
</>
)
}

View file

@ -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,

View file

@ -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',

View file

@ -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
},

View file

@ -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('_')