Makes home a room
This commit is contained in:
parent
ad0ce1ba3a
commit
3ae7eadfea
5 changed files with 11 additions and 11 deletions
|
@ -11,7 +11,7 @@ export default function Home(): JSX.Element {
|
||||||
<Head>
|
<Head>
|
||||||
<title>tldraw</title>
|
<title>tldraw</title>
|
||||||
</Head>
|
</Head>
|
||||||
<Editor />
|
<Editor roomId="home" />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ const Editor = dynamic(() => import('components/editor'), { ssr: false })
|
||||||
|
|
||||||
export default function Room({ id }: { id: string }): JSX.Element {
|
export default function Room({ id }: { id: string }): JSX.Element {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
coopState.send('JOINED_ROOM', { id })
|
||||||
return () => {
|
return () => {
|
||||||
coopState.send('LEFT_ROOM')
|
coopState.send('LEFT_ROOM')
|
||||||
}
|
}
|
||||||
|
@ -18,9 +19,13 @@ export default function Room({ id }: { id: string }): JSX.Element {
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
const session = await getSession(context)
|
const session = await getSession(context)
|
||||||
|
|
||||||
const { id } = context.query
|
const { id } = context.query
|
||||||
|
|
||||||
|
if (!session?.user) {
|
||||||
|
context.res.setHeader('Location', `/sponsorware`)
|
||||||
|
context.res.statusCode = 307
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
session,
|
session,
|
||||||
|
|
|
@ -21,14 +21,15 @@ const coopState = createState({
|
||||||
states: {
|
states: {
|
||||||
offline: {
|
offline: {
|
||||||
on: {
|
on: {
|
||||||
JOINED_ROOM: { to: 'online' },
|
OPENED_ROOM: { to: 'online' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
online: {
|
online: {
|
||||||
onEnter: ['createClient', 'setOthers'],
|
onEnter: ['createClient', 'connectToRoom'],
|
||||||
on: {
|
on: {
|
||||||
MOVED_CURSOR: 'updateCursor',
|
MOVED_CURSOR: 'updateCursor',
|
||||||
JOINED_ROOM: 'setOthers',
|
JOINED_ROOM: 'setOthers',
|
||||||
|
OPENED_ROOM: 'connectToRoom',
|
||||||
CHANGED_CONNECTION_STATUS: 'setStatus',
|
CHANGED_CONNECTION_STATUS: 'setStatus',
|
||||||
OTHER_USER_ENTERED: 'addOtherUser',
|
OTHER_USER_ENTERED: 'addOtherUser',
|
||||||
OTHER_USER_LEFT: 'removeOtherUser',
|
OTHER_USER_LEFT: 'removeOtherUser',
|
||||||
|
|
|
@ -1112,15 +1112,9 @@ const state = createState({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
conditions: {
|
conditions: {
|
||||||
hasRoomId(data, payload: { roomId?: string }) {
|
|
||||||
return payload?.roomId !== undefined
|
|
||||||
},
|
|
||||||
isSimulating() {
|
isSimulating() {
|
||||||
return logger.isSimulating
|
return logger.isSimulating
|
||||||
},
|
},
|
||||||
hasRoom(_, payload: { id?: string }) {
|
|
||||||
return payload.id !== undefined
|
|
||||||
},
|
|
||||||
isEditingShape(data, payload: { id: string }) {
|
isEditingShape(data, payload: { id: string }) {
|
||||||
return payload.id === data.editingId
|
return payload.id === data.editingId
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@ import state from './state'
|
||||||
import { uniqueId } from 'utils/utils'
|
import { uniqueId } from 'utils/utils'
|
||||||
import * as idb from 'idb-keyval'
|
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) {
|
function storageId(fileId: string, label: string, id?: string) {
|
||||||
return [CURRENT_VERSION, fileId, label, id].filter(Boolean).join('_')
|
return [CURRENT_VERSION, fileId, label, id].filter(Boolean).join('_')
|
||||||
|
|
Loading…
Reference in a new issue