mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
refactor use-publish-reply
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useAccount, usePublishComment } from '@plebbit/plebbit-react-hooks';
|
||||
import { Comment, useAccount, usePublishComment } from '@plebbit/plebbit-react-hooks';
|
||||
import useAnonMode from './use-anon-mode';
|
||||
import usePublishReplyStore, { SetReplyStoreData } from '../stores/use-publish-reply-store';
|
||||
import usePublishReplyStore from '../stores/use-publish-reply-store';
|
||||
|
||||
const usePublishReply = ({ cid, subplebbitAddress }: { cid: string; subplebbitAddress: string }) => {
|
||||
const parentCid = cid;
|
||||
@@ -22,8 +22,8 @@ const usePublishReply = ({ cid, subplebbitAddress }: { cid: string; subplebbitAd
|
||||
const resetReplyStore = usePublishReplyStore((state) => state.resetReplyStore);
|
||||
|
||||
const setPublishReplyOptions = useCallback(
|
||||
(options: Partial<SetReplyStoreData>) => {
|
||||
const newOptions: Partial<SetReplyStoreData> = {
|
||||
(options: Comment) => {
|
||||
const newOptions: Comment = {
|
||||
subplebbitAddress,
|
||||
parentCid,
|
||||
content: options.content === '' ? undefined : options.content ?? content,
|
||||
@@ -51,7 +51,7 @@ const usePublishReply = ({ cid, subplebbitAddress }: { cid: string; subplebbitAd
|
||||
};
|
||||
}
|
||||
|
||||
setReplyStore(newOptions as SetReplyStoreData);
|
||||
setReplyStore(newOptions);
|
||||
},
|
||||
[subplebbitAddress, parentCid, author, signer, content, link, spoiler, setReplyStore, anonMode, account],
|
||||
);
|
||||
|
||||
@@ -3,17 +3,6 @@ import { create } from 'zustand';
|
||||
import { alertChallengeVerificationFailed } from '../lib/utils/challenge-utils';
|
||||
import useChallengesStore from './use-challenges-store';
|
||||
|
||||
export type SetReplyStoreData = {
|
||||
subplebbitAddress: string;
|
||||
parentCid: string;
|
||||
author?: any;
|
||||
displayName?: string;
|
||||
content: string;
|
||||
link?: string;
|
||||
signer?: any;
|
||||
spoiler: boolean;
|
||||
};
|
||||
|
||||
type ReplyState = {
|
||||
author: { [parentCid: string]: any | undefined };
|
||||
displayName: { [parentCid: string]: string | undefined };
|
||||
@@ -22,7 +11,7 @@ type ReplyState = {
|
||||
signer: { [parentCid: string]: any | undefined };
|
||||
spoiler: { [parentCid: string]: boolean | undefined };
|
||||
publishCommentOptions: { [parentCid: string]: PublishCommentOptions | undefined };
|
||||
setReplyStore: (data: SetReplyStoreData) => void;
|
||||
setReplyStore: (comment: Comment) => void;
|
||||
resetReplyStore: (parentCid: string) => void;
|
||||
};
|
||||
|
||||
@@ -37,9 +26,9 @@ const usePublishReplyStore = create<ReplyState>((set) => ({
|
||||
spoiler: {},
|
||||
publishCommentOptions: {},
|
||||
|
||||
setReplyStore: (data: SetReplyStoreData) =>
|
||||
setReplyStore: (comment: Comment) =>
|
||||
set((state) => {
|
||||
const { subplebbitAddress, parentCid, author, displayName, content, link, signer, spoiler } = data;
|
||||
const { subplebbitAddress, parentCid, author, displayName, content, link, signer, spoiler } = comment;
|
||||
const updatedAuthor = displayName ? { ...author, displayName } : author;
|
||||
|
||||
const publishCommentOptions: PublishCommentOptions = {
|
||||
|
||||
Reference in New Issue
Block a user