diff --git a/src/app/(page-detail)/[slug]/page.tsx b/src/app/(page-detail)/[slug]/page.tsx index 0f5db71c86..23e9a038ab 100644 --- a/src/app/(page-detail)/[slug]/page.tsx +++ b/src/app/(page-detail)/[slug]/page.tsx @@ -4,14 +4,20 @@ import { ReadIndicatorForMobile } from '~/components/widgets/shared/ReadIndicato import { LayoutRightSidePortal } from '~/providers/shared/LayoutRightSideProvider' import { WrappedElementProvider } from '~/providers/shared/WrappedElementProvider' -import { MarkdownImageRecordProviderInternal, PageMarkdown } from './pageExtra' +import { + MarkdownImageRecordProviderInternal, + MarkdownSelection, + PageMarkdown, +} from './pageExtra' const PageDetail = () => { return ( - + + + diff --git a/src/app/(page-detail)/[slug]/pageExtra.tsx b/src/app/(page-detail)/[slug]/pageExtra.tsx index 3e185258c4..1a5fb24caf 100644 --- a/src/app/(page-detail)/[slug]/pageExtra.tsx +++ b/src/app/(page-detail)/[slug]/pageExtra.tsx @@ -9,6 +9,7 @@ import type { PropsWithChildren } from 'react' import { useSetHeaderMetaInfo } from '~/components/layout/header/hooks' import { MainMarkdown } from '~/components/ui/markdown' import { GoToAdminEditingButton } from '~/components/widgets/shared/GoToAdminEditingButton' +import { WithArticleSelectionAction } from '~/components/widgets/shared/WithArticleSelectionAction' import { noopArr } from '~/lib/noop' import { MarkdownImageRecordProvider } from '~/providers/article/MarkdownImageRecordProvider' import { useCurrentPageDataSelector } from '~/providers/page/CurrentPageDataProvider' @@ -138,3 +139,18 @@ export const PagePaginator = () => { ) } + +export const MarkdownSelection: Component = (props) => { + const id = useCurrentPageDataSelector((data) => data?.id)! + const title = useCurrentPageDataSelector((data) => data?.title)! + const canComment = useCurrentPageDataSelector((data) => data?.allowComment)! + return ( + + {props.children} + + ) +} diff --git a/src/app/notes/[id]/pageExtra.tsx b/src/app/notes/[id]/pageExtra.tsx index e02944ca6a..6b1ad9ed7e 100644 --- a/src/app/notes/[id]/pageExtra.tsx +++ b/src/app/notes/[id]/pageExtra.tsx @@ -25,8 +25,15 @@ 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)! + const canComment = useCurrentNoteDataSelector( + (data) => data?.data.allowComment, + )! return ( - + {props.children} ) diff --git a/src/app/posts/(post-detail)/[category]/[slug]/pageExtra.tsx b/src/app/posts/(post-detail)/[category]/[slug]/pageExtra.tsx index 723abeffad..3e2c1bdccf 100644 --- a/src/app/posts/(post-detail)/[category]/[slug]/pageExtra.tsx +++ b/src/app/posts/(post-detail)/[category]/[slug]/pageExtra.tsx @@ -25,8 +25,13 @@ export const PostTitle = () => { export const MarkdownSelection: Component = (props) => { const id = useCurrentPostDataSelector((data) => data?.id)! const title = useCurrentPostDataSelector((data) => data?.title)! + const allowComment = useCurrentPostDataSelector((data) => data?.allowComment)! return ( - + {props.children} ) diff --git a/src/components/layout/header/internal/HeaderDrawerButton.tsx b/src/components/layout/header/internal/HeaderDrawerButton.tsx index 6090d3c19f..905fed1737 100644 --- a/src/components/layout/header/internal/HeaderDrawerButton.tsx +++ b/src/components/layout/header/internal/HeaderDrawerButton.tsx @@ -6,7 +6,7 @@ import { atom, useAtom } from 'jotai' import { CloseIcon } from '~/components/icons/close' import { MotionButtonBase } from '~/components/ui/button' -import { DialogOverlay } from '~/components/ui/dlalog/DialogOverlay' +import { DialogOverlay } from '~/components/ui/dialog/DialogOverlay' import { useIsClient } from '~/hooks/common/use-is-client' import { HeaderActionButton } from './HeaderActionButton' diff --git a/src/components/ui/dlalog/DialogOverlay.tsx b/src/components/ui/dialog/DialogOverlay.tsx similarity index 100% rename from src/components/ui/dlalog/DialogOverlay.tsx rename to src/components/ui/dialog/DialogOverlay.tsx diff --git a/src/components/ui/dlalog/index.ts b/src/components/ui/dialog/index.ts similarity index 100% rename from src/components/ui/dlalog/index.ts rename to src/components/ui/dialog/index.ts diff --git a/src/components/widgets/shared/AsideDonateButton.tsx b/src/components/widgets/shared/AsideDonateButton.tsx index 8f968c76e8..8ee29f3b38 100644 --- a/src/components/widgets/shared/AsideDonateButton.tsx +++ b/src/components/widgets/shared/AsideDonateButton.tsx @@ -5,7 +5,7 @@ import type { HTMLMotionProps } from 'framer-motion' import { ImpressionView } from '~/components/common/ImpressionTracker' import { MotionButtonBase } from '~/components/ui/button' -import { DialogOverlay } from '~/components/ui/dlalog/DialogOverlay' +import { DialogOverlay } from '~/components/ui/dialog/DialogOverlay' import { TrackerAction } from '~/constants/tracker' import { useIsClient } from '~/hooks/common/use-is-client' import { clsxm } from '~/lib/helper' diff --git a/src/components/widgets/shared/BanCopyWrapper.tsx b/src/components/widgets/shared/BanCopyWrapper.tsx index 3eb6eedd8e..1c9b63ca8d 100644 --- a/src/components/widgets/shared/BanCopyWrapper.tsx +++ b/src/components/widgets/shared/BanCopyWrapper.tsx @@ -1,13 +1,17 @@ 'use client' import { DialogContent, DialogPortal, Root } from '@radix-ui/react-dialog' -import { useEffect, useRef, useState } from 'react' +import { createContext, useContext, useEffect, useRef, useState } from 'react' import { AnimatePresence, m } from 'framer-motion' import type { FC, PropsWithChildren } from 'react' import { isLogged } from '~/atoms' -import { DialogOverlay } from '../../ui/dlalog' +import { DialogOverlay } from '../../ui/dialog' + +const BanCopyContext = createContext(false) + +export const useIsInBanCopyContext = () => useContext(BanCopyContext) export const BanCopyWrapper: FC = (props) => { const [showCopyWarn, setShowCopyWarn] = useState(false) @@ -42,7 +46,7 @@ export const BanCopyWrapper: FC = (props) => { } }, [showCopyWarn]) return ( - <> +
{props.children}
@@ -71,6 +75,6 @@ export const BanCopyWrapper: FC = (props) => { )} - +
) } diff --git a/src/components/widgets/shared/WithArticleSelectionAction.tsx b/src/components/widgets/shared/WithArticleSelectionAction.tsx index 03994b52a7..f9e3d64368 100644 --- a/src/components/widgets/shared/WithArticleSelectionAction.tsx +++ b/src/components/widgets/shared/WithArticleSelectionAction.tsx @@ -10,12 +10,14 @@ import { useIsClient } from '~/hooks/common/use-is-client' import { stopPropagation } from '~/lib/dom' import { useModalStack } from '~/providers/root/modal-stack-provider' +import { useIsInBanCopyContext } from './BanCopyWrapper' import { CommentModal } from './CommentModal' export const WithArticleSelectionAction: Component<{ refId: string title: string -}> = ({ refId, title, children }) => { + canComment: boolean +}> = ({ refId, title, children, canComment }) => { const isMobile = useIsMobile() const [pos, setPos] = useState({ x: 0, @@ -52,7 +54,12 @@ export const WithArticleSelectionAction: Component<{ }, 1000) }, []) + const canCopy = !useIsInBanCopyContext() + + const actionCanActivated = canCopy || canComment + if (isMobile || !isClient) return children + if (!actionCanActivated) return children return (
- { - navigator.clipboard.writeText(selectedText) - setShow(false) - }} - > - 复制 - - - { - present({ - title: '评论', + {canCopy && ( + <> + { + navigator.clipboard.writeText(selectedText) + setShow(false) + }} + > + 复制 + + + + )} + {canComment && ( + { + present({ + title: '评论', - content: (rest) => ( - ${selectedText - ?.split('\n') - .join('')}\n\n`} - {...rest} - /> - ), - }) - }} - > - 引用评论 - + content: (rest) => ( + ${selectedText + ?.split('\n') + .join('')}\n\n`} + {...rest} + /> + ), + }) + }} + > + 引用评论 + + )} )} diff --git a/src/providers/root/modal-stack-provider.tsx b/src/providers/root/modal-stack-provider.tsx index 9d7045e1b1..0f934f9025 100644 --- a/src/providers/root/modal-stack-provider.tsx +++ b/src/providers/root/modal-stack-provider.tsx @@ -17,8 +17,8 @@ import type { Target, Transition } from 'framer-motion' import type { FC, PropsWithChildren, SyntheticEvent } from 'react' import { CloseIcon } from '~/components/icons/close' +import { DialogOverlay } from '~/components/ui/dialog/DialogOverlay' import { Divider } from '~/components/ui/divider' -import { DialogOverlay } from '~/components/ui/dlalog/DialogOverlay' import { microReboundPreset } from '~/constants/spring' import { useEventCallback } from '~/hooks/common/use-event-callback' import { useIsClient } from '~/hooks/common/use-is-client'