-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Desktop: Fixes #10230: Fix new note and to-do buttons greyed when initial selection is "all notes" or a tag #10434
Desktop: Fixes #10230: Fix new note and to-do buttons greyed when initial selection is "all notes" or a tag #10434
Conversation
… when initial selection is all notes/a tag
packages/lib/reducer.ts
Outdated
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be simpler to use existing events:
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': | |
case 'TAG_SELECT': | |
// 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; |
This would, however, require moving the logic to a separate switch
statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, the reducer actions are essentially setters - you provides some value and this is used to update the state. While in this case it's more like an event that has some side effect and I think we should avoid this pattern if possible (although it's present for a few actions).
If the goal here is to set the selected folder, isn't it possible to call FOLDER_SELECT
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FOLDER_SELECT
also sets notesParentType
to 'Folder'
and clears selectedNoteIds
. However, this could be fine if FOLDER_SELECT
is called before the initial selection is set.
An alternative could be to handle this in SETTING_UPDATE_ONE
or SETTING_UPDATE_ALL
, which would remove the need for dispatch({ type: 'SOME_TYPE_TO_SET_THE_INITIAL_SELECTION_HERE' })
in the initialization logic for mobile and desktop.
Summary
This pull request fixes #10230 by setting
selectedFolderId
in the application state on startup, even if the selected note parent is not a folder.Notes
At present,
selectedFolderId
determines whether the new note buttons are enabled and the parent of new notes and to-dos.Currently, if a user navigates from a folder to a smart filter (e.g. "All Notes") or a tag,
selectedFolderId
maintains its previous value. This causes the "New Note" and "New To-Do" buttons to stay enabled, despite a folder not being selected in the sidebar.However, when the app starts (before this pull request),
selectedFolderId
would benull
, unless a folder is initially selected. This caused "New Note" and "New To-Do" to be disabled on desktop and extra logic to determine whether the "new note"FAB.Group
should be enabled on mobile.On startup, making
selectedFolderId
default to the last selected folder ID, rather thannull
, thus both fixes #10230 and is consistent with the last application state, before the app was closed.Testing plan
This has been tested successfully on desktop/Ubuntu 24.04 and on mobile/iOS 17.4.
Note
There are a few things I don't like about this approach:
NAV_GO
route needed to be changed. Otherwise, the default route (all notes) would clearactiveFolderId
. Changing this makes mobile more consistent with desktop, but I think it makes navigation logic more confusing.selectedFolderId
benull
when no folder is selected. A new state variable orsettings.activeFolderId
could then be used to determine the parent folder for new notes.whenClause.oneFolderSelected
is currently determined byselectedFolderId
. If plugin commands haveenabledCondition
s similar to the enabled condition fornewNote
, this could break plugins.