Skip to content

Commit

Permalink
Hide code panel for viewers (#4729)
Browse files Browse the repository at this point in the history
* hide code panel for viewers

* remove unused field
  • Loading branch information
ruggi authored Jan 12, 2024
1 parent 6623745 commit aa95d5b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
6 changes: 4 additions & 2 deletions editor/src/components/editor/actions/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 => {
Expand Down
15 changes: 10 additions & 5 deletions editor/src/components/editor/editor-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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',
)
Expand Down
8 changes: 6 additions & 2 deletions editor/src/components/editor/store/collaborative-editing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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'
}
5 changes: 0 additions & 5 deletions editor/src/components/editor/store/editor-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,6 @@ export interface EditorState {
localProjectList: Array<ProjectListing>
projectList: Array<ProjectListing>
showcaseProjects: Array<ProjectListing>
codeEditingEnabled: boolean
codeEditorErrors: EditorStateCodeEditorErrors
thumbnailLastGenerated: number
pasteTargetsToIgnore: ElementPath[]
Expand Down Expand Up @@ -1508,7 +1507,6 @@ export function editorState(
localProjectList: Array<ProjectListing>,
projectList: Array<ProjectListing>,
showcaseProjects: Array<ProjectListing>,
codeEditingEnabled: boolean,
codeEditorErrors: EditorStateCodeEditorErrors,
thumbnailLastGenerated: number,
pasteTargetsToIgnore: ElementPath[],
Expand Down Expand Up @@ -1590,7 +1588,6 @@ export function editorState(
localProjectList: localProjectList,
projectList: projectList,
showcaseProjects: showcaseProjects,
codeEditingEnabled: codeEditingEnabled,
codeEditorErrors: codeEditorErrors,
thumbnailLastGenerated: thumbnailLastGenerated,
pasteTargetsToIgnore: pasteTargetsToIgnore,
Expand Down Expand Up @@ -2480,7 +2477,6 @@ export function createEditorState(dispatch: EditorDispatch): EditorState {
localProjectList: [],
projectList: [],
showcaseProjects: [],
codeEditingEnabled: false,
codeEditorErrors: {
buildErrors: {},
lintErrors: {},
Expand Down Expand Up @@ -2846,7 +2842,6 @@ export function editorModelFromPersistentModel(
localProjectList: [],
projectList: [],
showcaseProjects: [],
codeEditingEnabled: false,
thumbnailLastGenerated: 0,
pasteTargetsToIgnore: [],
parseOrPrintInFlight: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4428,10 +4428,6 @@ export const EditorStateKeepDeepEquality: KeepDeepEqualityCall<EditorState> = (
oldValue.showcaseProjects,
newValue.showcaseProjects,
)
const codeEditingEnabledResults = BooleanKeepDeepEquality(
oldValue.codeEditingEnabled,
newValue.codeEditingEnabled,
)
const codeEditorErrorsResults = EditorStateCodeEditorErrorsKeepDeepEquality(
oldValue.codeEditorErrors,
newValue.codeEditorErrors,
Expand Down Expand Up @@ -4592,7 +4588,6 @@ export const EditorStateKeepDeepEquality: KeepDeepEqualityCall<EditorState> = (
localProjectListResults.areEqual &&
projectListResults.areEqual &&
showcaseProjectsResults.areEqual &&
codeEditingEnabledResults.areEqual &&
codeEditorErrorsResults.areEqual &&
thumbnailLastGeneratedResults.areEqual &&
pasteTargetsToIgnoreResults.areEqual &&
Expand Down Expand Up @@ -4675,7 +4670,6 @@ export const EditorStateKeepDeepEquality: KeepDeepEqualityCall<EditorState> = (
localProjectListResults.value,
projectListResults.value,
showcaseProjectsResults.value,
codeEditingEnabledResults.value,
codeEditorErrorsResults.value,
thumbnailLastGeneratedResults.value,
pasteTargetsToIgnoreResults.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export const EmptyEditorStateForKeysOnly: EditorState = {
localProjectList: [],
projectList: [],
showcaseProjects: [],
codeEditingEnabled: false,
codeEditorErrors: {
buildErrors: {},
lintErrors: {},
Expand Down

0 comments on commit aa95d5b

Please sign in to comment.