diff --git a/src/App.tsx b/src/App.tsx index 7ffc271..55b6b0d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -45,7 +45,7 @@ export default function App({ }: WhiteboardAppProps) { const fileNameWithoutExtension = fileName.split('.').slice(0, -1).join('.') - const [viewModeEnabled] = useState(isEmbedded) + const [viewModeEnabled, setViewModeEnabled] = useState(isEmbedded) const [zenModeEnabled] = useState(isEmbedded) const [gridModeEnabled] = useState(false) @@ -92,7 +92,7 @@ export default function App({ = useState(null) const [collab, setCollab] = useState(null) - if (excalidrawAPI && !collab) { setCollab(new Collab(excalidrawAPI, fileId, publicSharingToken)) } + if (excalidrawAPI && !collab) { setCollab(new Collab(excalidrawAPI, fileId, publicSharingToken, setViewModeEnabled)) } if (collab && !collab.portal.socket) collab.startCollab() useEffect(() => { const extraTools = document.getElementsByClassName( diff --git a/src/collaboration/collab.ts b/src/collaboration/collab.ts index af598f5..8e1a471 100644 --- a/src/collaboration/collab.ts +++ b/src/collaboration/collab.ts @@ -16,14 +16,16 @@ export class Collab { fileId: number portal: Portal publicSharingToken: string | null + setViewModeEnabled: React.Dispatch> lastBroadcastedOrReceivedSceneVersion: number = -1 private collaborators = new Map() private files = new Map() - constructor(excalidrawAPI: ExcalidrawImperativeAPI, fileId: number, publicSharingToken: string | null) { + constructor(excalidrawAPI: ExcalidrawImperativeAPI, fileId: number, publicSharingToken: string | null, setViewModeEnabled: React.Dispatch>) { this.excalidrawAPI = excalidrawAPI this.fileId = fileId this.publicSharingToken = publicSharingToken + this.setViewModeEnabled = setViewModeEnabled this.portal = new Portal(`${fileId}`, this, publicSharingToken) } @@ -142,11 +144,7 @@ export class Collab { } makeBoardReadOnly = () => { - this.excalidrawAPI.updateScene({ - appState: { - viewModeEnabled: true, - }, - }) + this.setViewModeEnabled(true) } addFile = (file: BinaryFileData) => {