mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(reply modal): changing anon mode before publishing reply didn't work
This commit is contained in:
@@ -47,34 +47,29 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s
|
|||||||
const comment = useComment({ commentCid: postCid });
|
const comment = useComment({ commentCid: postCid });
|
||||||
const address = comment?.author?.address;
|
const address = comment?.author?.address;
|
||||||
|
|
||||||
const hasCalledAnonAddressRef = useRef(false);
|
|
||||||
|
|
||||||
const getAnonAddressForReply = useCallback(async () => {
|
const getAnonAddressForReply = useCallback(async () => {
|
||||||
if (anonMode && !hasCalledAnonAddressRef.current) {
|
const existingSigner = await getExistingSigner(address);
|
||||||
hasCalledAnonAddressRef.current = true;
|
if (existingSigner) {
|
||||||
const existingSigner = await getExistingSigner(address);
|
setPublishReplyOptions({
|
||||||
if (existingSigner) {
|
signer: existingSigner,
|
||||||
|
author: {
|
||||||
|
address: existingSigner.address,
|
||||||
|
displayName: displayName || undefined,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const newSigner = await getNewSigner();
|
||||||
|
if (newSigner) {
|
||||||
setPublishReplyOptions({
|
setPublishReplyOptions({
|
||||||
signer: existingSigner,
|
signer: newSigner,
|
||||||
author: {
|
author: {
|
||||||
address: existingSigner.address,
|
address: newSigner.address,
|
||||||
displayName: displayName || undefined,
|
displayName: displayName || undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
const newSigner = await getNewSigner();
|
|
||||||
if (newSigner) {
|
|
||||||
setPublishReplyOptions({
|
|
||||||
signer: newSigner,
|
|
||||||
author: {
|
|
||||||
address: newSigner.address,
|
|
||||||
displayName: displayName || undefined,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, anonMode, displayName]);
|
}, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, displayName]);
|
||||||
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
@@ -98,9 +93,25 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (anonMode) {
|
if (anonMode) {
|
||||||
|
setPublishReplyOptions({
|
||||||
|
signer: undefined,
|
||||||
|
author: {
|
||||||
|
address: undefined,
|
||||||
|
displayName: displayName || undefined,
|
||||||
|
},
|
||||||
|
});
|
||||||
getAnonAddressForReply();
|
getAnonAddressForReply();
|
||||||
|
} else {
|
||||||
|
setPublishReplyOptions({
|
||||||
|
signer: undefined,
|
||||||
|
author: {
|
||||||
|
...account?.author,
|
||||||
|
displayName: displayName || account?.author?.displayName,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [anonMode, getAnonAddressForReply]);
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [anonMode]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof replyIndex === 'number') {
|
if (typeof replyIndex === 'number') {
|
||||||
|
|||||||
@@ -30,15 +30,17 @@ const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; sub
|
|||||||
spoiler,
|
spoiler,
|
||||||
};
|
};
|
||||||
|
|
||||||
const authorOptions = {
|
|
||||||
displayName: author?.displayName,
|
|
||||||
address: anonMode ? signer?.address : account?.author?.address,
|
|
||||||
};
|
|
||||||
|
|
||||||
baseOptions.author = authorOptions;
|
|
||||||
|
|
||||||
if (anonMode) {
|
if (anonMode) {
|
||||||
|
baseOptions.author = {
|
||||||
|
address: signer?.address,
|
||||||
|
displayName: author?.displayName,
|
||||||
|
};
|
||||||
baseOptions.signer = signer;
|
baseOptions.signer = signer;
|
||||||
|
} else {
|
||||||
|
baseOptions.author = {
|
||||||
|
...account?.author,
|
||||||
|
displayName: author?.displayName || account?.author?.displayName,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseOptions;
|
return baseOptions;
|
||||||
|
|||||||
Reference in New Issue
Block a user