Skip to content

Commit e17876c

Browse files
committed
Fix refresh bug
When user restores note after previously restored note in same folder the ordered IDs were not updated immediately, now the notes are correctly restored even before app refresh
1 parent cf25630 commit e17876c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/lib/db/FSNoteDb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ class FSNoteDb implements NoteDb {
544544
newFolderMap[folderPathname] = {
545545
...folder,
546546
orderedIds: orderedIds,
547+
updatedAt: getNow(),
547548
}
548549

549550
this.data!.folderMap = newFolderMap

src/lib/db/createStore.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ export function createDbStoreCreator(
859859
}
860860
const noteDoc = await storage.db.untrashNote(noteId)
861861

862-
const folder: PopulatedFolderDoc =
862+
const noteFolder: PopulatedFolderDoc =
863863
storage.folderMap[noteDoc.folderPathname] == null
864864
? ({
865865
...(await storage.db.upsertFolder(noteDoc.folderPathname)),
@@ -878,11 +878,12 @@ export function createDbStoreCreator(
878878
noteDoc.folderPathname
879879
)
880880

881-
const isRootFolder = folder.pathname == '/'
882-
const foldersToUpdate: PopulatedFolderDoc[] = [folder]
883-
const foldersToUpdateParentOrderedIds: PopulatedFolderDoc[] = isRootFolder
884-
? []
885-
: [folder]
881+
const isFolderMissing =
882+
storage.folderMap[noteDoc.folderPathname] == null
883+
const foldersToUpdate: PopulatedFolderDoc[] = []
884+
const foldersToUpdateParentOrderedIds: PopulatedFolderDoc[] = isFolderMissing
885+
? [noteFolder]
886+
: []
886887
for (const parentFolderPathname of parentFolderPathnames) {
887888
if (storage.folderMap[parentFolderPathname] == null) {
888889
const missingFolder = await storage.db.upsertFolder(
@@ -892,7 +893,7 @@ export function createDbStoreCreator(
892893
const missingFolderPopulatedDoc = {
893894
...missingFolder,
894895
pathname: parentFolderPathname,
895-
noteIdSet: new Set(),
896+
orderedIds: [],
896897
} as PopulatedFolderDoc
897898
foldersToUpdate.push(missingFolderPopulatedDoc)
898899
foldersToUpdateParentOrderedIds.push(missingFolderPopulatedDoc)
@@ -946,10 +947,16 @@ export function createDbStoreCreator(
946947
return acc
947948
}, {})
948949

950+
// update note doc folder ordered IDs
951+
await storage.db.updateFolderOrderedIds(
952+
noteFolder._id,
953+
noteFolder.orderedIds || []
954+
)
955+
949956
setStorageMap(
950957
produce((draft: ObjectMap<NoteStorage>) => {
951958
draft[storageId]!.noteMap[noteDoc._id] = noteDoc
952-
draft[storageId]!.folderMap[noteDoc.folderPathname] = folder
959+
draft[storageId]!.folderMap[noteDoc.folderPathname] = noteFolder
953960
foldersToUpdate.forEach((folderToUpdate) => {
954961
draft[storageId]!.folderMap[
955962
folderToUpdate.pathname

0 commit comments

Comments
 (0)