mirror of https://github.com/laurent22/joplin.git
Desktop: Fixes #10230: Fix new note and to-do buttons greyed when initial selection is "all notes" or a tag (#10434)
parent
34092d8491
commit
4e3326b12f
|
@ -18,7 +18,6 @@ const { BackButtonService } = require('../../services/back-button.js');
|
||||||
import { AppState } from '../../utils/types';
|
import { AppState } from '../../utils/types';
|
||||||
import { NoteEntity } from '@joplin/lib/services/database/types';
|
import { NoteEntity } from '@joplin/lib/services/database/types';
|
||||||
import { itemIsInTrash } from '@joplin/lib/services/trash';
|
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
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||||
class NotesScreenComponent extends BaseScreenComponent<any> {
|
class NotesScreenComponent extends BaseScreenComponent<any> {
|
||||||
|
@ -230,34 +229,19 @@ class NotesScreenComponent extends BaseScreenComponent<any> {
|
||||||
let buttonFolderId = this.props.selectedFolderId !== Folder.conflictFolderId() ? this.props.selectedFolderId : null;
|
let buttonFolderId = this.props.selectedFolderId !== Folder.conflictFolderId() ? this.props.selectedFolderId : null;
|
||||||
if (!buttonFolderId) buttonFolderId = this.props.activeFolderId;
|
if (!buttonFolderId) buttonFolderId = this.props.activeFolderId;
|
||||||
|
|
||||||
const isAllNotes =
|
const addFolderNoteButtons = !!buttonFolderId;
|
||||||
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 thisComp = this;
|
||||||
|
|
||||||
const makeActionButtonComp = () => {
|
const makeActionButtonComp = () => {
|
||||||
if ((this.props.notesParentType === 'Folder' && itemIsInTrash(parent)) || !Folder.atLeastOneRealFolderExists(this.props.folders)) return null;
|
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) {
|
if (addFolderNoteButtons && this.props.folders.length > 0) {
|
||||||
const buttons = [];
|
const buttons = [];
|
||||||
buttons.push({
|
buttons.push({
|
||||||
label: _('New to-do'),
|
label: _('New to-do'),
|
||||||
onPress: async () => {
|
onPress: async () => {
|
||||||
const folderId = await getTargetFolderId();
|
|
||||||
const isTodo = true;
|
const isTodo = true;
|
||||||
void this.newNoteNavigate(folderId, isTodo);
|
void this.newNoteNavigate(buttonFolderId, isTodo);
|
||||||
},
|
},
|
||||||
color: '#9b59b6',
|
color: '#9b59b6',
|
||||||
icon: 'checkbox-outline',
|
icon: 'checkbox-outline',
|
||||||
|
@ -266,9 +250,8 @@ class NotesScreenComponent extends BaseScreenComponent<any> {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
label: _('New note'),
|
label: _('New note'),
|
||||||
onPress: async () => {
|
onPress: async () => {
|
||||||
const folderId = await getTargetFolderId();
|
|
||||||
const isTodo = false;
|
const isTodo = false;
|
||||||
void this.newNoteNavigate(folderId, isTodo);
|
void this.newNoteNavigate(buttonFolderId, isTodo);
|
||||||
},
|
},
|
||||||
color: '#9b59b6',
|
color: '#9b59b6',
|
||||||
icon: 'document',
|
icon: 'document',
|
||||||
|
|
|
@ -215,7 +215,10 @@ const generalMiddleware = (store: any) => (next: any) => async (action: any) =>
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.type === 'NAV_GO' && action.routeName === 'Notes') {
|
if (action.type === 'NAV_GO' && action.routeName === 'Notes') {
|
||||||
|
if ('selectedFolderId' in newState) {
|
||||||
Setting.setValue('activeFolderId', newState.selectedFolderId);
|
Setting.setValue('activeFolderId', newState.selectedFolderId);
|
||||||
|
}
|
||||||
|
|
||||||
const notesParent: NotesParent = {
|
const notesParent: NotesParent = {
|
||||||
type: action.smartFilterId ? 'SmartFilter' : 'Folder',
|
type: action.smartFilterId ? 'SmartFilter' : 'Folder',
|
||||||
selectedItemId: action.smartFilterId ? action.smartFilterId : newState.selectedFolderId,
|
selectedItemId: action.smartFilterId ? action.smartFilterId : newState.selectedFolderId,
|
||||||
|
@ -469,6 +472,21 @@ const initializeTempDir = async () => {
|
||||||
return tempDir;
|
return tempDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getInitialActiveFolder = async () => {
|
||||||
|
let folderId = Setting.value('activeFolderId');
|
||||||
|
|
||||||
|
// In some cases (e.g. new profile/install), activeFolderId hasn't been set yet.
|
||||||
|
// Because activeFolderId is used to determine the parent for new notes, initialize
|
||||||
|
// it here:
|
||||||
|
if (!folderId) {
|
||||||
|
folderId = (await Folder.defaultFolder())?.id;
|
||||||
|
if (folderId) {
|
||||||
|
Setting.setValue('activeFolderId', folderId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return await Folder.load(folderId);
|
||||||
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
|
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
|
||||||
async function initialize(dispatch: Function) {
|
async function initialize(dispatch: Function) {
|
||||||
shimInit();
|
shimInit();
|
||||||
|
@ -686,10 +704,7 @@ async function initialize(dispatch: Function) {
|
||||||
// items: masterKeys,
|
// items: masterKeys,
|
||||||
// });
|
// });
|
||||||
|
|
||||||
const folderId = Setting.value('activeFolderId');
|
const folder = await getInitialActiveFolder();
|
||||||
let folder = await Folder.load(folderId);
|
|
||||||
|
|
||||||
if (!folder) folder = await Folder.defaultFolder();
|
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'FOLDER_SET_COLLAPSED_ALL',
|
type: 'FOLDER_SET_COLLAPSED_ALL',
|
||||||
|
|
|
@ -1335,6 +1335,12 @@ const reducer = produce((draft: Draft<State> = defaultState, action: any) => {
|
||||||
handleHistory(draft, action);
|
handleHistory(draft, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action.type === 'SETTING_UPDATE_ALL' || (action.type === 'SETTING_UPDATE_ONE' && action.key === 'activeFolderId')) {
|
||||||
|
// To allow creating notes when opening the app with all notes and/or tags,
|
||||||
|
// a "last selected folder ID" needs to be set.
|
||||||
|
draft.selectedFolderId ??= draft.settings.activeFolderId;
|
||||||
|
}
|
||||||
|
|
||||||
for (const additionalReducer of additionalReducers) {
|
for (const additionalReducer of additionalReducers) {
|
||||||
additionalReducer.reducer(draft, action);
|
additionalReducer.reducer(draft, action);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue