-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed fallback preview of similar entry items
- Loading branch information
Showing
2 changed files
with
66 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...)/entry/[category]/[author]/[permlink]/_components/similar-entries/similar-entry-item.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { motion } from "framer-motion"; | ||
import Image from "next/image"; | ||
import { catchPostImage } from "@ecency/render-helper"; | ||
import { dateToFullRelative } from "@/utils"; | ||
import { EntryLink } from "@/features/shared"; | ||
import React, { useMemo } from "react"; | ||
import { SearchResult } from "@/entities"; | ||
import { useGlobalStore } from "@/core/global-store"; | ||
|
||
interface Props { | ||
entry: SearchResult; | ||
i: number; | ||
} | ||
|
||
export function SimilarEntryItem({ entry, i }: Props) { | ||
const canUseWebp = useGlobalStore((s) => s.canUseWebp); | ||
const postImage = useMemo( | ||
() => catchPostImage(entry.img_url, 600, 500, canUseWebp ? "webp" : "match"), | ||
[canUseWebp, entry.img_url] | ||
); | ||
|
||
return ( | ||
<EntryLink entry={entry}> | ||
<motion.div | ||
className="similar-entries-list-item bg-gray-100 hover:bg-blue-dark-sky-040 dark:bg-gray-900 rounded-2xl overflow-hidden" | ||
whileHover={{ | ||
rotate: 1.5 | ||
}} | ||
initial={{ | ||
opacity: 0, | ||
y: -24 | ||
}} | ||
animate={{ opacity: 1, y: 0, transition: { delay: i * 0.2 } }} | ||
> | ||
{postImage && ( | ||
<Image | ||
src={postImage} | ||
alt={entry.title} | ||
width={1000} | ||
height={1000} | ||
className="object-cover w-full h-[8rem]" | ||
/> | ||
)} | ||
{!postImage && ( | ||
<div className="w-full h-[8rem] flex items-center justify-center bg-gray-200 dark:bg-dark-default"> | ||
<Image | ||
src="/assets/noimage.svg" | ||
alt={entry.title} | ||
width={1000} | ||
height={1000} | ||
className="w-8 h-8" | ||
/> | ||
</div> | ||
)} | ||
<div className="truncate py-2 px-4">{entry.title}</div> | ||
<div className="item-footer py-2 px-4"> | ||
<span className="item-footer-author">{entry.author}</span> | ||
<span className="item-footer-date">{dateToFullRelative(entry.created_at)}</span> | ||
</div> | ||
</motion.div> | ||
</EntryLink> | ||
); | ||
} |