From 4a94877c2261e75c4cf46c95a3e7de572bc8b99f Mon Sep 17 00:00:00 2001 From: Innei Date: Sat, 8 Jul 2023 23:39:18 +0800 Subject: [PATCH] feat: reference comment Signed-off-by: Innei --- global.d.ts | 1 + src/app/notes/[id]/page.tsx | 5 +- src/app/notes/[id]/pageExtra.tsx | 11 ++ .../(post-detail)/[category]/[slug]/page.tsx | 5 +- .../[category]/[slug]/pageExtra.tsx | 10 ++ .../widgets/comment/CommentBox/Root.tsx | 8 +- .../comment/CommentBox/UniversalTextArea.tsx | 10 +- .../widgets/comment/CommentBox/providers.tsx | 31 +++-- src/components/widgets/comment/types.ts | 1 + src/components/widgets/post/PostOutdate.tsx | 2 +- .../widgets/shared/AsideCommentButton.tsx | 33 ++---- .../widgets/shared/CommentModal.tsx | 34 ++++++ .../shared/WithArticleSelectionAction.tsx | 108 ++++++++++++++++++ src/styles/tailwindcss.css | 6 + 14 files changed, 222 insertions(+), 43 deletions(-) create mode 100644 src/components/widgets/shared/CommentModal.tsx create mode 100644 src/components/widgets/shared/WithArticleSelectionAction.tsx diff --git a/global.d.ts b/global.d.ts index 7b7d3e8aa4..5ac91e7b6a 100644 --- a/global.d.ts +++ b/global.d.ts @@ -34,6 +34,7 @@ declare global { declare module 'react' { export interface AriaAttributes { 'data-hide-print'?: boolean + 'data-event'?: string 'data-testid'?: string } } diff --git a/src/app/notes/[id]/page.tsx b/src/app/notes/[id]/page.tsx index a9c284cacd..6c005ac529 100644 --- a/src/app/notes/[id]/page.tsx +++ b/src/app/notes/[id]/page.tsx @@ -20,6 +20,7 @@ import { NoteHideIfSecret } from '../../../components/widgets/note/NoteHideIfSec import { NoteMetaBar } from '../../../components/widgets/note/NoteMetaBar' import { IndentArticleContainer, + MarkdownSelection, NoteHeaderDate, NoteHeaderMetaInfoSetting, NoteMarkdown, @@ -90,7 +91,9 @@ const NotePage = memo(function Notepage() { - + + + diff --git a/src/app/notes/[id]/pageExtra.tsx b/src/app/notes/[id]/pageExtra.tsx index 5750112735..5bbfc1ade6 100644 --- a/src/app/notes/[id]/pageExtra.tsx +++ b/src/app/notes/[id]/pageExtra.tsx @@ -14,6 +14,7 @@ import { useSetHeaderMetaInfo } from '~/components/layout/header/hooks' import { FloatPopover } from '~/components/ui/float-popover' import { Markdown } from '~/components/ui/markdown' import { GoToAdminEditingButton } from '~/components/widgets/shared/GoToAdminEditingButton' +import { WithArticleSelectionAction } from '~/components/widgets/shared/WithArticleSelectionAction' import { parseDate } from '~/lib/datetime' import { noopArr } from '~/lib/noop' import { MarkdownImageRecordProvider } from '~/providers/article/MarkdownImageRecordProvider' @@ -21,6 +22,16 @@ import { useCurrentNoteDataSelector } from '~/providers/note/CurrentNoteDataProv import styles from './page.module.css' +export const MarkdownSelection: Component = (props) => { + const id = useCurrentNoteDataSelector((data) => data?.data?.id)! + const title = useCurrentNoteDataSelector((data) => data?.data?.title)! + return ( + + {props.children} + + ) +} + export const NoteTitle = () => { const title = useCurrentNoteDataSelector((data) => data?.data.title) const id = useCurrentNoteDataSelector((data) => data?.data.id) diff --git a/src/app/posts/(post-detail)/[category]/[slug]/page.tsx b/src/app/posts/(post-detail)/[category]/[slug]/page.tsx index 5178887794..2c4aca50b9 100644 --- a/src/app/posts/(post-detail)/[category]/[slug]/page.tsx +++ b/src/app/posts/(post-detail)/[category]/[slug]/page.tsx @@ -21,6 +21,7 @@ import { WrappedElementProvider } from '~/providers/shared/WrappedElementProvide import Loading from './loading' import { HeaderMetaInfoSetting, + MarkdownSelection, PostMarkdown, PostMarkdownImageRecordProvider, PostMetaBarInternal, @@ -61,7 +62,9 @@ const PostPage = () => { - + + + diff --git a/src/app/posts/(post-detail)/[category]/[slug]/pageExtra.tsx b/src/app/posts/(post-detail)/[category]/[slug]/pageExtra.tsx index 9fc74dbc3a..638aaf8ad5 100644 --- a/src/app/posts/(post-detail)/[category]/[slug]/pageExtra.tsx +++ b/src/app/posts/(post-detail)/[category]/[slug]/pageExtra.tsx @@ -7,10 +7,20 @@ import type { PropsWithChildren } from 'react' import { useSetHeaderMetaInfo } from '~/components/layout/header/hooks' import { Markdown } from '~/components/ui/markdown' import { PostMetaBar } from '~/components/widgets/post/PostMetaBar' +import { WithArticleSelectionAction } from '~/components/widgets/shared/WithArticleSelectionAction' import { noopArr } from '~/lib/noop' import { MarkdownImageRecordProvider } from '~/providers/article/MarkdownImageRecordProvider' import { useCurrentPostDataSelector } from '~/providers/post/CurrentPostDataProvider' +export const MarkdownSelection: Component = (props) => { + const id = useCurrentPostDataSelector((data) => data?.id)! + const title = useCurrentPostDataSelector((data) => data?.title)! + return ( + + {props.children} + + ) +} export const PostMarkdown = () => { const text = useCurrentPostDataSelector((data) => data?.text) if (!text) return null diff --git a/src/components/widgets/comment/CommentBox/Root.tsx b/src/components/widgets/comment/CommentBox/Root.tsx index 22723456b9..2be53d60e5 100644 --- a/src/components/widgets/comment/CommentBox/Root.tsx +++ b/src/components/widgets/comment/CommentBox/Root.tsx @@ -17,7 +17,7 @@ import { CommentBoxSignedOutContent } from './SignedOutContent' import { SwitchCommentMode } from './SwitchCommentMode' export const CommentBoxRoot: Component = (props) => { - const { refId, className, afterSubmit } = props + const { refId, className, afterSubmit, initialValue } = props const mode = useCommentMode() @@ -27,7 +27,11 @@ export const CommentBoxRoot: Component = (props) => { }, [isLogged]) return ( - +
{ $ta.value = value } }, [value]) + + useLayoutEffect(() => { + // autofocus + const $ta = taRef.current + if (!$ta) return + $ta.selectionStart = $ta.selectionEnd = $ta.value.length + $ta.focus() + }, []) return (