diff --git a/editor/src/components/editor/actions/actions.tsx b/editor/src/components/editor/actions/actions.tsx index 53c5ec789edc..505067fae0f5 100644 --- a/editor/src/components/editor/actions/actions.tsx +++ b/editor/src/components/editor/actions/actions.tsx @@ -895,7 +895,6 @@ export function restoreEditorState( localProjectList: currentEditor.localProjectList, projectList: currentEditor.projectList, showcaseProjects: currentEditor.showcaseProjects, - codeEditingEnabled: desiredEditor.codeEditingEnabled, thumbnailLastGenerated: currentEditor.thumbnailLastGenerated, pasteTargetsToIgnore: desiredEditor.pasteTargetsToIgnore, codeEditorErrors: currentEditor.codeEditorErrors, @@ -3385,7 +3384,10 @@ export const UPDATE_FNS = { ): EditorModel => { return { ...editor, - codeEditingEnabled: action.value, + interfaceDesigner: { + ...editor.interfaceDesigner, + codePaneVisible: action.value, + }, } }, OPEN_CODE_EDITOR: (editor: EditorModel): EditorModel => { diff --git a/editor/src/components/editor/editor-component.tsx b/editor/src/components/editor/editor-component.tsx index 4cf0b9324734..fae13a391071 100644 --- a/editor/src/components/editor/editor-component.tsx +++ b/editor/src/components/editor/editor-component.tsx @@ -68,7 +68,7 @@ import LiveblocksProvider from '@liveblocks/yjs' import { isRoomId, projectIdToRoomId } from '../../core/shared/multiplayer' import { useDisplayOwnershipWarning } from './project-owner-hooks' import { EditorModes } from './editor-modes' -import { allowedToEditProject } from './store/collaborative-editing' +import { checkIsMyProject } from './store/collaborative-editing' import { useDataThemeAttributeOnBody } from '../../core/commenting/comment-hooks' import { CollaborationStateUpdater } from './store/collaboration-state' @@ -359,13 +359,18 @@ export const EditorComponentInner = React.memo((props: EditorProps) => { useSelectorWithCallback( Substores.projectServerState, (store) => store.projectServerState, - (isMyProject) => { - if (!allowedToEditProject(isMyProject)) { - dispatch([ + (serverState) => { + let actions: EditorAction[] = [] + if (!checkIsMyProject(serverState)) { + actions.push( EditorActions.switchEditorMode(EditorModes.commentMode(null, 'not-dragging')), EditorActions.setRightMenuTab(RightMenuTab.Comments), - ]) + EditorActions.setCodeEditorVisibility(false), + ) + } else { + actions.push(EditorActions.setCodeEditorVisibility(true)) } + dispatch(actions) }, 'EditorComponentInner viewer mode', ) diff --git a/editor/src/components/editor/store/collaborative-editing.ts b/editor/src/components/editor/store/collaborative-editing.ts index 6d5c9582e75e..12a4bda38cec 100644 --- a/editor/src/components/editor/store/collaborative-editing.ts +++ b/editor/src/components/editor/store/collaborative-editing.ts @@ -776,7 +776,7 @@ export function allowedToEditProject(serverState: ProjectServerState): boolean { if (isFeatureEnabled('Baton Passing For Control')) { return serverState.currentlyHolderOfTheBaton } else { - return serverState.isMyProject === 'yes' + return checkIsMyProject(serverState) } } @@ -791,7 +791,11 @@ export function useAllowedToEditProject(): boolean { export function useIsMyProject(): boolean { return useEditorState( Substores.projectServerState, - (store) => store.projectServerState.isMyProject === 'yes', + (store) => checkIsMyProject(store.projectServerState), 'useIsMyProject', ) } + +export function checkIsMyProject(serverState: ProjectServerState): boolean { + return serverState.isMyProject === 'yes' +} diff --git a/editor/src/components/editor/store/editor-state.ts b/editor/src/components/editor/store/editor-state.ts index 5439b35d8d02..afb8ca81fcea 100644 --- a/editor/src/components/editor/store/editor-state.ts +++ b/editor/src/components/editor/store/editor-state.ts @@ -1427,7 +1427,6 @@ export interface EditorState { localProjectList: Array projectList: Array showcaseProjects: Array - codeEditingEnabled: boolean codeEditorErrors: EditorStateCodeEditorErrors thumbnailLastGenerated: number pasteTargetsToIgnore: ElementPath[] @@ -1508,7 +1507,6 @@ export function editorState( localProjectList: Array, projectList: Array, showcaseProjects: Array, - codeEditingEnabled: boolean, codeEditorErrors: EditorStateCodeEditorErrors, thumbnailLastGenerated: number, pasteTargetsToIgnore: ElementPath[], @@ -1590,7 +1588,6 @@ export function editorState( localProjectList: localProjectList, projectList: projectList, showcaseProjects: showcaseProjects, - codeEditingEnabled: codeEditingEnabled, codeEditorErrors: codeEditorErrors, thumbnailLastGenerated: thumbnailLastGenerated, pasteTargetsToIgnore: pasteTargetsToIgnore, @@ -2480,7 +2477,6 @@ export function createEditorState(dispatch: EditorDispatch): EditorState { localProjectList: [], projectList: [], showcaseProjects: [], - codeEditingEnabled: false, codeEditorErrors: { buildErrors: {}, lintErrors: {}, @@ -2846,7 +2842,6 @@ export function editorModelFromPersistentModel( localProjectList: [], projectList: [], showcaseProjects: [], - codeEditingEnabled: false, thumbnailLastGenerated: 0, pasteTargetsToIgnore: [], parseOrPrintInFlight: false, diff --git a/editor/src/components/editor/store/store-deep-equality-instances.ts b/editor/src/components/editor/store/store-deep-equality-instances.ts index fedecfbb0bdb..518a421a58d6 100644 --- a/editor/src/components/editor/store/store-deep-equality-instances.ts +++ b/editor/src/components/editor/store/store-deep-equality-instances.ts @@ -4428,10 +4428,6 @@ export const EditorStateKeepDeepEquality: KeepDeepEqualityCall = ( oldValue.showcaseProjects, newValue.showcaseProjects, ) - const codeEditingEnabledResults = BooleanKeepDeepEquality( - oldValue.codeEditingEnabled, - newValue.codeEditingEnabled, - ) const codeEditorErrorsResults = EditorStateCodeEditorErrorsKeepDeepEquality( oldValue.codeEditorErrors, newValue.codeEditorErrors, @@ -4592,7 +4588,6 @@ export const EditorStateKeepDeepEquality: KeepDeepEqualityCall = ( localProjectListResults.areEqual && projectListResults.areEqual && showcaseProjectsResults.areEqual && - codeEditingEnabledResults.areEqual && codeEditorErrorsResults.areEqual && thumbnailLastGeneratedResults.areEqual && pasteTargetsToIgnoreResults.areEqual && @@ -4675,7 +4670,6 @@ export const EditorStateKeepDeepEquality: KeepDeepEqualityCall = ( localProjectListResults.value, projectListResults.value, showcaseProjectsResults.value, - codeEditingEnabledResults.value, codeEditorErrorsResults.value, thumbnailLastGeneratedResults.value, pasteTargetsToIgnoreResults.value, diff --git a/editor/src/components/editor/store/store-hook-substore-helpers.ts b/editor/src/components/editor/store/store-hook-substore-helpers.ts index 336193da1685..89bb124816a7 100644 --- a/editor/src/components/editor/store/store-hook-substore-helpers.ts +++ b/editor/src/components/editor/store/store-hook-substore-helpers.ts @@ -138,7 +138,6 @@ export const EmptyEditorStateForKeysOnly: EditorState = { localProjectList: [], projectList: [], showcaseProjects: [], - codeEditingEnabled: false, codeEditorErrors: { buildErrors: {}, lintErrors: {},