From 73f537ba2df42ebe5ecdbd660d21bc90a466da8e Mon Sep 17 00:00:00 2001 From: "ildar.timerbaev" Date: Tue, 5 Nov 2024 00:02:24 +0300 Subject: [PATCH] Fixed fallback preview of similar entry items --- .../_components/similar-entries/index.tsx | 45 +------------ .../similar-entries/similar-entry-item.tsx | 63 +++++++++++++++++++ 2 files changed, 66 insertions(+), 42 deletions(-) create mode 100644 src/app/(dynamicPages)/entry/[category]/[author]/[permlink]/_components/similar-entries/similar-entry-item.tsx diff --git a/src/app/(dynamicPages)/entry/[category]/[author]/[permlink]/_components/similar-entries/index.tsx b/src/app/(dynamicPages)/entry/[category]/[author]/[permlink]/_components/similar-entries/index.tsx index 252c35555..77e8ce354 100644 --- a/src/app/(dynamicPages)/entry/[category]/[author]/[permlink]/_components/similar-entries/index.tsx +++ b/src/app/(dynamicPages)/entry/[category]/[author]/[permlink]/_components/similar-entries/index.tsx @@ -3,17 +3,12 @@ import React from "react"; import defaults from "@/defaults.json"; -import { catchPostImage, setProxyBase } from "@ecency/render-helper"; +import { setProxyBase } from "@ecency/render-helper"; import "./_index.scss"; import { Entry } from "@/entities"; import i18next from "i18next"; -import { useGlobalStore } from "@/core/global-store"; -import { dateToFullRelative, makeEntryPath } from "@/utils"; -import Image from "next/image"; import { getSimilarEntriesQuery } from "@/api/queries/get-similar-entries-query"; -import { useRouter } from "next/navigation"; -import { motion } from "framer-motion"; -import { EntryLink } from "@/features/shared"; +import { SimilarEntryItem } from "@/app/(dynamicPages)/entry/[category]/[author]/[permlink]/_components/similar-entries/similar-entry-item"; setProxyBase(defaults.imageServer); @@ -22,9 +17,6 @@ interface Props { } export function SimilarEntries({ entry }: Props) { - const canUseWebp = useGlobalStore((s) => s.canUseWebp); - - const router = useRouter(); const { data: entries } = getSimilarEntriesQuery(entry).useClientQuery(); return entries?.length === 3 ? ( @@ -33,38 +25,7 @@ export function SimilarEntries({ entry }: Props) {
{i18next.t("similar-entries.title")}
- {entries?.map((en, i) => ( - - - {en.title} -
{en.title}
-
- {en.author} - {dateToFullRelative(en.created_at)} -
-
-
- ))} + {entries?.map((en, i) => )}
) : ( diff --git a/src/app/(dynamicPages)/entry/[category]/[author]/[permlink]/_components/similar-entries/similar-entry-item.tsx b/src/app/(dynamicPages)/entry/[category]/[author]/[permlink]/_components/similar-entries/similar-entry-item.tsx new file mode 100644 index 000000000..263e18c64 --- /dev/null +++ b/src/app/(dynamicPages)/entry/[category]/[author]/[permlink]/_components/similar-entries/similar-entry-item.tsx @@ -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 ( + + + {postImage && ( + {entry.title} + )} + {!postImage && ( +
+ {entry.title} +
+ )} +
{entry.title}
+
+ {entry.author} + {dateToFullRelative(entry.created_at)} +
+
+
+ ); +}