From 7a31ee727d2a70940872768ca111e5212d4ed44c Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 9 Jun 2023 15:42:06 +0100 Subject: [PATCH] feat: posts in view fade in --- src/components/common/FadeIn.tsx | 44 +++++++++ src/components/home/HomeFeed.tsx | 131 ++++++++++++++------------- src/components/site/PostList.tsx | 151 ++++++++++++++++--------------- tailwind.config.ts | 1 + 4 files changed, 191 insertions(+), 136 deletions(-) create mode 100644 src/components/common/FadeIn.tsx diff --git a/src/components/common/FadeIn.tsx b/src/components/common/FadeIn.tsx new file mode 100644 index 00000000..d742c5f7 --- /dev/null +++ b/src/components/common/FadeIn.tsx @@ -0,0 +1,44 @@ +"use client" + +import { useInViewport } from "ahooks" +import { useEffect, useRef, useState } from "react" + +import { cn } from "~/lib/utils" + +const FadeIn = ({ + children, + className, + ...props +}: { + children?: JSX.Element | JSX.Element[] + className?: string +} & React.HTMLAttributes) => { + const ref = useRef(null) + const [isInView] = useInViewport(ref) + + const [locked, setLocked] = useState(false) + + useEffect(() => { + if (!locked && isInView === true) { + setLocked(true) + } + }, [isInView]) + + return ( +
+ {children} +
+ ) +} + +export default FadeIn diff --git a/src/components/home/HomeFeed.tsx b/src/components/home/HomeFeed.tsx index 964323bb..71833fd3 100644 --- a/src/components/home/HomeFeed.tsx +++ b/src/components/home/HomeFeed.tsx @@ -10,9 +10,12 @@ import { useAccountState, useConnectModal } from "@crossbell/connect-kit" import { Switch } from "@headlessui/react" import { CharacterFloatCard } from "~/components/common/CharacterFloatCard" +import FadeIn from "~/components/common/FadeIn" import { Titles } from "~/components/common/Titles" import PostCover from "~/components/site/PostCover" +import { EmptyState } from "~/components/ui/EmptyState" import { Image } from "~/components/ui/Image" +import { Skeleton } from "~/components/ui/Skeleton" import { Tabs } from "~/components/ui/Tabs" import { Tooltip } from "~/components/ui/Tooltip" import { useDate } from "~/hooks/useDate" @@ -24,8 +27,6 @@ import type { FeedType, SearchType } from "~/models/home.model" import { useGetFeed } from "~/queries/home" import topics from "../../../data/topics.json" -import { EmptyState } from "../ui/EmptyState" -import { Skeleton } from "../ui/Skeleton" const PostCard = ({ post, @@ -156,70 +157,72 @@ const Post = ({ } return ( -
- {!simple && ( -
- - + <> + {!simple && ( +
+ + + + {post.character?.handle + + + {post.character?.metadata?.content?.name || + post.character?.handle} + + + + + · +
+ )} + {isComment && ( + - {t("ago", { - time: date.dayjs - .duration( - date.dayjs(post?.createdAt).diff(date.dayjs(), "minute"), - "minute", - ) - .humanize(), - })} - -
- )} - {isComment && ( - - - - {post.metadata?.content?.summary} - - - )} - -
+ + + {post.metadata?.content?.summary} + + + )} + + + ) } diff --git a/src/components/site/PostList.tsx b/src/components/site/PostList.tsx index 70e5fb61..6b5978eb 100644 --- a/src/components/site/PostList.tsx +++ b/src/components/site/PostList.tsx @@ -7,6 +7,7 @@ import reactStringReplace from "react-string-replace" import { UseInfiniteQueryResult } from "@tanstack/react-query" +import FadeIn from "~/components/common/FadeIn" import PostCover from "~/components/site/PostCover" import { Button } from "~/components/ui/Button" import { EmptyState } from "~/components/ui/EmptyState" @@ -53,85 +54,91 @@ export default function PostList({ posts.list.map((post) => { currentLength++ return ( - - -
-

- {post.metadata?.content?.title} -

-
- - {!!post.metadata?.content?.tags?.filter( - (tag) => tag !== "post" && tag !== "page", - ).length && ( - + +
+

+ {post.metadata?.content?.title} +

+
+ + {!!post.metadata?.content?.tags?.filter( + (tag) => tag !== "post" && tag !== "page", + ).length && ( + + {post.metadata?.content?.tags + ?.filter( + (tag) => tag !== "post" && tag !== "page", + ) + .map((tag) => ( + { + e.stopPropagation() + e.preventDefault() + router.push(`/tag/${tag}`) + }} + > + #{tag} + + ))} + + )} + + + {post.metadata?.content?.views} - )} - +
- - {post.metadata?.content?.views} - + {keyword + ? reactStringReplace( + post.metadata?.content?.summary || "", + keyword, + (match, i) => ( + + {match} + + ), + ) + : post.metadata?.content?.summary} + {post.metadata?.content?.summary && "..."} +
-
- {keyword - ? reactStringReplace( - post.metadata?.content?.summary || "", - keyword, - (match, i) => ( - - {match} - - ), - ) - : post.metadata?.content?.summary} - {post.metadata?.content?.summary && "..."} -
-
- + + ) }), )} diff --git a/tailwind.config.ts b/tailwind.config.ts index e662a70e..2e4a6785 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -71,6 +71,7 @@ const config: Config = { }, transitionDuration: { "400": "400ms", + "800": "800ms", }, }, },