2022-07-08 13:09:08 +00:00
|
|
|
import { Tldraw, useFileSystem } from '@tldraw/tldraw'
|
2022-08-02 13:56:12 +00:00
|
|
|
import * as React from 'react'
|
|
|
|
import { useReadOnlyMultiplayerState } from '~hooks/useReadOnlyMultiplayerState'
|
|
|
|
import { styled } from '~styles'
|
|
|
|
import { RoomProvider } from '~utils/liveblocks'
|
2022-07-08 13:09:08 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
roomId: string
|
|
|
|
}
|
|
|
|
|
2022-07-23 14:05:48 +00:00
|
|
|
const ReadOnlyMultiplayerEditor = ({ roomId }: Props) => {
|
2022-07-08 13:09:08 +00:00
|
|
|
return (
|
|
|
|
<RoomProvider id={roomId}>
|
2022-07-23 14:05:48 +00:00
|
|
|
<ReadOnlyEditor roomId={roomId} />
|
2022-07-08 13:09:08 +00:00
|
|
|
</RoomProvider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inner Editor
|
|
|
|
|
2022-07-23 14:05:48 +00:00
|
|
|
function ReadOnlyEditor({ roomId }: Props) {
|
2022-07-08 13:09:08 +00:00
|
|
|
const { onSaveProjectAs, onSaveProject } = useFileSystem()
|
|
|
|
const { error, ...events } = useReadOnlyMultiplayerState(roomId)
|
|
|
|
|
|
|
|
if (error) return <LoadingScreen>Error: {error.message}</LoadingScreen>
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="tldraw">
|
|
|
|
<Tldraw
|
|
|
|
autofocus
|
|
|
|
disableAssets={false}
|
|
|
|
showPages={false}
|
|
|
|
onSaveProjectAs={onSaveProjectAs}
|
|
|
|
onSaveProject={onSaveProject}
|
|
|
|
readOnly
|
|
|
|
{...events}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ReadOnlyMultiplayerEditor
|
|
|
|
|
|
|
|
const LoadingScreen = styled('div', {
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
})
|