Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set viewmode if share is readonly #216

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverting your previous fix? 😁

&& 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
Loading