From dbb354ad107cbd8c10fee718437f8adabcfdeaeb Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Sun, 19 Nov 2023 02:43:57 -0800 Subject: [PATCH] Mobile: Fixes #9328: Fix new note/to-do buttons not visible on app startup in some cases (#9329) --- .../app-mobile/components/screens/Notes.tsx | 27 +++++++++++++++---- packages/app-mobile/root.tsx | 1 + 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/app-mobile/components/screens/Notes.tsx b/packages/app-mobile/components/screens/Notes.tsx index 0844f677b2..dff462b710 100644 --- a/packages/app-mobile/components/screens/Notes.tsx +++ b/packages/app-mobile/components/screens/Notes.tsx @@ -16,6 +16,7 @@ const DialogBox = require('react-native-dialogbox').default; const { BaseScreenComponent } = require('../base-screen'); const { BackButtonService } = require('../../services/back-button.js'); import { AppState } from '../../utils/types'; +const { ALL_NOTES_FILTER_ID } = require('@joplin/lib/reserved-ids.js'); class NotesScreenComponent extends BaseScreenComponent { @@ -223,17 +224,32 @@ class NotesScreenComponent extends BaseScreenComponent { let buttonFolderId = this.props.selectedFolderId !== Folder.conflictFolderId() ? this.props.selectedFolderId : null; if (!buttonFolderId) buttonFolderId = this.props.activeFolderId; - const addFolderNoteButtons = !!buttonFolderId; + const isAllNotes = + this.props.notesParentType === 'SmartFilter' + && this.props.selectedSmartFilterId === ALL_NOTES_FILTER_ID; + + // Usually, when showing all notes, activeFolderId/selectedFolderId is set to the last + // active folder. + // If the app starts showing all notes, activeFolderId/selectedFolderId are + // empty or null. As such, we need a special case to show the buttons: + const addFolderNoteButtons = !!buttonFolderId || isAllNotes; const thisComp = this; const makeActionButtonComp = () => { + const getTargetFolderId = async () => { + if (!buttonFolderId && isAllNotes) { + return (await Folder.defaultFolder()).id; + } + return buttonFolderId; + }; if (addFolderNoteButtons && this.props.folders.length > 0) { const buttons = []; buttons.push({ label: _('New to-do'), - onPress: () => { + onPress: async () => { + const folderId = await getTargetFolderId(); const isTodo = true; - void this.newNoteNavigate(buttonFolderId, isTodo); + void this.newNoteNavigate(folderId, isTodo); }, color: '#9b59b6', icon: 'checkbox-outline', @@ -241,9 +257,10 @@ class NotesScreenComponent extends BaseScreenComponent { buttons.push({ label: _('New note'), - onPress: () => { + onPress: async () => { + const folderId = await getTargetFolderId(); const isTodo = false; - void this.newNoteNavigate(buttonFolderId, isTodo); + void this.newNoteNavigate(folderId, isTodo); }, color: '#9b59b6', icon: 'document', diff --git a/packages/app-mobile/root.tsx b/packages/app-mobile/root.tsx index 5eb8944a20..39cf3d5dfb 100644 --- a/packages/app-mobile/root.tsx +++ b/packages/app-mobile/root.tsx @@ -317,6 +317,7 @@ const appReducer = (state = appDefaultState, action: any) => { if ('smartFilterId' in action) { newState.smartFilterId = action.smartFilterId; + newState.selectedSmartFilterId = action.smartFilterId; newState.notesParentType = 'SmartFilter'; }