add path to new inbox file in pinia store

Not ideal to have data in multiple store (pinia and PouchDB) but it work this way. May need a refactoring.
This commit is contained in:
Julien Calixte
2023-11-26 10:35:38 +01:00
parent 086f7664df
commit c7ea52c7f8
6 changed files with 33 additions and 6 deletions

View File

@@ -1,19 +1,30 @@
import { data } from '@/data/data'
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) => {
const store = useUserRepoStore()
const noteId = data.generateId(DataType.Note, sha)
const getCachedNote = async () => data.get<DataType.Note, Note>(noteId)
const saveCacheNote = async (content: string, editedSha?: string) => {
const saveCacheNote = async (
content: string,
params?: { editedSha?: string; path?: string }
) => {
const newNote: Note = {
_id: noteId,
$type: DataType.Note,
content,
editedSha
editedSha: params?.editedSha
}
store.addFile({
path: params?.path,
sha: params?.editedSha
})
await data.update(newNote)
}

View File

@@ -86,6 +86,9 @@ export const useUserRepoStore = defineStore({
}, 350)
})
},
addFile(file: RepoFile) {
this.files = [...this.files.filter((f) => f.sha !== file.sha), file]
},
resetUserRepo() {
this.user = ''
this.repo = ''