Skip to content

Commit

Permalink
Mobile: Fix homescreen new-note shortcuts are re-applied after switch…
Browse files Browse the repository at this point in the history
…ing notes (#11779)
  • Loading branch information
personalizedrefrigerator authored Feb 6, 2025
1 parent c2c7221 commit c703156
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
3 changes: 2 additions & 1 deletion packages/app-mobile/components/screens/Note/Note.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ interface WrapperProps {

let store: Store<AppState>;

const mockNavigation = { state: { } };
const WrappedNoteScreen: React.FC<WrapperProps> = _props => {
return <TestProviderStack store={store}>
<NoteScreen />
<NoteScreen navigation={mockNavigation}/>
</TestProviderStack>;
};

Expand Down
17 changes: 12 additions & 5 deletions packages/app-mobile/components/screens/Note/Note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -89,7 +97,6 @@ interface Props extends BaseProps {
highlightedWords: string[];
noteHash: string;
toolbarEnabled: boolean;
newNoteAttachFileAction: AttachFileAction;
}

interface ComponentProps extends Props {
Expand Down Expand Up @@ -531,13 +538,14 @@ class NoteScreenComponent extends BaseScreenComponent<ComponentProps, State> 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);
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions packages/app-mobile/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion packages/app-mobile/utils/appDefaultState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions packages/app-mobile/utils/types.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}

0 comments on commit c703156

Please sign in to comment.