mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
- delete the anon mode hook/store and stop wiring publish flows through alternate signers - strip the settings UI, avatar warning, reply indicators, and FAQ text that referenced the toggle - drop the anon mode translation keys via scripts/update-translations.js
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import { useCallback } from 'react';
|
|
import { Comment, useAccount, usePublishComment } from '@plebbit/plebbit-react-hooks';
|
|
import usePublishReplyStore from '../stores/use-publish-reply-store';
|
|
|
|
const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; subplebbitAddress: string; postCid?: string }) => {
|
|
const parentCid = cid;
|
|
const account = useAccount();
|
|
|
|
const { author, content, link, spoiler, publishCommentOptions } = usePublishReplyStore((state) => ({
|
|
author: state.author[parentCid],
|
|
content: state.content[parentCid] || undefined,
|
|
link: state.link[parentCid] || undefined,
|
|
spoiler: state.spoiler[parentCid] || false,
|
|
publishCommentOptions: state.publishCommentOptions[parentCid],
|
|
}));
|
|
|
|
const setPublishReplyStore = usePublishReplyStore((state) => state.setPublishReplyStore);
|
|
const resetPublishReplyStore = usePublishReplyStore((state) => state.resetPublishReplyStore);
|
|
|
|
const createBaseOptions = useCallback(() => {
|
|
const baseOptions: Comment = {
|
|
subplebbitAddress,
|
|
parentCid,
|
|
postCid: postCid ?? parentCid,
|
|
content,
|
|
link,
|
|
spoiler,
|
|
};
|
|
|
|
baseOptions.author = {
|
|
...account?.author,
|
|
displayName: author?.displayName || account?.author?.displayName,
|
|
};
|
|
|
|
return baseOptions;
|
|
}, [author, content, link, parentCid, postCid, spoiler, subplebbitAddress, account]);
|
|
|
|
const setPublishReplyOptions = useCallback(
|
|
(options: Partial<Comment>) => {
|
|
const baseOptions = createBaseOptions();
|
|
const sanitizedOptions = Object.entries(options).reduce((acc, [key, value]) => {
|
|
acc[key] = value === '' ? undefined : value;
|
|
return acc;
|
|
}, {} as Partial<Comment>);
|
|
|
|
const newOptions = { ...baseOptions, ...sanitizedOptions };
|
|
setPublishReplyStore(newOptions);
|
|
},
|
|
[createBaseOptions, setPublishReplyStore],
|
|
);
|
|
|
|
const resetPublishReplyOptions = useCallback(() => resetPublishReplyStore(parentCid), [parentCid, resetPublishReplyStore]);
|
|
|
|
const { index, publishComment } = usePublishComment(publishCommentOptions);
|
|
|
|
return {
|
|
setPublishReplyOptions,
|
|
resetPublishReplyOptions,
|
|
replyIndex: index,
|
|
publishReply: publishComment,
|
|
};
|
|
};
|
|
|
|
export default usePublishReply;
|