diff --git a/src/hooks/useFile.hook.ts b/src/hooks/useFile.hook.ts index 14b281a..c1ef97a 100644 --- a/src/hooks/useFile.hook.ts +++ b/src/hooks/useFile.hook.ts @@ -18,7 +18,10 @@ export const useFile = (sha: Ref | string, retrieveContent = true) => { renderFromUTF8, getRawContent: getRawContentFromFile } = useMarkdown(toValue(sha)) - const { getCachedNote, saveCacheNote } = prepareNoteCache(toValue(sha)) + const { getCachedNote, saveCacheNote } = prepareNoteCache( + toValue(sha), + toValue(path) + ) const fromCache = ref(false) const rawContent = ref('') diff --git a/src/modules/note/cache/prepareNoteCache.ts b/src/modules/note/cache/prepareNoteCache.ts index c5d4524..33b4442 100644 --- a/src/modules/note/cache/prepareNoteCache.ts +++ b/src/modules/note/cache/prepareNoteCache.ts @@ -3,11 +3,24 @@ import { DataType } from '@/data/DataType.enum' import { Note } from '@/modules/note/models/Note' import { useUserRepoStore } from '@/modules/repo/store/userRepo.store' -export const prepareNoteCache = (sha: string) => { +export const prepareNoteCache = (sha: string, path?: string) => { const store = useUserRepoStore() const noteId = data.generateId(DataType.Note, sha) - const getCachedNote = async () => data.get(noteId) + const notePath = path ? data.generateId(DataType.Note, path) : null + const getCachedNote = async () => { + const note = await data.get(noteId) + + if (note) { + return note + } + + if (notePath) { + return data.get(notePath) + } + + return null + } const saveCacheNote = async ( content: string, @@ -26,6 +39,13 @@ export const prepareNoteCache = (sha: string) => { }) await data.update(newNote) + + if (notePath) { + await data.update({ + ...newNote, + _id: notePath + }) + } } return { diff --git a/src/views/FleetingNotes.vue b/src/views/FleetingNotes.vue index 6409e17..d63d5c5 100644 --- a/src/views/FleetingNotes.vue +++ b/src/views/FleetingNotes.vue @@ -49,7 +49,7 @@ watch(mode, async (newMode) => { } newContent.value = initialContent - const { saveCacheNote } = prepareNoteCache(newSha) + const { saveCacheNote } = prepareNoteCache(newSha, newContentPath) await saveCacheNote(encodeUTF8ToBase64(content), { editedSha: newSha, path: newContentPath