Skip to content

Commit

Permalink
Mobile: Fixes #9328: Fix new note/to-do buttons not visible on app st…
Browse files Browse the repository at this point in the history
…artup in some cases (#9329)
  • Loading branch information
personalizedrefrigerator authored and laurent22 committed Nov 26, 2023
1 parent c103bbc commit d11bdf5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
27 changes: 22 additions & 5 deletions packages/app-mobile/components/screens/Notes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {

Expand Down Expand Up @@ -223,27 +224,43 @@ class NotesScreenComponent extends BaseScreenComponent<any> {
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',
});

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',
Expand Down
1 change: 1 addition & 0 deletions packages/app-mobile/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down

0 comments on commit d11bdf5

Please sign in to comment.