fix displayName

This commit is contained in:
Tom (plebeius.eth)
2024-09-19 21:07:45 +02:00
parent bb976409ff
commit 81e2c0ffcb
2 changed files with 14 additions and 8 deletions
+6
View File
@@ -131,6 +131,12 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
const { link, publishCommentOptions, setSubmitStore, resetSubmitStore } = useSubmitStore(); const { link, publishCommentOptions, setSubmitStore, resetSubmitStore } = useSubmitStore();
const { index, publishComment } = usePublishComment(publishCommentOptions); const { index, publishComment } = usePublishComment(publishCommentOptions);
useEffect(() => {
if (displayName) {
setSubmitStore({ displayName });
}
}, [displayName, setSubmitStore]);
const textRef = useRef<HTMLTextAreaElement>(null); const textRef = useRef<HTMLTextAreaElement>(null);
const urlRef = useRef<HTMLInputElement>(null); const urlRef = useRef<HTMLInputElement>(null);
const subjectRef = useRef<HTMLInputElement>(null); const subjectRef = useRef<HTMLInputElement>(null);
+8 -8
View File
@@ -93,23 +93,22 @@ const useReplyStore = create<ReplyState>((set) => ({
const useReply = ({ cid, subplebbitAddress }: { cid: string; subplebbitAddress: string }) => { const useReply = ({ cid, subplebbitAddress }: { cid: string; subplebbitAddress: string }) => {
const parentCid = cid; const parentCid = cid;
const account = useAccount();
const { anonMode } = useAnonMode();
const { author, signer, content, link, spoiler, publishCommentOptions } = useReplyStore((state) => ({ const { author, signer, content, link, spoiler, publishCommentOptions } = useReplyStore((state) => ({
author: state.author[parentCid], author: state.author[parentCid] || (account?.author ? { ...account.author, displayName: account.author.displayName || undefined } : undefined),
displayName: state.displayName[parentCid], displayName: state.displayName[parentCid] || account?.author?.displayName,
signer: state.signer[parentCid], signer: state.signer[parentCid],
content: state.content[parentCid], content: state.content[parentCid] || '',
link: state.link[parentCid], link: state.link[parentCid],
spoiler: state.spoiler[parentCid], spoiler: state.spoiler[parentCid] || false,
publishCommentOptions: state.publishCommentOptions[parentCid], publishCommentOptions: state.publishCommentOptions[parentCid],
})); }));
const { anonMode } = useAnonMode();
const setReplyStore = useReplyStore((state) => state.setReplyStore); const setReplyStore = useReplyStore((state) => state.setReplyStore);
const resetReplyStore = useReplyStore((state) => state.resetReplyStore); const resetReplyStore = useReplyStore((state) => state.resetReplyStore);
const account = useAccount();
const setPublishReplyOptions = useCallback( const setPublishReplyOptions = useCallback(
(options: Partial<SetReplyStoreData>) => { (options: Partial<SetReplyStoreData>) => {
const newOptions: Partial<SetReplyStoreData> = { const newOptions: Partial<SetReplyStoreData> = {
@@ -118,6 +117,7 @@ const useReply = ({ cid, subplebbitAddress }: { cid: string; subplebbitAddress:
content: options.content ?? content, content: options.content ?? content,
link: options.link ?? link, link: options.link ?? link,
spoiler: options.spoiler ?? spoiler, spoiler: options.spoiler ?? spoiler,
displayName: options.displayName ?? author?.displayName ?? account?.author?.displayName,
}; };
if ('displayName' in options) { if ('displayName' in options) {