From af5a7dd2f9fc51eb6a6710e286866633aff5edbd Mon Sep 17 00:00:00 2001 From: saurav Date: Tue, 15 Oct 2024 21:42:44 +0600 Subject: [PATCH 1/4] Make the thumbnail image keeping its ratio like pinterest layout for masonry --- .../bookmarks/BookmarkLayoutAdaptingCard.tsx | 7 ++-- .../dashboard/bookmarks/FixedRatioImage.tsx | 36 +++++++++++++++++++ .../dashboard/bookmarks/LinkCard.tsx | 7 +++- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 apps/web/components/dashboard/bookmarks/FixedRatioImage.tsx diff --git a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx index 1df0c197..10adc148 100644 --- a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx +++ b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx @@ -155,18 +155,19 @@ function GridView({ layout, fitHeight = false, }: Props & { layout: BookmarksLayoutTypes }) { - const img = image("grid", "h-56 min-h-56 w-full object-cover rounded-t-lg"); + const img = image("grid", "w-full rounded-t-lg"); return (
- {img &&
{img}
} + {/* {img &&
{img}
} */} + {img &&
{img}
}
{title && ( diff --git a/apps/web/components/dashboard/bookmarks/FixedRatioImage.tsx b/apps/web/components/dashboard/bookmarks/FixedRatioImage.tsx new file mode 100644 index 00000000..e9ea6169 --- /dev/null +++ b/apps/web/components/dashboard/bookmarks/FixedRatioImage.tsx @@ -0,0 +1,36 @@ +import { useState } from "react"; +import Image from "next/image"; + +export default function FixedRatioImage({ + src, + unoptimized, + className, +}: { + src: string; + unoptimized: boolean; + className: string | undefined; +}) { + const [height, setHeight] = useState(0); + const [width, setWidth] = useState(0); + + if (height === null) return
; + + const onImgLoad = ({ target }: React.SyntheticEvent) => { + const img = target as HTMLImageElement; + setHeight(img.offsetHeight); + setWidth(img.offsetWidth); + }; + + return ( + card banner + ); +} diff --git a/apps/web/components/dashboard/bookmarks/LinkCard.tsx b/apps/web/components/dashboard/bookmarks/LinkCard.tsx index 86eed9e7..d3321178 100644 --- a/apps/web/components/dashboard/bookmarks/LinkCard.tsx +++ b/apps/web/components/dashboard/bookmarks/LinkCard.tsx @@ -11,6 +11,7 @@ import { } from "@hoarder/shared-react/utils/bookmarkUtils"; import { BookmarkLayoutAdaptingCard } from "./BookmarkLayoutAdaptingCard"; +import FixedRatioImage from "./FixedRatioImage"; import FooterLinkURL from "./FooterLinkURL"; function LinkTitle({ bookmark }: { bookmark: ZBookmarkTypeLink }) { @@ -48,7 +49,11 @@ function LinkImage({ if (isBookmarkStillCrawling(bookmark)) { img = imgComponent("/blur.avif", false); } else if (imageDetails) { - img = imgComponent(imageDetails.url, !imageDetails.localAsset); + img = FixedRatioImage({ + src: imageDetails.url, + unoptimized: !imageDetails.localAsset, + className: className, + }); } else { // No image found // A dummy white pixel for when there's no image. From f93395003a9be3fb294a8e45dab3246a717eeb10 Mon Sep 17 00:00:00 2001 From: saurav Date: Sat, 19 Oct 2024 21:25:15 +0600 Subject: [PATCH 2/4] added max-h-screen for a max image height --- .../dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx index 10adc148..b701ffd9 100644 --- a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx +++ b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx @@ -155,7 +155,7 @@ function GridView({ layout, fitHeight = false, }: Props & { layout: BookmarksLayoutTypes }) { - const img = image("grid", "w-full rounded-t-lg"); + const img = image("grid", "w-full object-cover max-h-screen rounded-t-lg"); return (
Date: Sun, 20 Oct 2024 03:49:23 +0600 Subject: [PATCH 3/4] added max-h-screen for a max image height for both linkcard and asset image --- apps/web/components/dashboard/bookmarks/AssetCard.tsx | 10 +++++----- .../components/dashboard/bookmarks/FixedRatioImage.tsx | 8 ++++++-- apps/web/components/dashboard/bookmarks/LinkCard.tsx | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/web/components/dashboard/bookmarks/AssetCard.tsx b/apps/web/components/dashboard/bookmarks/AssetCard.tsx index 61b3bc8d..dda67ac3 100644 --- a/apps/web/components/dashboard/bookmarks/AssetCard.tsx +++ b/apps/web/components/dashboard/bookmarks/AssetCard.tsx @@ -1,6 +1,5 @@ "use client"; -import Image from "next/image"; import Link from "next/link"; import type { ZBookmarkTypeAsset } from "@hoarder/shared/types/bookmarks"; @@ -8,6 +7,7 @@ import { getAssetUrl } from "@hoarder/shared-react/utils/assetUtils"; import { getSourceUrl } from "@hoarder/shared-react/utils/bookmarkUtils"; import { BookmarkLayoutAdaptingCard } from "./BookmarkLayoutAdaptingCard"; +import FixedRatioImage from "./FixedRatioImage"; import FooterLinkURL from "./FooterLinkURL"; function AssetImage({ @@ -22,11 +22,11 @@ function AssetImage({ case "image": { return ( - asset ); diff --git a/apps/web/components/dashboard/bookmarks/FixedRatioImage.tsx b/apps/web/components/dashboard/bookmarks/FixedRatioImage.tsx index e9ea6169..b888f9ac 100644 --- a/apps/web/components/dashboard/bookmarks/FixedRatioImage.tsx +++ b/apps/web/components/dashboard/bookmarks/FixedRatioImage.tsx @@ -1,3 +1,5 @@ +"use client"; + import { useState } from "react"; import Image from "next/image"; @@ -5,10 +7,12 @@ export default function FixedRatioImage({ src, unoptimized, className, + alt, }: { src: string; unoptimized: boolean; className: string | undefined; + alt: string; }) { const [height, setHeight] = useState(0); const [width, setWidth] = useState(0); @@ -28,8 +32,8 @@ export default function FixedRatioImage({ height={height} unoptimized={unoptimized} className={className} - alt="card banner" - // fill={true} + alt={alt} + fill={false} src={src} /> ); diff --git a/apps/web/components/dashboard/bookmarks/LinkCard.tsx b/apps/web/components/dashboard/bookmarks/LinkCard.tsx index d3321178..5512eae9 100644 --- a/apps/web/components/dashboard/bookmarks/LinkCard.tsx +++ b/apps/web/components/dashboard/bookmarks/LinkCard.tsx @@ -53,6 +53,7 @@ function LinkImage({ src: imageDetails.url, unoptimized: !imageDetails.localAsset, className: className, + alt: "card banner", }); } else { // No image found From 3878c818697dcd03cd10711f420ea8f0f7605c1d Mon Sep 17 00:00:00 2001 From: saurav Date: Sun, 20 Oct 2024 04:03:01 +0600 Subject: [PATCH 4/4] set asset image as optimized --- apps/web/components/dashboard/bookmarks/AssetCard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/components/dashboard/bookmarks/AssetCard.tsx b/apps/web/components/dashboard/bookmarks/AssetCard.tsx index dda67ac3..5e6788b5 100644 --- a/apps/web/components/dashboard/bookmarks/AssetCard.tsx +++ b/apps/web/components/dashboard/bookmarks/AssetCard.tsx @@ -24,7 +24,7 @@ function AssetImage({