From aa3b3a8b5def60cd5d55706e4743b4955d0ef1f5 Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Tue, 5 Nov 2024 12:02:01 +0100 Subject: [PATCH] refactor use-publish-reply --- src/hooks/use-publish-reply.ts | 10 +++++----- src/stores/use-publish-reply-store.ts | 17 +++-------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/hooks/use-publish-reply.ts b/src/hooks/use-publish-reply.ts index 85f28a1c..a6cd90cf 100644 --- a/src/hooks/use-publish-reply.ts +++ b/src/hooks/use-publish-reply.ts @@ -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) => { - const newOptions: Partial = { + (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], ); diff --git a/src/stores/use-publish-reply-store.ts b/src/stores/use-publish-reply-store.ts index fe8d06e8..5fb4eb89 100644 --- a/src/stores/use-publish-reply-store.ts +++ b/src/stores/use-publish-reply-store.ts @@ -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((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 = {