mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-09-29 00:10:50 +00:00
Save user refs for drafts as well
This commit is contained in:
parent
a9c1be7f51
commit
0e24016052
@ -2,7 +2,7 @@ import { useIntl } from "@cookbook/solid-intl";
|
||||
import { Router, useLocation } from "@solidjs/router";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import { Component, createEffect, createSignal, For, onCleanup, onMount, Show } from "solid-js";
|
||||
import { createStore, unwrap } from "solid-js/store";
|
||||
import { createStore, reconcile, unwrap } from "solid-js/store";
|
||||
import { noteRegex, profileRegex, Kind, editMentionRegex, emojiSearchLimit, profileRegexG } from "../../../constants";
|
||||
import { useAccountContext } from "../../../contexts/AccountContext";
|
||||
import { useSearchContext } from "../../../contexts/SearchContext";
|
||||
@ -40,7 +40,7 @@ import { useProfileContext } from "../../../contexts/ProfileContext";
|
||||
import ButtonGhost from "../../Buttons/ButtonGhost";
|
||||
import EmojiPickPopover from "../../EmojiPickModal/EmojiPickPopover";
|
||||
import ConfirmAlternativeModal from "../../ConfirmModal/ConfirmAlternativeModal";
|
||||
import { readNoteDraft, saveNoteDraft } from "../../../lib/localStore";
|
||||
import { readNoteDraft, readNoteDraftUserRefs, saveNoteDraft, saveNoteDraftUserRefs } from "../../../lib/localStore";
|
||||
import Uploader from "../../Uploader/Uploader";
|
||||
import { logError } from "../../../lib/logger";
|
||||
|
||||
@ -499,6 +499,9 @@ const EditBox: Component<{
|
||||
createEffect(() => {
|
||||
if (props.open) {
|
||||
const draft = readNoteDraft(account?.publicKey, props.replyToNote?.post.noteId);
|
||||
const draftUserRefs = readNoteDraftUserRefs(account?.publicKey, props.replyToNote?.post.noteId);
|
||||
|
||||
setUserRefs(reconcile(draftUserRefs));
|
||||
|
||||
setMessage((msg) => {
|
||||
if (msg.length > 0) return msg;
|
||||
@ -527,6 +530,7 @@ const EditBox: Component<{
|
||||
|
||||
// save draft just in case there is an unintended interuption
|
||||
saveNoteDraft(account?.publicKey, message(), props.replyToNote?.post.noteId);
|
||||
saveNoteDraftUserRefs(account?.publicKey, userRefs, props.replyToNote?.post.noteId);
|
||||
});
|
||||
|
||||
const onEscape = (e: KeyboardEvent) => {
|
||||
@ -575,6 +579,7 @@ const EditBox: Component<{
|
||||
}
|
||||
|
||||
saveNoteDraft(account?.publicKey, '', props.replyToNote?.post.noteId);
|
||||
saveNoteDraftUserRefs(account?.publicKey, {}, props.replyToNote?.post.noteId);
|
||||
clearEditor();
|
||||
};
|
||||
|
||||
@ -587,6 +592,7 @@ const EditBox: Component<{
|
||||
|
||||
const persistNote = (note: string) => {
|
||||
saveNoteDraft(account?.publicKey, note, props.replyToNote?.post.noteId);
|
||||
saveNoteDraftUserRefs(account?.publicKey, userRefs, props.replyToNote?.post.noteId);
|
||||
clearEditor();
|
||||
};
|
||||
|
||||
|
@ -23,6 +23,7 @@ export type LocalStore = {
|
||||
},
|
||||
emojiHistory: EmojiOption[],
|
||||
noteDraft: Record<string, string>,
|
||||
noteDraftUserRefs: Record<string, Record<string, PrimalUser>>,
|
||||
uploadTime: Record<string, number>,
|
||||
};
|
||||
|
||||
@ -58,6 +59,7 @@ export const emptyStorage = {
|
||||
recomended: { profiles: [], stats: {} },
|
||||
emojiHistory: [],
|
||||
noteDraft: {},
|
||||
noteDraftUserRefs: {},
|
||||
uploadTime: defaultUploadTime,
|
||||
}
|
||||
|
||||
@ -261,6 +263,40 @@ export const readNoteDraft = (pubkey: string | undefined, replyTo?: string) => {
|
||||
return store.noteDraft[key] || '';
|
||||
}
|
||||
|
||||
export const saveNoteDraftUserRefs = (pubkey: string | undefined, refs: Record<string, PrimalUser>, replyTo?: string) => {
|
||||
if (!pubkey) {
|
||||
return;
|
||||
}
|
||||
|
||||
const store = getStorage(pubkey);
|
||||
|
||||
const key = replyTo || 'root';
|
||||
|
||||
if (!store.noteDraftUserRefs || typeof store.noteDraftUserRefs === 'string') {
|
||||
store.noteDraftUserRefs = {};
|
||||
}
|
||||
|
||||
store.noteDraftUserRefs[key] = refs;
|
||||
|
||||
setStorage(pubkey, store);
|
||||
}
|
||||
|
||||
export const readNoteDraftUserRefs = (pubkey: string | undefined, replyTo?: string) => {
|
||||
if (!pubkey) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const store = getStorage(pubkey);
|
||||
|
||||
if (!store.noteDraftUserRefs || typeof store.noteDraftUserRefs === 'string') {
|
||||
store.noteDraftUserRefs = {};
|
||||
}
|
||||
|
||||
const key = replyTo || 'root';
|
||||
|
||||
return store.noteDraftUserRefs[key] || {};
|
||||
}
|
||||
|
||||
export const saveUploadTime = (pubkey: string | undefined, uploadTime: Record<string, number>) => {
|
||||
if (!pubkey) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user