Skip to content

Commit

Permalink
Mobile: Fix new note button on new profile
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed May 16, 2024
1 parent f00c02d commit a7efc80
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions packages/app-mobile/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ const generalMiddleware = (store: any) => (next: any) => async (action: any) =>
}

if (action.type === 'NAV_GO' && action.routeName === 'Notes') {
if (newState.selectedFolderId) {
if ('selectedFolderId' in newState) {
Setting.setValue('activeFolderId', newState.selectedFolderId);
}

const notesParent: NotesParent = {
type: action.smartFilterId ? 'SmartFilter' : 'Folder',
selectedItemId: action.smartFilterId ? action.smartFilterId : newState.selectedFolderId,
Expand Down Expand Up @@ -471,6 +472,21 @@ const initializeTempDir = async () => {
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
async function initialize(dispatch: Function) {
shimInit();
Expand Down Expand Up @@ -688,10 +704,7 @@ async function initialize(dispatch: Function) {
// items: masterKeys,
// });

const folderId = Setting.value('activeFolderId');
let folder = await Folder.load(folderId);

if (!folder) folder = await Folder.defaultFolder();
const folder = await getInitialActiveFolder();

dispatch({
type: 'FOLDER_SET_COLLAPSED_ALL',
Expand Down

0 comments on commit a7efc80

Please sign in to comment.