mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix anon mode was altering comment.author
This commit is contained in:
@@ -27,7 +27,8 @@ import useFetchGifFirstFrame from '../../hooks/use-fetch-gif-first-frame';
|
||||
import useAnonMode from '../../hooks/use-anon-mode';
|
||||
|
||||
type SubmitState = {
|
||||
author: any | undefined;
|
||||
author?: any | undefined;
|
||||
displayName?: string | undefined;
|
||||
signer?: any | undefined;
|
||||
subplebbitAddress: string | undefined;
|
||||
title: string | undefined;
|
||||
@@ -50,10 +51,11 @@ const useSubmitStore = create<SubmitState>((set) => ({
|
||||
link: undefined,
|
||||
spoiler: undefined,
|
||||
publishCommentOptions: {},
|
||||
setSubmitStore: ({ author, signer, subplebbitAddress, title, content, link, spoiler }) =>
|
||||
setSubmitStore: ({ author, displayName, signer, subplebbitAddress, title, content, link, spoiler }) =>
|
||||
set((state) => {
|
||||
const updatedAuthor = displayName ? { ...author, displayName } : author;
|
||||
const nextState = { ...state };
|
||||
if (author !== undefined) nextState.author = author;
|
||||
if (author !== undefined) nextState.author = updatedAuthor;
|
||||
if (signer !== undefined) nextState.signer = signer;
|
||||
if (subplebbitAddress !== undefined) nextState.subplebbitAddress = subplebbitAddress;
|
||||
if (title !== undefined) nextState.title = title || undefined;
|
||||
@@ -62,7 +64,6 @@ const useSubmitStore = create<SubmitState>((set) => ({
|
||||
if (spoiler !== undefined) nextState.spoiler = spoiler || undefined;
|
||||
|
||||
const publishCommentOptions: PublishCommentOptions = {
|
||||
author: nextState.author,
|
||||
subplebbitAddress: nextState.subplebbitAddress,
|
||||
title: nextState.title,
|
||||
content: nextState.content,
|
||||
@@ -80,6 +81,10 @@ const useSubmitStore = create<SubmitState>((set) => ({
|
||||
publishCommentOptions.signer = nextState.signer;
|
||||
}
|
||||
|
||||
if (nextState.author) {
|
||||
publishCommentOptions.author = nextState.author;
|
||||
}
|
||||
|
||||
nextState.publishCommentOptions = publishCommentOptions;
|
||||
return nextState;
|
||||
}),
|
||||
@@ -269,7 +274,10 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
|
||||
type='text'
|
||||
placeholder={!displayName ? _.capitalize(t('anonymous')) : undefined}
|
||||
defaultValue={displayName || undefined}
|
||||
onChange={(e) => setAccount({ ...account, author: { ...account?.author, displayName: e.target.value } })}
|
||||
onChange={(e) => {
|
||||
setAccount({ ...account, author: { ...account?.author, displayName: e.target.value } });
|
||||
setSubmitStore({ displayName: e.target.value });
|
||||
}}
|
||||
/>
|
||||
{isInPostView && <button onClick={onPublishReply}>{t('post')}</button>}
|
||||
</td>
|
||||
|
||||
@@ -42,18 +42,24 @@ const ReplyModal = ({ closeModal, parentCid, postCid, scrollY }: ReplyModalProps
|
||||
const getAnonAddressForReply = useCallback(async () => {
|
||||
if (anonMode && !hasCalledAnonAddressRef.current) {
|
||||
hasCalledAnonAddressRef.current = true;
|
||||
let signer = getExistingSigner(address);
|
||||
if (!signer) {
|
||||
signer = await getNewSigner();
|
||||
if (signer) {
|
||||
setPublishReplyOptions({
|
||||
signer,
|
||||
author: {
|
||||
displayName,
|
||||
address: signer.address,
|
||||
},
|
||||
});
|
||||
}
|
||||
const existingSigner = getExistingSigner(address);
|
||||
if (existingSigner) {
|
||||
setPublishReplyOptions({
|
||||
signer: existingSigner,
|
||||
author: {
|
||||
displayName,
|
||||
address: existingSigner.address,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const newSigner = await getNewSigner();
|
||||
setPublishReplyOptions({
|
||||
signer: newSigner,
|
||||
author: {
|
||||
displayName,
|
||||
address: newSigner.address,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [anonMode, address, getExistingSigner, getNewSigner, displayName, setPublishReplyOptions]);
|
||||
@@ -119,7 +125,9 @@ const ReplyModal = ({ closeModal, parentCid, postCid, scrollY }: ReplyModalProps
|
||||
const setTextRef = (ref: HTMLTextAreaElement | null) => {
|
||||
if (ref) {
|
||||
textRef.current = ref;
|
||||
!isMobile && ref.focus();
|
||||
// if (!isMobile && !urlRef.current?.value) {
|
||||
// ref.focus();
|
||||
// }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -166,7 +174,10 @@ const ReplyModal = ({ closeModal, parentCid, postCid, scrollY }: ReplyModalProps
|
||||
type='text'
|
||||
defaultValue={displayName}
|
||||
placeholder={displayName ? undefined : _.capitalize(t('name'))}
|
||||
onChange={(e) => setAccount({ ...account, author: { ...account?.author, displayName: e.target.value } })}
|
||||
onChange={(e) => {
|
||||
setAccount({ ...account, author: { ...account?.author, displayName: e.target.value } });
|
||||
setPublishReplyOptions({ displayName: e.target.value || undefined });
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.link}>
|
||||
@@ -176,7 +187,7 @@ const ReplyModal = ({ closeModal, parentCid, postCid, scrollY }: ReplyModalProps
|
||||
placeholder={_.capitalize(t('link'))}
|
||||
onChange={(e) => {
|
||||
setUrl(e.target.value);
|
||||
setPublishReplyOptions({ link: e.target.value });
|
||||
setPublishReplyOptions({ link: e.target.value || undefined });
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,8 @@ import useAnonMode from './use-anon-mode';
|
||||
type SetReplyStoreData = {
|
||||
subplebbitAddress: string;
|
||||
parentCid: string;
|
||||
author: any | undefined;
|
||||
author?: any | undefined;
|
||||
displayName?: string | undefined;
|
||||
content: string | undefined;
|
||||
link: string | undefined;
|
||||
signer?: any | undefined;
|
||||
@@ -37,11 +38,12 @@ const useReplyStore = create<ReplyState>((set) => ({
|
||||
publishCommentOptions: {},
|
||||
setReplyStore: (data: SetReplyStoreData) =>
|
||||
set((state) => {
|
||||
const { subplebbitAddress, parentCid, author, content, link, signer, spoiler } = data;
|
||||
const { subplebbitAddress, parentCid, author, displayName, content, link, signer, spoiler } = data;
|
||||
const updatedAuthor = displayName ? { ...author, displayName } : author;
|
||||
const publishCommentOptions = {
|
||||
subplebbitAddress,
|
||||
parentCid,
|
||||
author,
|
||||
...(data.author ? { author: updatedAuthor } : {}),
|
||||
...(data.signer ? { signer: data.signer } : {}),
|
||||
content,
|
||||
link,
|
||||
@@ -56,7 +58,7 @@ const useReplyStore = create<ReplyState>((set) => ({
|
||||
},
|
||||
};
|
||||
return {
|
||||
author: { ...state.author, [parentCid]: author },
|
||||
author: { ...state.author, [parentCid]: updatedAuthor },
|
||||
signer: { ...state.signer, [parentCid]: signer },
|
||||
content: { ...state.content, [parentCid]: content },
|
||||
link: { ...state.link, [parentCid]: link },
|
||||
@@ -97,7 +99,7 @@ const useReply = ({ cid, subplebbitAddress }: { cid: string; subplebbitAddress:
|
||||
setReplyStore({
|
||||
subplebbitAddress,
|
||||
parentCid,
|
||||
author,
|
||||
...(anonMode ? { author } : {}),
|
||||
content,
|
||||
link,
|
||||
spoiler,
|
||||
|
||||
Reference in New Issue
Block a user