refactor: hide unnecessary header options on mobile when typing in super note [skip e2e]

This commit is contained in:
Aman Harwara
2024-02-28 21:09:14 +05:30
parent 89491870eb
commit c42bfdcd2a
3 changed files with 28 additions and 17 deletions

View File

@@ -75,7 +75,7 @@ type State = {
stackComponentViewers: ComponentViewerInterface[] stackComponentViewers: ComponentViewerInterface[]
syncTakingTooLong: boolean syncTakingTooLong: boolean
monospaceFont?: boolean monospaceFont?: boolean
plainEditorFocused?: boolean editorFocused?: boolean
paneGestureEnabled?: boolean paneGestureEnabled?: boolean
noteLastEditedByUuid?: string noteLastEditedByUuid?: string
updateSavingIndicator?: boolean updateSavingIndicator?: boolean
@@ -780,15 +780,15 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
} }
} }
onPlainFocus = () => { onEditorFocus = () => {
this.setState({ plainEditorFocused: true }) this.setState({ editorFocused: true })
} }
onPlainBlur = (event: FocusEvent) => { onEditorBlur = (event: FocusEvent) => {
if (event.relatedTarget?.id === ElementIds.NoteOptionsButton) { if (event.relatedTarget?.id === ElementIds.NoteOptionsButton) {
return return
} }
this.setState({ plainEditorFocused: false }) this.setState({ editorFocused: false })
} }
toggleConflictResolutionModal = () => { toggleConflictResolutionModal = () => {
@@ -817,7 +817,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
) )
} }
const renderHeaderOptions = isMobileScreen() ? !this.state.plainEditorFocused : true const renderHeaderOptions = isMobileScreen() ? !this.state.editorFocused : true
const editorMode = const editorMode =
this.note.noteType === NoteType.Super this.note.noteType === NoteType.Super
@@ -930,7 +930,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
onClickPreprocessing={this.ensureNoteIsInsertedBeforeUIAction} onClickPreprocessing={this.ensureNoteIsInsertedBeforeUIAction}
onButtonBlur={() => { onButtonBlur={() => {
this.setState({ this.setState({
plainEditorFocused: false, editorFocused: false,
}) })
}} }}
/> />
@@ -983,8 +983,8 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
ref={this.setPlainEditorRef} ref={this.setPlainEditorRef}
controller={this.controller} controller={this.controller}
locked={this.state.noteLocked || !!this.state.readonly} locked={this.state.noteLocked || !!this.state.readonly}
onFocus={this.onPlainFocus} onFocus={this.onEditorFocus}
onBlur={this.onPlainBlur} onBlur={this.onEditorBlur}
/> />
)} )}
@@ -998,6 +998,8 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
spellcheck={this.state.spellcheck} spellcheck={this.state.spellcheck}
controller={this.controller} controller={this.controller}
readonly={this.state.readonly} readonly={this.state.readonly}
onFocus={this.onEditorFocus}
onBlur={this.onEditorBlur}
/> />
</div> </div>
)} )}

View File

@@ -1,4 +1,4 @@
import { FunctionComponent, useCallback, useState } from 'react' import { FocusEvent, FunctionComponent, useCallback, useState } from 'react'
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin' import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin'
import { ContentEditable } from '@lexical/react/LexicalContentEditable' import { ContentEditable } from '@lexical/react/LexicalContentEditable'
import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin' import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin'
@@ -44,8 +44,8 @@ type BlocksEditorProps = {
spellcheck?: boolean spellcheck?: boolean
ignoreFirstChange?: boolean ignoreFirstChange?: boolean
readonly?: boolean readonly?: boolean
onFocus?: () => void onFocus?: (event: FocusEvent) => void
onBlur?: () => void onBlur?: (event: FocusEvent) => void
} }
export const BlocksEditor: FunctionComponent<BlocksEditorProps> = ({ export const BlocksEditor: FunctionComponent<BlocksEditorProps> = ({

View File

@@ -8,7 +8,7 @@ import {
EditorLineHeightValues, EditorLineHeightValues,
WebAppEvent, WebAppEvent,
} from '@standardnotes/snjs' } from '@standardnotes/snjs'
import { CSSProperties, FunctionComponent, useCallback, useEffect, useRef, useState } from 'react' import { CSSProperties, FocusEvent, FunctionComponent, useCallback, useEffect, useRef, useState } from 'react'
import { BlocksEditor } from './BlocksEditor' import { BlocksEditor } from './BlocksEditor'
import { BlocksEditorComposer } from './BlocksEditorComposer' import { BlocksEditorComposer } from './BlocksEditorComposer'
import { ItemSelectionPlugin } from './Plugins/ItemSelectionPlugin/ItemSelectionPlugin' import { ItemSelectionPlugin } from './Plugins/ItemSelectionPlugin/ItemSelectionPlugin'
@@ -50,6 +50,8 @@ type Props = {
filesController: FilesController filesController: FilesController
spellcheck: boolean spellcheck: boolean
readonly?: boolean readonly?: boolean
onFocus?: (event: FocusEvent) => void
onBlur?: (event: FocusEvent) => void
} }
export const SuperEditor: FunctionComponent<Props> = ({ export const SuperEditor: FunctionComponent<Props> = ({
@@ -59,6 +61,8 @@ export const SuperEditor: FunctionComponent<Props> = ({
spellcheck, spellcheck,
controller, controller,
readonly, readonly,
onFocus,
onBlur,
}) => { }) => {
const note = useRef(controller.item) const note = useRef(controller.item)
const changeEditorFunction = useRef<ChangeEditorFunction>() const changeEditorFunction = useRef<ChangeEditorFunction>()
@@ -220,9 +224,13 @@ export const SuperEditor: FunctionComponent<Props> = ({
} }
}, []) }, [])
const onFocus = useCallback(() => { const handleFocus = useCallback(
application.notifyWebEvent(WebAppEvent.EditorDidFocus, { eventSource: EditorEventSource.UserInteraction }) (event: FocusEvent) => {
}, [application]) application.notifyWebEvent(WebAppEvent.EditorDidFocus, { eventSource: EditorEventSource.UserInteraction })
onFocus?.(event)
},
[application, onFocus],
)
return ( return (
<div <div
@@ -249,7 +257,8 @@ export const SuperEditor: FunctionComponent<Props> = ({
previewLength={SuperNotePreviewCharLimit} previewLength={SuperNotePreviewCharLimit}
spellcheck={spellcheck} spellcheck={spellcheck}
readonly={note.current.locked || readonly} readonly={note.current.locked || readonly}
onFocus={onFocus} onFocus={handleFocus}
onBlur={onBlur}
> >
<ItemSelectionPlugin currentNote={note.current} /> <ItemSelectionPlugin currentNote={note.current} />
<FilePlugin currentNote={note.current} /> <FilePlugin currentNote={note.current} />