Skip to content

Commit

Permalink
set viewmode if share is readonly
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <[email protected]>
  • Loading branch information
grnd-alt committed Oct 14, 2024
1 parent 7f367e3 commit 7b0c427
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -92,7 +92,7 @@ export default function App({
= useState<ExcalidrawImperativeAPI | null>(null)
const [collab, setCollab] = useState<Collab | null>(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(
Expand Down
10 changes: 4 additions & 6 deletions src/collaboration/collab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ export class Collab {
fileId: number
portal: Portal
publicSharingToken: string | null
setViewModeEnabled: React.Dispatch<React.SetStateAction<boolean>>
lastBroadcastedOrReceivedSceneVersion: number = -1
private collaborators = new Map<string, Collaborator>()
private files = new Map<string, BinaryFileData>()

constructor(excalidrawAPI: ExcalidrawImperativeAPI, fileId: number, publicSharingToken: string | null) {
constructor(excalidrawAPI: ExcalidrawImperativeAPI, fileId: number, publicSharingToken: string | null, setViewModeEnabled: React.Dispatch<React.SetStateAction<boolean>>) {
this.excalidrawAPI = excalidrawAPI
this.fileId = fileId
this.publicSharingToken = publicSharingToken
this.setViewModeEnabled = setViewModeEnabled

this.portal = new Portal(`${fileId}`, this, publicSharingToken)
}
Expand Down Expand Up @@ -142,11 +144,7 @@ export class Collab {
}

makeBoardReadOnly = () => {
this.excalidrawAPI.updateScene({
appState: {
viewModeEnabled: true,
},
})
this.setViewModeEnabled(true)
}

addFile = (file: BinaryFileData) => {
Expand Down

0 comments on commit 7b0c427

Please sign in to comment.