From 6569aa44275c67e74970e383f1673e6df0eca39d Mon Sep 17 00:00:00 2001 From: sai80082 Date: Tue, 7 Apr 2026 00:12:03 +0530 Subject: [PATCH] fix: replace react-grid-gallery with react-photo-album for React 19 compatibility --- package.json | 2 +- src/components/shared/AssetGrid.tsx | 43 +++++++++++++++++++-------- src/components/ui/lazy-grid-image.tsx | 27 +++++++++-------- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index e049bb8..f61a434 100644 --- a/package.json +++ b/package.json @@ -72,10 +72,10 @@ "react-autosuggest": "^10.1.0", "react-day-picker": "9.0.8", "react-dom": "19.2.4", - "react-grid-gallery": "^1.0.1", "react-hot-toast": "^2.6.0", "react-leaflet": "^4.2.1", "react-mentions": "^4.4.10", + "react-photo-album": "^3.5.1", "react-window": "^1.8.11", "recharts": "^2.15.4", "remotion": "4.0.232", diff --git a/src/components/shared/AssetGrid.tsx b/src/components/shared/AssetGrid.tsx index 473e5be..f5c4c8d 100644 --- a/src/components/shared/AssetGrid.tsx +++ b/src/components/shared/AssetGrid.tsx @@ -1,15 +1,23 @@ import "yet-another-react-lightbox/styles.css"; +import "react-photo-album/rows.css"; import { IAsset } from '@/types/asset'; import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useState } from 'react' import Lightbox from 'yet-another-react-lightbox'; -import { Gallery } from "react-grid-gallery"; +import { RowsPhotoAlbum } from "react-photo-album"; +import type { Photo, RenderImageContext, RenderImageProps } from "react-photo-album"; import LazyGridImage from "../ui/lazy-grid-image"; import Download from "yet-another-react-lightbox/plugins/download"; import Video from "yet-another-react-lightbox/plugins/video"; import { usePhotoSelectionContext } from '@/contexts/PhotoSelectionContext'; import { useConfig } from '@/contexts/ConfigContext'; +export interface AssetPhoto extends Photo { + id: string; + isVideo: boolean; + duration?: string; + isSelected: boolean; +} interface AssetGridProps { assets: IAsset[]; @@ -45,7 +53,7 @@ const AssetGrid = forwardRef(({ assets, isInternal }), [assets, selectedIds, updateContext]); - const handleClick = (index: number, asset: IAsset, event: React.MouseEvent) => { + const handleClick = (index: number, asset: AssetPhoto, event: React.MouseEvent) => { if (selectedIds.length > 0) { handleSelect(index, asset, event); } else { @@ -53,7 +61,7 @@ const AssetGrid = forwardRef(({ assets, isInternal } } - const handleSelect = (_idx: number, asset: IAsset, event: React.MouseEvent) => { + const handleSelect = (_idx: number, asset: AssetPhoto, event: React.MouseEvent) => { event.stopPropagation(); const isPresent = selectedIds.includes(asset.id); @@ -103,16 +111,17 @@ const AssetGrid = forwardRef(({ assets, isInternal })); }, [assets]); - const images = useMemo(() => { + const images: AssetPhoto[] = useMemo(() => { return assets.map((p) => ({ ...p, src: p.url as string, original: p.previewUrl as string, - width: p.exifImageWidth / 10 as number, - height: p.exifImageHeight / 10 as number, + width: p.exifImageWidth as number, + height: p.exifImageHeight as number, orientation: 1, isSelected: selectedIds.includes(p.id), isVideo: p.type === "VIDEO", + duration: p.duration != null ? String(p.duration) : undefined, tags: [ { title: "Immich Link", @@ -139,6 +148,17 @@ const AssetGrid = forwardRef(({ assets, isInternal return () => window.removeEventListener("keydown", handleEsc); }, [images]); + const renderImage = (props: RenderImageProps, context: RenderImageContext) => { + return ( + + ); + }; + return (
(({ assets, isInternal index={index} close={() => setIndex(-1)} /> - handleClick(index, photo, event)} + render={{ image: renderImage }} />
); diff --git a/src/components/ui/lazy-grid-image.tsx b/src/components/ui/lazy-grid-image.tsx index f32ad5c..015fc33 100644 --- a/src/components/ui/lazy-grid-image.tsx +++ b/src/components/ui/lazy-grid-image.tsx @@ -2,16 +2,19 @@ import { humanizeDuration } from '@/helpers/string.helper' import { PlayIcon } from '@radix-ui/react-icons' import React, { useEffect } from 'react' -import { Image, ImageExtended, ThumbnailImageProps } from 'react-grid-gallery' +import type { RenderImageProps } from 'react-photo-album' +import type { AssetPhoto } from '../shared/AssetGrid' -interface LazyImageProps extends ThumbnailImageProps> {} +interface LazyGridImageProps { + imageProps: RenderImageProps; + photo: AssetPhoto; + width: number; + height: number; +} - -export default function LazyGridImage( - props: LazyImageProps -) { +export default function LazyGridImage({ imageProps, photo, width, height }: LazyGridImageProps) { const [isVisible, setIsVisible] = React.useState(false) - const imageRef = React.useRef(null) + const imageRef = React.useRef(null) const setupObserver = () => { const observer = new IntersectionObserver((entries) => { @@ -38,15 +41,15 @@ export default function LazyGridImage( }, []) if (!isVisible) return ( -
+
) return ( -
- {props.imageProps.alt - {props.item.isVideo &&
+
+ {imageProps.alt + {photo.isVideo &&
- {!!props.item.duration && {humanizeDuration(props.item.duration)}} + {!!photo.duration && {humanizeDuration(photo.duration)}}
}
)