Skip to content

Commit

Permalink
No comment mode when logged out (#4541)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbalint authored Nov 22, 2023
1 parent e45e28e commit e6e8fd2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions editor/src/components/editor/actions/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ import type {
} from '../action-types'
import { isLoggedIn } from '../action-types'
import type { Mode } from '../editor-modes'
import { isFollowMode, isTextEditMode } from '../editor-modes'
import { isCommentMode, isFollowMode, isTextEditMode } from '../editor-modes'
import { EditorModes, isLiveMode, isSelectMode } from '../editor-modes'
import * as History from '../history'
import type { StateHistory } from '../history'
Expand Down Expand Up @@ -2054,7 +2054,7 @@ export const UPDATE_FNS = {
SWITCH_EDITOR_MODE: (
action: SwitchEditorMode,
editor: EditorModel,
derived: DerivedState,
userState: UserState,
): EditorModel => {
// TODO this should probably be merged with UPDATE_EDITOR_MODE
if (action.unlessMode === editor.mode.type) {
Expand All @@ -2076,6 +2076,9 @@ export const UPDATE_FNS = {
return editor
}
}
if (isCommentMode(action.mode) && !isLoggedIn(userState.loginState)) {
return editor
}
return setModeState(action.mode, editor)
},
TOGGLE_CANVAS_IS_LIVE: (editor: EditorModel, derived: DerivedState): EditorModel => {
Expand Down Expand Up @@ -3078,7 +3081,6 @@ export const UPDATE_FNS = {
SAVE_ASSET: (
action: SaveAsset,
editor: EditorModel,
derived: DerivedState,
dispatch: EditorDispatch,
userState: UserState,
): EditorModel => {
Expand Down Expand Up @@ -3220,7 +3222,7 @@ export const UPDATE_FNS = {
const editorInsertEnabled = UPDATE_FNS.SWITCH_EDITOR_MODE(
switchMode,
editorWithToast,
derived,
userState,
)
return {
...editorInsertEnabled,
Expand Down Expand Up @@ -3302,7 +3304,7 @@ export const UPDATE_FNS = {
INSERT_IMAGE_INTO_UI: (
action: InsertImageIntoUI,
editor: EditorModel,
derived: DerivedState,
userState: UserState,
): EditorModel => {
const possiblyAnImage = getProjectFileByFilePath(editor.projectContents, action.imagePath)
if (possiblyAnImage != null && isImageFile(possiblyAnImage)) {
Expand Down Expand Up @@ -3332,7 +3334,7 @@ export const UPDATE_FNS = {
)
const size = width != null && height != null ? { width: width, height: height } : null
const switchMode = enableInsertModeForJSXElement(imageElement, newUID, {}, size)
return UPDATE_FNS.SWITCH_EDITOR_MODE(switchMode, editor, derived)
return UPDATE_FNS.SWITCH_EDITOR_MODE(switchMode, editor, userState)
} else {
return editor
}
Expand Down
6 changes: 3 additions & 3 deletions editor/src/components/editor/store/editor-update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function runLocalEditorAction(
case 'DISTRIBUTE_SELECTED_VIEWS':
return UPDATE_FNS.DISTRIBUTE_SELECTED_VIEWS(action, state)
case 'SAVE_ASSET':
return UPDATE_FNS.SAVE_ASSET(action, state, derivedState, dispatch, userState)
return UPDATE_FNS.SAVE_ASSET(action, state, dispatch, userState)
default:
return runSimpleLocalEditorAction(
state,
Expand Down Expand Up @@ -105,7 +105,7 @@ export function runSimpleLocalEditorAction(
case 'UPDATE_EDITOR_MODE':
return UPDATE_FNS.UPDATE_EDITOR_MODE(action, state)
case 'SWITCH_EDITOR_MODE':
return UPDATE_FNS.SWITCH_EDITOR_MODE(action, state, derivedState)
return UPDATE_FNS.SWITCH_EDITOR_MODE(action, state, userState)
case 'TOGGLE_HIDDEN':
return UPDATE_FNS.TOGGLE_HIDDEN(action, state)
case 'RENAME_COMPONENT':
Expand Down Expand Up @@ -274,7 +274,7 @@ export function runSimpleLocalEditorAction(
case 'UNWRAP_ELEMENTS':
return UPDATE_FNS.UNWRAP_ELEMENTS(action, state, dispatch, builtInDependencies)
case 'INSERT_IMAGE_INTO_UI':
return UPDATE_FNS.INSERT_IMAGE_INTO_UI(action, state, derivedState)
return UPDATE_FNS.INSERT_IMAGE_INTO_UI(action, state, userState)
case 'UPDATE_JSX_ELEMENT_NAME':
return UPDATE_FNS.UPDATE_JSX_ELEMENT_NAME(action, state)
case 'ADD_IMPORTS':
Expand Down

0 comments on commit e6e8fd2

Please sign in to comment.