From c7031568a8c1b91fc83ecd55e9303e1510023930 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Thu, 6 Feb 2025 09:57:27 -0800 Subject: [PATCH] Mobile: Fix homescreen new-note shortcuts are re-applied after switching notes (#11779) --- .../components/screens/Note/Note.test.tsx | 3 ++- .../app-mobile/components/screens/Note/Note.tsx | 17 ++++++++++++----- packages/app-mobile/root.tsx | 4 ---- packages/app-mobile/utils/appDefaultState.ts | 1 - packages/app-mobile/utils/types.ts | 3 --- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/app-mobile/components/screens/Note/Note.test.tsx b/packages/app-mobile/components/screens/Note/Note.test.tsx index 3a1e209453f..ff2338b11f3 100644 --- a/packages/app-mobile/components/screens/Note/Note.test.tsx +++ b/packages/app-mobile/components/screens/Note/Note.test.tsx @@ -36,9 +36,10 @@ interface WrapperProps { let store: Store; +const mockNavigation = { state: { } }; const WrappedNoteScreen: React.FC = _props => { return - + ; }; diff --git a/packages/app-mobile/components/screens/Note/Note.tsx b/packages/app-mobile/components/screens/Note/Note.tsx index 6a7536256c1..937d2aa05ea 100644 --- a/packages/app-mobile/components/screens/Note/Note.tsx +++ b/packages/app-mobile/components/screens/Note/Note.tsx @@ -73,8 +73,16 @@ interface InsertTextOptions { newLine?: boolean; } +interface NoteNavigation { + // Arguments passed to the NAV_GO action + state: { + newNoteAttachFileAction?: AttachFileAction; + }; +} + interface Props extends BaseProps { provisionalNoteIds: string[]; + navigation: NoteNavigation; dispatch: Dispatch; noteId: string; useEditorBeta: boolean; @@ -89,7 +97,6 @@ interface Props extends BaseProps { highlightedWords: string[]; noteHash: string; toolbarEnabled: boolean; - newNoteAttachFileAction: AttachFileAction; } interface ComponentProps extends Props { @@ -531,13 +538,14 @@ class NoteScreenComponent extends BaseScreenComponent imp // been granted, the popup will open anyway. void this.requestGeoLocationPermissions(); - if (this.props.newNoteAttachFileAction) { + const action = this.props.navigation.state?.newNoteAttachFileAction; + if (action) { setTimeout(async () => { - if (this.props.newNoteAttachFileAction === AttachFileAction.AttachDrawing) { + if (action === AttachFileAction.AttachDrawing) { await this.drawPicture_onPress(); } else { const options: AttachFileOptions = { - action: this.props.newNoteAttachFileAction, + action: action, }; await CommandService.instance().execute('attachFile', '', options); } @@ -1632,7 +1640,6 @@ const NoteScreen = connect((state: AppState) => { return { noteId: state.selectedNoteIds.length ? state.selectedNoteIds[0] : null, noteHash: state.selectedNoteHash, - newNoteAttachFileAction: state.newNoteAttachFileAction, itemType: state.selectedItemType, folders: state.folders, searchQuery: state.searchQuery, diff --git a/packages/app-mobile/root.tsx b/packages/app-mobile/root.tsx index 68b54a3590f..e4e6593a76d 100644 --- a/packages/app-mobile/root.tsx +++ b/packages/app-mobile/root.tsx @@ -354,10 +354,6 @@ const appReducer = (state = appDefaultState, action: any) => { newState.selectedNoteHash = action.noteHash; } - if ('newNoteAttachFileAction' in action) { - newState.newNoteAttachFileAction = action.newNoteAttachFileAction; - } - if ('sharedData' in action) { newState.sharedData = action.sharedData; } else { diff --git a/packages/app-mobile/utils/appDefaultState.ts b/packages/app-mobile/utils/appDefaultState.ts index 880cb9525c7..9598bc75745 100644 --- a/packages/app-mobile/utils/appDefaultState.ts +++ b/packages/app-mobile/utils/appDefaultState.ts @@ -16,7 +16,6 @@ const appDefaultState: AppState = { isOnMobileData: false, disableSideMenuGestures: false, showPanelsDialog: false, - newNoteAttachFileAction: null, ...defaultState, // On mobile, it's possible to select notes that aren't in the selected folder/tag/etc. diff --git a/packages/app-mobile/utils/types.ts b/packages/app-mobile/utils/types.ts index 969f8b7e2df..f844f1eddf6 100644 --- a/packages/app-mobile/utils/types.ts +++ b/packages/app-mobile/utils/types.ts @@ -1,5 +1,4 @@ import { State } from '@joplin/lib/reducer'; -import { AttachFileAction } from '../components/screens/Note/commands/attachFile'; export interface AppState extends State { showPanelsDialog: boolean; @@ -11,6 +10,4 @@ export interface AppState extends State { // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied noteSideMenuOptions: any; disableSideMenuGestures: boolean; - - newNoteAttachFileAction: AttachFileAction | null; }