feat: posts in view fade in
This commit is contained in:
@@ -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<HTMLDivElement>) => {
|
||||
const ref = useRef<HTMLDivElement>(null)
|
||||
const [isInView] = useInViewport(ref)
|
||||
|
||||
const [locked, setLocked] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!locked && isInView === true) {
|
||||
setLocked(true)
|
||||
}
|
||||
}, [isInView])
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
className,
|
||||
"transition-[opacity,transform] duration-800 ease-in-out",
|
||||
isInView === false && !locked
|
||||
? "opacity-0 translate-y-[20%]"
|
||||
: "opacity-1 translate-y-0",
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default FadeIn
|
||||
@@ -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 (
|
||||
<div className={cn(simple ? "!mt-4" : "")}>
|
||||
{!simple && (
|
||||
<div className="flex items-center space-x-2">
|
||||
<CharacterFloatCard siteId={post.character?.handle}>
|
||||
<Link
|
||||
target="_blank"
|
||||
href={`/api/redirection?characterId=${post.characterId}`}
|
||||
className="flex items-center space-x-4 cursor-pointer"
|
||||
prefetch={false}
|
||||
<FadeIn className={cn(simple ? "!mt-4" : "")}>
|
||||
<>
|
||||
{!simple && (
|
||||
<div className="flex items-center space-x-2">
|
||||
<CharacterFloatCard siteId={post.character?.handle}>
|
||||
<Link
|
||||
target="_blank"
|
||||
href={`/api/redirection?characterId=${post.characterId}`}
|
||||
className="flex items-center space-x-4 cursor-pointer"
|
||||
prefetch={false}
|
||||
>
|
||||
<span className="w-10 h-10 inline-block">
|
||||
<Image
|
||||
className="rounded-full"
|
||||
src={
|
||||
post.character?.metadata?.content?.avatars?.[0] ||
|
||||
"ipfs://bafkreiabgixxp63pg64moxnsydz7hewmpdkxxi3kdsa4oqv4pb6qvwnmxa"
|
||||
}
|
||||
alt={post.character?.handle || ""}
|
||||
width="40"
|
||||
height="40"
|
||||
></Image>
|
||||
</span>
|
||||
<span className="font-medium">
|
||||
{post.character?.metadata?.content?.name ||
|
||||
post.character?.handle}
|
||||
</span>
|
||||
</Link>
|
||||
</CharacterFloatCard>
|
||||
<Titles characterId={post.characterId} />
|
||||
<span className="text-zinc-400">·</span>
|
||||
<time
|
||||
dateTime={date.formatToISO(post.createdAt)}
|
||||
className="xlog-post-date whitespace-nowrap text-zinc-400 text-sm"
|
||||
>
|
||||
<span className="w-10 h-10 inline-block">
|
||||
<Image
|
||||
className="rounded-full"
|
||||
src={
|
||||
post.character?.metadata?.content?.avatars?.[0] ||
|
||||
"ipfs://bafkreiabgixxp63pg64moxnsydz7hewmpdkxxi3kdsa4oqv4pb6qvwnmxa"
|
||||
}
|
||||
alt={post.character?.handle || ""}
|
||||
width="40"
|
||||
height="40"
|
||||
></Image>
|
||||
</span>
|
||||
<span className="font-medium">
|
||||
{post.character?.metadata?.content?.name ||
|
||||
post.character?.handle}
|
||||
</span>
|
||||
</Link>
|
||||
</CharacterFloatCard>
|
||||
<Titles characterId={post.characterId} />
|
||||
<span className="text-zinc-400">·</span>
|
||||
<time
|
||||
dateTime={date.formatToISO(post.createdAt)}
|
||||
className="xlog-post-date whitespace-nowrap text-zinc-400 text-sm"
|
||||
{t("ago", {
|
||||
time: date.dayjs
|
||||
.duration(
|
||||
date.dayjs(post?.createdAt).diff(date.dayjs(), "minute"),
|
||||
"minute",
|
||||
)
|
||||
.humanize(),
|
||||
})}
|
||||
</time>
|
||||
</div>
|
||||
)}
|
||||
{isComment && (
|
||||
<Link
|
||||
target="_blank"
|
||||
href={`/api/redirection?characterId=${post.characterId}¬eId=${post.noteId}`}
|
||||
className="block p-4 ml-10 font-medium text-zinc-700"
|
||||
>
|
||||
{t("ago", {
|
||||
time: date.dayjs
|
||||
.duration(
|
||||
date.dayjs(post?.createdAt).diff(date.dayjs(), "minute"),
|
||||
"minute",
|
||||
)
|
||||
.humanize(),
|
||||
})}
|
||||
</time>
|
||||
</div>
|
||||
)}
|
||||
{isComment && (
|
||||
<Link
|
||||
target="_blank"
|
||||
href={`/api/redirection?characterId=${post.characterId}¬eId=${post.noteId}`}
|
||||
className="block p-4 ml-10 font-medium text-zinc-700"
|
||||
>
|
||||
<i className="icon-[mingcute--comment-fill] align-middle mr-2" />
|
||||
<span className="align-middle">
|
||||
{post.metadata?.content?.summary}
|
||||
</span>
|
||||
</Link>
|
||||
)}
|
||||
<PostCard
|
||||
post={isComment ? (post.toNote as ExpandedNote) : post}
|
||||
simple={simple || isComment}
|
||||
isComment={isComment}
|
||||
keyword={keyword}
|
||||
/>
|
||||
</div>
|
||||
<i className="icon-[mingcute--comment-fill] align-middle mr-2" />
|
||||
<span className="align-middle">
|
||||
{post.metadata?.content?.summary}
|
||||
</span>
|
||||
</Link>
|
||||
)}
|
||||
<PostCard
|
||||
post={isComment ? (post.toNote as ExpandedNote) : post}
|
||||
simple={simple || isComment}
|
||||
isComment={isComment}
|
||||
keyword={keyword}
|
||||
/>
|
||||
</>
|
||||
</FadeIn>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<Link
|
||||
<FadeIn
|
||||
key={`${post.characterId}-${post.noteId}`}
|
||||
className="xlog-post -mx-5 first:-mt-5 sm:rounded-2xl bg-white"
|
||||
role="article"
|
||||
key={post.transactionHash}
|
||||
href={getSlugUrl(`/${post.metadata?.content?.slug}`)}
|
||||
className="xlog-post focus-visible:outline focus-visible:outline-accent bg-white transition-colors px-5 py-7 -mx-5 first:-mt-5 sm:rounded-xl flex flex-col sm:flex-row items-center group"
|
||||
suppressHydrationWarning
|
||||
aria-label={post.metadata?.content?.title}
|
||||
>
|
||||
<PostCover cover={post.metadata?.content?.cover} />
|
||||
<div className="flex-1 flex justify-center flex-col w-full min-w-0">
|
||||
<h3 className="xlog-post-title text-2xl font-bold text-zinc-700 line-clamp-2">
|
||||
{post.metadata?.content?.title}
|
||||
</h3>
|
||||
<div className="xlog-post-meta text-sm text-zinc-400 mt-1 space-x-4 flex items-center mr-8">
|
||||
<time
|
||||
dateTime={date.formatToISO(
|
||||
post.metadata?.content?.date_published || "",
|
||||
)}
|
||||
className="xlog-post-date whitespace-nowrap"
|
||||
>
|
||||
{date.formatDate(
|
||||
post.metadata?.content?.date_published || "",
|
||||
undefined,
|
||||
isMounted ? undefined : "America/Los_Angeles",
|
||||
)}
|
||||
</time>
|
||||
{!!post.metadata?.content?.tags?.filter(
|
||||
(tag) => tag !== "post" && tag !== "page",
|
||||
).length && (
|
||||
<span
|
||||
aria-label="tags for this post"
|
||||
className="xlog-post-tags space-x-1 truncate min-w-0"
|
||||
<Link
|
||||
className="flex flex-col sm:flex-row items-center group px-5 py-7 focus-visible:outline focus-visible:outline-accent"
|
||||
href={getSlugUrl(`/${post.metadata?.content?.slug}`)}
|
||||
suppressHydrationWarning
|
||||
>
|
||||
<PostCover cover={post.metadata?.content?.cover} />
|
||||
<div className="flex-1 flex justify-center flex-col w-full min-w-0">
|
||||
<h3 className="xlog-post-title text-2xl font-bold text-zinc-700 line-clamp-2">
|
||||
{post.metadata?.content?.title}
|
||||
</h3>
|
||||
<div className="xlog-post-meta text-sm text-zinc-400 mt-1 space-x-4 flex items-center mr-8">
|
||||
<time
|
||||
dateTime={date.formatToISO(
|
||||
post.metadata?.content?.date_published || "",
|
||||
)}
|
||||
className="xlog-post-date whitespace-nowrap"
|
||||
>
|
||||
{post.metadata?.content?.tags
|
||||
?.filter((tag) => tag !== "post" && tag !== "page")
|
||||
.map((tag) => (
|
||||
<span
|
||||
className="hover:text-zinc-600"
|
||||
key={tag}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
router.push(`/tag/${tag}`)
|
||||
}}
|
||||
>
|
||||
#{tag}
|
||||
</span>
|
||||
))}
|
||||
{date.formatDate(
|
||||
post.metadata?.content?.date_published || "",
|
||||
undefined,
|
||||
isMounted ? undefined : "America/Los_Angeles",
|
||||
)}
|
||||
</time>
|
||||
{!!post.metadata?.content?.tags?.filter(
|
||||
(tag) => tag !== "post" && tag !== "page",
|
||||
).length && (
|
||||
<span
|
||||
aria-label="tags for this post"
|
||||
className="xlog-post-tags space-x-1 truncate min-w-0"
|
||||
>
|
||||
{post.metadata?.content?.tags
|
||||
?.filter(
|
||||
(tag) => tag !== "post" && tag !== "page",
|
||||
)
|
||||
.map((tag) => (
|
||||
<span
|
||||
className="hover:text-zinc-600"
|
||||
key={tag}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
router.push(`/tag/${tag}`)
|
||||
}}
|
||||
>
|
||||
#{tag}
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
<span
|
||||
aria-label="views for this post"
|
||||
className="xlog-post-views inline-flex items-center"
|
||||
>
|
||||
<i className="icon-[mingcute--eye-line] mr-[2px]" />
|
||||
<span>{post.metadata?.content?.views}</span>
|
||||
</span>
|
||||
)}
|
||||
<span
|
||||
aria-label="views for this post"
|
||||
className="xlog-post-views inline-flex items-center"
|
||||
</div>
|
||||
<div
|
||||
className="xlog-post-excerpt mt-3 text-zinc-500 line-clamp-2"
|
||||
style={{
|
||||
wordBreak: "break-word",
|
||||
}}
|
||||
>
|
||||
<i className="icon-[mingcute--eye-line] mr-[2px]" />
|
||||
<span>{post.metadata?.content?.views}</span>
|
||||
</span>
|
||||
{keyword
|
||||
? reactStringReplace(
|
||||
post.metadata?.content?.summary || "",
|
||||
keyword,
|
||||
(match, i) => (
|
||||
<span key={i} className="bg-yellow-200">
|
||||
{match}
|
||||
</span>
|
||||
),
|
||||
)
|
||||
: post.metadata?.content?.summary}
|
||||
{post.metadata?.content?.summary && "..."}
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className="xlog-post-excerpt mt-3 text-zinc-500 line-clamp-2"
|
||||
style={{
|
||||
wordBreak: "break-word",
|
||||
}}
|
||||
>
|
||||
{keyword
|
||||
? reactStringReplace(
|
||||
post.metadata?.content?.summary || "",
|
||||
keyword,
|
||||
(match, i) => (
|
||||
<span key={i} className="bg-yellow-200">
|
||||
{match}
|
||||
</span>
|
||||
),
|
||||
)
|
||||
: post.metadata?.content?.summary}
|
||||
{post.metadata?.content?.summary && "..."}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
</Link>
|
||||
</FadeIn>
|
||||
)
|
||||
}),
|
||||
)}
|
||||
|
||||
@@ -71,6 +71,7 @@ const config: Config = {
|
||||
},
|
||||
transitionDuration: {
|
||||
"400": "400ms",
|
||||
"800": "800ms",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user