mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix couldn't change displayName more than once on anon mode
This commit is contained in:
@@ -160,12 +160,11 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
|
||||
setSubmitStore({
|
||||
signer: newSigner,
|
||||
author: {
|
||||
displayName,
|
||||
address: newSigner.address,
|
||||
},
|
||||
});
|
||||
}
|
||||
}, [anonMode, getNewSigner, setSubmitStore, displayName]);
|
||||
}, [anonMode, getNewSigner, setSubmitStore]);
|
||||
|
||||
const onPublishPost = async () => {
|
||||
if (!title && !content && !link) {
|
||||
@@ -212,7 +211,6 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
|
||||
setPublishReplyOptions({
|
||||
signer: existingSigner,
|
||||
author: {
|
||||
displayName,
|
||||
address: existingSigner.address,
|
||||
},
|
||||
});
|
||||
@@ -221,13 +219,12 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
|
||||
setPublishReplyOptions({
|
||||
signer: newSigner,
|
||||
author: {
|
||||
displayName,
|
||||
address: newSigner.address,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, displayName, anonMode]);
|
||||
}, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, anonMode]);
|
||||
|
||||
const onPublishReply = () => {
|
||||
const currentContent = textRef.current?.value || '';
|
||||
@@ -246,6 +243,14 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
|
||||
publishReply();
|
||||
};
|
||||
|
||||
const hasSetInitialDisplayName = useRef(false);
|
||||
useEffect(() => {
|
||||
if (!hasSetInitialDisplayName.current && displayName) {
|
||||
setPublishReplyOptions({ displayName });
|
||||
hasSetInitialDisplayName.current = true;
|
||||
}
|
||||
}, [displayName, setPublishReplyOptions]);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof replyIndex === 'number') {
|
||||
resetPublishReplyOptions();
|
||||
@@ -276,7 +281,11 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
|
||||
defaultValue={displayName || undefined}
|
||||
onChange={(e) => {
|
||||
setAccount({ ...account, author: { ...account?.author, displayName: e.target.value } });
|
||||
setSubmitStore({ displayName: e.target.value });
|
||||
if (isInPostView) {
|
||||
setPublishReplyOptions({ displayName: e.target.value });
|
||||
} else {
|
||||
setSubmitStore({ displayName: e.target.value });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{isInPostView && <button onClick={onPublishReply}>{t('post')}</button>}
|
||||
|
||||
Reference in New Issue
Block a user