From 00e6022e4ce8d6cfe72dcbd96fa9055ce4fa30b5 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 19 May 2023 02:33:29 +0100 Subject: [PATCH] feat: post side actions --- src/app/site/[site]/[slug]/page.tsx | 3 + src/components/common/PageContent.tsx | 9 +++ src/components/common/ReactionLike.tsx | 44 +++++++++----- src/components/common/ReactionMint.tsx | 49 +++++++++++----- src/components/common/ReactionTip.tsx | 40 +++++++++---- src/components/site/PostActions.tsx | 79 ++++++++++++++++++++++++++ src/components/site/PostToc.tsx | 4 +- 7 files changed, 185 insertions(+), 43 deletions(-) create mode 100644 src/components/site/PostActions.tsx diff --git a/src/app/site/[site]/[slug]/page.tsx b/src/app/site/[site]/[slug]/page.tsx index 35514220..a4820492 100644 --- a/src/app/site/[site]/[slug]/page.tsx +++ b/src/app/site/[site]/[slug]/page.tsx @@ -151,6 +151,9 @@ export default async function SitePagePage({ className="mt-10" content={page?.metadata?.content?.content} toc={true} + page={page} + site={site} + withActions={true} /> {!onlyContent && ( diff --git a/src/components/common/PageContent.tsx b/src/components/common/PageContent.tsx index 9e057898..811969b7 100644 --- a/src/components/common/PageContent.tsx +++ b/src/components/common/PageContent.tsx @@ -2,8 +2,10 @@ import { MutableRefObject, useEffect, useMemo } from "react" +import { PostActions } from "~/components/site/PostActions" import { PostToc } from "~/components/site/PostToc" import { useCodeCopy } from "~/hooks/useCodeCopy" +import { ExpandedCharacter, ExpandedNote } from "~/lib/types" import { calculateElementTop, cn } from "~/lib/utils" import { renderPageContent } from "~/markdown" @@ -16,6 +18,9 @@ export const PageContent: React.FC<{ onMouseEnter?: () => void parsedContent?: ReturnType isComment?: boolean + page?: ExpandedNote + site?: ExpandedCharacter + withActions?: boolean }> = ({ className, content, @@ -25,6 +30,9 @@ export const PageContent: React.FC<{ onMouseEnter, parsedContent, isComment, + page, + site, + withActions, }) => { useCodeCopy() @@ -75,6 +83,7 @@ export const PageContent: React.FC<{ {inParsedContent?.element} {toc && inParsedContent?.toc && } + {withActions && } ) } diff --git a/src/components/common/ReactionLike.tsx b/src/components/common/ReactionLike.tsx index 09e5bdf4..db47bef1 100644 --- a/src/components/common/ReactionLike.tsx +++ b/src/components/common/ReactionLike.tsx @@ -24,7 +24,8 @@ export const ReactionLike: React.FC<{ size?: "sm" | "base" characterId?: number noteId?: number -}> = ({ size, characterId, noteId }) => { + vertical?: boolean +}> = ({ size, characterId, noteId, vertical }) => { const toggleLikePage = useToggleLikePage() const { t, i18n } = useTranslation("common") @@ -94,6 +95,8 @@ export const ReactionLike: React.FC<{ } }, [toggleLikePage.isSuccess]) + const showAvatarStack = size !== "sm" && !vertical + const avatars = useMemo( () => likes @@ -112,7 +115,13 @@ export const ReactionLike: React.FC<{
- {size !== "sm" && ( + {showAvatarStack && (
- + {showAvatarStack && ( + + )} ) } diff --git a/src/components/common/ReactionMint.tsx b/src/components/common/ReactionMint.tsx index a07cfef4..44a80dd4 100644 --- a/src/components/common/ReactionMint.tsx +++ b/src/components/common/ReactionMint.tsx @@ -23,7 +23,8 @@ export const ReactionMint: React.FC<{ size?: "sm" | "base" noteId?: number characterId?: number -}> = ({ size, noteId, characterId }) => { + vertical?: boolean +}> = ({ size, noteId, characterId, vertical }) => { const mintPage = useMintPage() const { t, i18n } = useTranslation("common") @@ -83,6 +84,8 @@ export const ReactionMint: React.FC<{ } }, [mintPage.isSuccess]) + const showAvatarStack = size !== "sm" && !vertical + const avatars = useMemo( () => mints.data?.pages?.[0]?.list @@ -102,9 +105,13 @@ export const ReactionMint: React.FC<{
- {size !== "sm" && ( + {showAvatarStack && ( setIsMintListOpen(true)} @@ -161,14 +178,16 @@ export const ReactionMint: React.FC<{
- + {showAvatarStack && ( + + )} ) } diff --git a/src/components/common/ReactionTip.tsx b/src/components/common/ReactionTip.tsx index 76d4781e..6e2b54d3 100644 --- a/src/components/common/ReactionTip.tsx +++ b/src/components/common/ReactionTip.tsx @@ -9,6 +9,7 @@ import { Tooltip } from "~/components/ui/Tooltip" import { useTranslation } from "~/lib/i18n/client" import { noopArr } from "~/lib/noop" import { ExpandedCharacter, ExpandedNote } from "~/lib/types" +import { cn } from "~/lib/utils" import { useGetTips } from "~/queries/site" import { AvatarStack } from "../ui/AvatarStack" @@ -19,7 +20,8 @@ export const ReactionTip: React.FC<{ noteId?: number site?: ExpandedCharacter page?: ExpandedNote -}> = ({ characterId, noteId, site, page }) => { + vertical?: boolean +}> = ({ characterId, noteId, site, page, vertical }) => { const { t } = useTranslation("common") const account = useAccountState((s) => s.computed.account) @@ -43,6 +45,8 @@ export const ReactionTip: React.FC<{ } } + const showAvatarStack = !vertical + const avatars = useMemo( () => tips.data?.pages?.[0]?.list @@ -62,16 +66,25 @@ export const ReactionTip: React.FC<{
- - + {showAvatarStack && ( + + )}
= ({ page, site }) => { + const containerRef = useRef(null) + + const [maxWidth, setMaxWidth] = useState(0) + useEffect(() => { + if (containerRef?.current) { + setMaxWidth( + (window.innerWidth - + (containerRef.current?.parentElement?.clientWidth || 0)) / + 2 - + 40, + ) + } + }, [containerRef]) + + const comments = useGetComments({ + characterId: page?.characterId, + noteId: page?.noteId, + }) + + return ( +
60 ? "block" : "none", + }} + ref={containerRef} + > +
+ + + +
{ + const targetElement = document.querySelector( + "#comments", + ) as HTMLElement + window.scrollTo({ + top: calculateElementTop(targetElement) - 20, + behavior: "smooth", + }) + }} + > + + + {comments.data?.pages?.[0]?.count} + +
+
+
+ ) +} diff --git a/src/components/site/PostToc.tsx b/src/components/site/PostToc.tsx index 1b625b88..cd706362 100644 --- a/src/components/site/PostToc.tsx +++ b/src/components/site/PostToc.tsx @@ -154,8 +154,8 @@ export const PostToc: React.FC<{
40 ? maxWidth : 0, - display: maxWidth > 40 ? "block" : "none", + maxWidth: maxWidth > 60 ? maxWidth : 0, + display: maxWidth > 60 ? "block" : "none", }} ref={containerRef} >