From 1c74c89142d92c68e6bee491f2c3ebed7ff8a872 Mon Sep 17 00:00:00 2001 From: Innei Date: Wed, 28 Jun 2023 23:58:58 +0800 Subject: [PATCH] feat: @fz6m teaching and review suggestions --- .../header/internal/HeaderDrawerButton.tsx | 5 +- src/components/widgets/comment/Comment.tsx | 2 +- ...{CommentBoxActionBar.tsx => ActionBar.tsx} | 4 +- ...CommentAuthedInput.tsx => AuthedInput.tsx} | 52 ++++----- ...utSkeleton.tsx => AuthedInputSkeleton.tsx} | 2 +- .../comment/CommentBox/CommentBoxProvider.tsx | 110 ------------------ .../{CommentBoxRoot.tsx => Root.tsx} | 8 +- ...nedOutContent.tsx => SignedOutContent.tsx} | 11 +- .../widgets/comment/CommentBox/hooks.tsx | 61 ++++++++++ .../widgets/comment/CommentBox/index.ts | 2 +- .../widgets/comment/CommentBox/inputStyles.ts | 13 --- .../widgets/comment/CommentBox/providers.tsx | 61 ++++++++++ .../widgets/comment/CommentPinButton.tsx | 2 +- .../widgets/comment/CommentReplyButton.tsx | 8 +- .../widgets/comment/CommentRoot.tsx | 2 +- src/components/widgets/comment/Comments.tsx | 2 +- 16 files changed, 175 insertions(+), 170 deletions(-) rename src/components/widgets/comment/CommentBox/{CommentBoxActionBar.tsx => ActionBar.tsx} (99%) rename src/components/widgets/comment/CommentBox/{CommentAuthedInput.tsx => AuthedInput.tsx} (59%) rename src/components/widgets/comment/CommentBox/{CommentAuthedInputSkeleton.tsx => AuthedInputSkeleton.tsx} (87%) delete mode 100644 src/components/widgets/comment/CommentBox/CommentBoxProvider.tsx rename src/components/widgets/comment/CommentBox/{CommentBoxRoot.tsx => Root.tsx} (82%) rename src/components/widgets/comment/CommentBox/{CommentBoxSignedOutContent.tsx => SignedOutContent.tsx} (77%) create mode 100644 src/components/widgets/comment/CommentBox/hooks.tsx delete mode 100644 src/components/widgets/comment/CommentBox/inputStyles.ts create mode 100644 src/components/widgets/comment/CommentBox/providers.tsx diff --git a/src/components/layout/header/internal/HeaderDrawerButton.tsx b/src/components/layout/header/internal/HeaderDrawerButton.tsx index 2b24d2bb44..456e8fa63a 100644 --- a/src/components/layout/header/internal/HeaderDrawerButton.tsx +++ b/src/components/layout/header/internal/HeaderDrawerButton.tsx @@ -82,7 +82,10 @@ export const HeaderDrawerButton = () => { } // @ts-ignore -const LinkInternal: typeof Link = memo(({ children, ...rest }) => { +const LinkInternal: typeof Link = memo(function LinkInternal({ + children, + ...rest +}) { return ( = memo((props) => { +}> = memo(function Comment(props) { const { comment, className, showLine } = props const elAtom = useMemo(() => atom(null), []) // FIXME 兜一下后端给的脏数据 diff --git a/src/components/widgets/comment/CommentBox/CommentBoxActionBar.tsx b/src/components/widgets/comment/CommentBox/ActionBar.tsx similarity index 99% rename from src/components/widgets/comment/CommentBox/CommentBoxActionBar.tsx rename to src/components/widgets/comment/CommentBox/ActionBar.tsx index 6280c86a10..a7bb4d98e6 100644 --- a/src/components/widgets/comment/CommentBox/CommentBoxActionBar.tsx +++ b/src/components/widgets/comment/CommentBox/ActionBar.tsx @@ -21,6 +21,7 @@ import { clsxm } from '~/utils/helper' import { apiClient, getErrorMessageFromRequestError } from '~/utils/request' import { buildQueryKey } from '../Comments' +import { MAX_COMMENT_TEXT_LENGTH } from './constants' import { useCommentBoxHasText, useCommentBoxRefIdValue, @@ -30,8 +31,7 @@ import { useCommentOriginalRefId, useGetCommentBoxAtomValues, useUseCommentReply, -} from './CommentBoxProvider' -import { MAX_COMMENT_TEXT_LENGTH } from './constants' +} from './hooks' const TextLengthIndicator = () => { const isTextOversize = useCommentBoxTextIsOversize() diff --git a/src/components/widgets/comment/CommentBox/CommentAuthedInput.tsx b/src/components/widgets/comment/CommentBox/AuthedInput.tsx similarity index 59% rename from src/components/widgets/comment/CommentBox/CommentAuthedInput.tsx rename to src/components/widgets/comment/CommentBox/AuthedInput.tsx index 107f7a3de8..f9cbe39d41 100644 --- a/src/components/widgets/comment/CommentBox/CommentAuthedInput.tsx +++ b/src/components/widgets/comment/CommentBox/AuthedInput.tsx @@ -6,15 +6,31 @@ import Image from 'next/image' import { useUser } from '@clerk/nextjs' -import { CommentAuthedInputSkeleton } from './CommentAuthedInputSkeleton' -import { CommentBoxActionBar } from './CommentBoxActionBar' -import { - useCommentBoxTextValue, - useSetCommentBoxValues, -} from './CommentBoxProvider' +import { CommentBoxActionBar } from './ActionBar' +import { CommentBoxAuthedInputSkeleton } from './AuthedInputSkeleton' import { getRandomPlaceholder } from './constants' +import { useCommentBoxTextValue, useSetCommentBoxValues } from './hooks' -export const CommentAuthedInput = () => { +const TextArea = () => { + const placeholder = useRef(getRandomPlaceholder()).current + const setter = useSetCommentBoxValues() + const value = useCommentBoxTextValue() + return ( +