mirror of
https://github.com/versia-pub/frontend.git
synced 2025-12-06 08:28:20 +01:00
feat: ✨ Persist composer state in localStorage
Some checks failed
Some checks failed
This commit is contained in:
parent
b510782a30
commit
e055e2bc8f
|
|
@ -69,7 +69,7 @@ const send = async () => {
|
||||||
watch(
|
watch(
|
||||||
props,
|
props,
|
||||||
async (props) => {
|
async (props) => {
|
||||||
if (props.relation) {
|
if (props.relation && !store.relation) {
|
||||||
store.stateFromRelation(
|
store.stateFromRelation(
|
||||||
props.relation.type,
|
props.relation.type,
|
||||||
props.relation.note,
|
props.relation.note,
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,6 @@ export const useComposerStore = (key: ComposerStateKey) =>
|
||||||
if (relationType === "edit") {
|
if (relationType === "edit") {
|
||||||
this.content = source?.text || note.content;
|
this.content = source?.text || note.content;
|
||||||
this.rawContent = source?.text || "";
|
this.rawContent = source?.text || "";
|
||||||
console.log(note.media_attachments);
|
|
||||||
this.files = await Promise.all(
|
this.files = await Promise.all(
|
||||||
note.media_attachments.map(async (file) => ({
|
note.media_attachments.map(async (file) => ({
|
||||||
id: crypto.randomUUID(),
|
id: crypto.randomUUID(),
|
||||||
|
|
@ -257,4 +256,38 @@ export const useComposerStore = (key: ComposerStateKey) =>
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
persist: {
|
||||||
|
serializer: {
|
||||||
|
serialize(data) {
|
||||||
|
// Delete file references before storing to avoid large storage usage
|
||||||
|
const newFiles = (data as ComposerState).files.map((f) => {
|
||||||
|
const { file, ...rest } = f;
|
||||||
|
|
||||||
|
return rest;
|
||||||
|
});
|
||||||
|
|
||||||
|
return JSON.stringify({ ...data, files: newFiles });
|
||||||
|
},
|
||||||
|
deserialize(str) {
|
||||||
|
return JSON.parse(str);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
storage: {
|
||||||
|
// Store everything in "composer" key to avoid creating too many entries
|
||||||
|
getItem(key) {
|
||||||
|
return JSON.stringify(
|
||||||
|
JSON.parse(localStorage.getItem("composer") || "{}")[
|
||||||
|
key
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
setItem(key, value) {
|
||||||
|
const composer = JSON.parse(
|
||||||
|
localStorage.getItem("composer") || "{}",
|
||||||
|
);
|
||||||
|
composer[key] = JSON.parse(value);
|
||||||
|
localStorage.setItem("composer", JSON.stringify(composer));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue