diff --git a/src/components/Img.tsx b/src/components/Img.tsx index a4f8272..3aa7602 100644 --- a/src/components/Img.tsx +++ b/src/components/Img.tsx @@ -1,47 +1,40 @@ -import { ImageProps } from "next/image"; -import { MouseEventHandler } from "react"; +import { DetailedHTMLProps, ImgHTMLAttributes } from "react"; import { UploadImageFragment } from "graphql/generated"; -import { getAssetURL, getImgSizesByQuality, ImageQuality } from "helpers/img"; +import { getAssetURL, ImageQuality } from "helpers/img"; /* * ╭─────────────╮ * ────────────────────────────────────────╯ CONSTANTS ╰────────────────────────────────────────── */ -interface Props { - className?: string; - image?: UploadImageFragment | string; +interface Props + extends Omit< + DetailedHTMLProps, HTMLImageElement>, + "src" + > { + src: UploadImageFragment | string; quality?: ImageQuality; - alt?: ImageProps["alt"]; - onClick?: MouseEventHandler; } // ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ export const Img = ({ className, - image, + src: rawSrc, quality = ImageQuality.Small, alt, - onClick, + loading = "lazy", + ...otherProps }: Props): JSX.Element => { - if (typeof image === "string") { - return ( - {alt - ); - } else if (image?.width && image.height) { - const imgSize = getImgSizesByQuality(image.width, image.height, quality); - return ( - {alt - ); - } - return <>; + const src = + typeof rawSrc === "string" ? rawSrc : getAssetURL(rawSrc.url, quality); + return ( + {alt} + ); }; diff --git a/src/components/Library/ScanSet.tsx b/src/components/Library/ScanSet.tsx index 5856ef4..b2cd04a 100644 --- a/src/components/Library/ScanSet.tsx +++ b/src/components/Library/ScanSet.tsx @@ -235,7 +235,7 @@ export const ScanSet = ({ openLightBox(images, index); }} > - + ))} diff --git a/src/components/Library/ScanSetCover.tsx b/src/components/Library/ScanSetCover.tsx index 1cef0ae..3586eff 100644 --- a/src/components/Library/ScanSetCover.tsx +++ b/src/components/Library/ScanSetCover.tsx @@ -180,7 +180,7 @@ export const ScanSetCover = ({ openLightBox(imgs, index); }} > - + ))} diff --git a/src/components/LightBox.tsx b/src/components/LightBox.tsx index 82c4bbb..f020f5f 100644 --- a/src/components/LightBox.tsx +++ b/src/components/LightBox.tsx @@ -90,7 +90,7 @@ export const LightBox = ({
diff --git a/src/components/Markdown/Markdawn.tsx b/src/components/Markdown/Markdawn.tsx index 7426fbc..1473993 100644 --- a/src/components/Markdown/Markdawn.tsx +++ b/src/components/Markdown/Markdawn.tsx @@ -284,7 +284,7 @@ export const Markdawn = ({ }} > )} @@ -164,7 +164,7 @@ export const PreviewCard = ({ {thumbnail && ( )} @@ -193,7 +193,7 @@ export const PreviewCard = ({ ), cIf(thumbnailForceAspectRatio, "h-full w-full object-cover") )} - image={thumbnail} + src={thumbnail} quality={ImageQuality.Medium} /> {stackNumber > 0 && ( diff --git a/src/components/PreviewLine.tsx b/src/components/PreviewLine.tsx index b909d78..407a27d 100644 --- a/src/components/PreviewLine.tsx +++ b/src/components/PreviewLine.tsx @@ -41,7 +41,7 @@ export const PreviewLine = ({
diff --git a/src/components/RecorderChip.tsx b/src/components/RecorderChip.tsx index 3ed1aae..608799e 100644 --- a/src/components/RecorderChip.tsx +++ b/src/components/RecorderChip.tsx @@ -29,7 +29,7 @@ export const RecorderChip = ({ recorder, langui }: Props): JSX.Element => ( {recorder.avatar?.data?.attributes && ( )} diff --git a/src/components/ThumbnailHeader.tsx b/src/components/ThumbnailHeader.tsx index 93dbd17..b7d259a 100644 --- a/src/components/ThumbnailHeader.tsx +++ b/src/components/ThumbnailHeader.tsx @@ -53,7 +53,7 @@ export const ThumbnailHeader = ({ {thumbnail ? ( { openLightBox([getAssetURL(thumbnail.url, ImageQuality.Large)]); diff --git a/src/helpers/numbers.ts b/src/helpers/numbers.ts index 740bf0b..7474bc5 100644 --- a/src/helpers/numbers.ts +++ b/src/helpers/numbers.ts @@ -24,3 +24,13 @@ export const randomInt = (min: number, max: number): number => export const isInteger = (value: string): boolean => /^[+-]?[0-9]+$/u.test(value); + +export const clamp = ( + value: number, + minValue: number, + maxValue: number +): number => { + if (value > maxValue) return maxValue; + if (value < minValue) return minValue; + return value; +}; diff --git a/src/pages/library/[slug]/index.tsx b/src/pages/library/[slug]/index.tsx index 58e6fd7..906ec4b 100644 --- a/src/pages/library/[slug]/index.tsx +++ b/src/pages/library/[slug]/index.tsx @@ -172,7 +172,7 @@ const LibrarySlug = ({ > {item.thumbnail?.data?.attributes ? ( @@ -273,7 +273,7 @@ const LibrarySlug = ({
diff --git a/src/pages/wiki/[slug]/index.tsx b/src/pages/wiki/[slug]/index.tsx index 6991479..1419919 100644 --- a/src/pages/wiki/[slug]/index.tsx +++ b/src/pages/wiki/[slug]/index.tsx @@ -112,7 +112,7 @@ const WikiPage = ({ > {page.thumbnail?.data?.attributes && ( {