Skip to content

Commit

Permalink
Desktop: Fixes laurent22#10230: Fix new note and to-do buttons greyed…
Browse files Browse the repository at this point in the history
… when initial selection is all notes/a tag
  • Loading branch information
personalizedrefrigerator committed May 14, 2024
1 parent cd0ff94 commit 7c7c1b9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
4 changes: 4 additions & 0 deletions packages/app-desktop/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ class Application extends BaseApplication {
});
}

this.store().dispatch({
type: 'INITIAL_SELECTION_SET',
});

this.store().dispatch({
type: 'FOLDER_SET_COLLAPSED_ALL',
ids: Setting.value('collapsedFolderIds'),
Expand Down
23 changes: 3 additions & 20 deletions packages/app-mobile/components/screens/Notes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const { BackButtonService } = require('../../services/back-button.js');
import { AppState } from '../../utils/types';
import { NoteEntity } from '@joplin/lib/services/database/types';
import { itemIsInTrash } from '@joplin/lib/services/trash';
const { ALL_NOTES_FILTER_ID } = require('@joplin/lib/reserved-ids.js');

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
class NotesScreenComponent extends BaseScreenComponent<any> {
Expand Down Expand Up @@ -230,34 +229,19 @@ class NotesScreenComponent extends BaseScreenComponent<any> {
let buttonFolderId = this.props.selectedFolderId !== Folder.conflictFolderId() ? this.props.selectedFolderId : null;
if (!buttonFolderId) buttonFolderId = this.props.activeFolderId;

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 addFolderNoteButtons = !!buttonFolderId;
const thisComp = this;

const makeActionButtonComp = () => {
if ((this.props.notesParentType === 'Folder' && itemIsInTrash(parent)) || !Folder.atLeastOneRealFolderExists(this.props.folders)) return null;

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: async () => {
const folderId = await getTargetFolderId();
const isTodo = true;
void this.newNoteNavigate(folderId, isTodo);
void this.newNoteNavigate(buttonFolderId, isTodo);
},
color: '#9b59b6',
icon: 'checkbox-outline',
Expand All @@ -266,9 +250,8 @@ class NotesScreenComponent extends BaseScreenComponent<any> {
buttons.push({
label: _('New note'),
onPress: async () => {
const folderId = await getTargetFolderId();
const isTodo = false;
void this.newNoteNavigate(folderId, isTodo);
void this.newNoteNavigate(buttonFolderId, isTodo);
},
color: '#9b59b6',
icon: 'document',
Expand Down
4 changes: 4 additions & 0 deletions packages/app-mobile/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,10 @@ async function initialize(dispatch: Function) {
});
}

this.store().dispatch({
type: 'INITIAL_SELECTION_SET',
});

await clearSharedFilesCache();
} catch (error) {
alert(`Initialization error: ${error.message}`);
Expand Down
6 changes: 6 additions & 0 deletions packages/lib/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,12 @@ const reducer = produce((draft: Draft<State> = defaultState, action: any) => {
break;
}

case 'INITIAL_SELECTION_SET':
// To allow creating notes when opening the app with all notes and/or tags,
// we also need a "last selected folder ID".
draft.selectedFolderId ??= draft.settings.activeFolderId;
break;

case 'SMART_FILTER_SELECT':
draft.notesParentType = 'SmartFilter';
draft.selectedSmartFilterId = action.id;
Expand Down

0 comments on commit 7c7c1b9

Please sign in to comment.