fix(notes): persist uploaded image to cache so it survives reload
This commit is contained in:
@@ -85,12 +85,12 @@ export const useImageUpload = ({
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!store.files.some((f) => f.path === targetPath)) {
|
store.registerUploadedFile({
|
||||||
store.files = [
|
path: targetPath,
|
||||||
...store.files,
|
sha,
|
||||||
{ path: targetPath, sha, type: "blob", size: file.size }
|
type: "blob",
|
||||||
]
|
size: file.size
|
||||||
}
|
})
|
||||||
|
|
||||||
return { filename }
|
return { filename }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -230,6 +230,28 @@ export const useUserRepoStore = defineStore("USER_REPO_STATE", {
|
|||||||
})
|
})
|
||||||
this.files = newFiles
|
this.files = newFiles
|
||||||
},
|
},
|
||||||
|
registerUploadedFile(file: RepoFile) {
|
||||||
|
if (!file.path) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const savedRepoId = generateId(
|
||||||
|
DataType.SavedRepo,
|
||||||
|
`${this.user}-${this.repo}`
|
||||||
|
)
|
||||||
|
const newFiles = [
|
||||||
|
...toRaw(this.files).filter((f) => f.path !== file.path),
|
||||||
|
toRaw(file)
|
||||||
|
]
|
||||||
|
data.update<DataType.SavedRepo, SavedRepo>({
|
||||||
|
_id: savedRepoId,
|
||||||
|
$type: DataType.SavedRepo,
|
||||||
|
repo: this.repo,
|
||||||
|
user: this.user,
|
||||||
|
files: newFiles
|
||||||
|
})
|
||||||
|
this.files = newFiles
|
||||||
|
},
|
||||||
resetUserRepo() {
|
resetUserRepo() {
|
||||||
this.user = ""
|
this.user = ""
|
||||||
this.repo = ""
|
this.repo = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user