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 <salimbelakkaf@outlook.de>
  • Loading branch information
grnd-alt committed Oct 10, 2024
1 parent 7f367e3 commit 50fb2fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ 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)

const isDarkMode = () => {
const ncThemes = document.body.dataset?.themes
return (
(window.matchMedia('(prefers-color-scheme: dark)').matches
&& (ncThemes === undefined || ncThemes?.indexOf('light') === -1))
&& ncThemes?.indexOf('light') === -1)
|| ncThemes?.indexOf('dark') > -1
)
}
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 50fb2fc

Please sign in to comment.