fix: replace react-grid-gallery with react-photo-album for React 19 compatibility
This commit is contained in:
1 parent
4f7e770cf3
commit
6569aa4427
3 files changed
+47
-25
No files matched your search
+1
-1
@@ -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",
|
||||
|
||||
@@ -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<AssetGridRef, AssetGridProps>(({ assets, isInternal
|
||||
}), [assets, selectedIds, updateContext]);
|
||||
|
||||
|
||||
const handleClick = (index: number, asset: IAsset, event: React.MouseEvent<HTMLElement>) => {
|
||||
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<AssetGridRef, AssetGridProps>(({ assets, isInternal
|
||||
}
|
||||
}
|
||||
|
||||
const handleSelect = (_idx: number, asset: IAsset, event: React.MouseEvent<HTMLElement>) => {
|
||||
const handleSelect = (_idx: number, asset: AssetPhoto, event: React.MouseEvent) => {
|
||||
|
||||
event.stopPropagation();
|
||||
const isPresent = selectedIds.includes(asset.id);
|
||||
@@ -103,16 +111,17 @@ const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ 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<AssetGridRef, AssetGridProps>(({ assets, isInternal
|
||||
return () => window.removeEventListener("keydown", handleEsc);
|
||||
}, [images]);
|
||||
|
||||
const renderImage = (props: RenderImageProps, context: RenderImageContext<AssetPhoto>) => {
|
||||
return (
|
||||
<LazyGridImage
|
||||
imageProps={props}
|
||||
photo={context.photo}
|
||||
width={context.width}
|
||||
height={context.height}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Lightbox
|
||||
@@ -148,12 +168,11 @@ const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal
|
||||
index={index}
|
||||
close={() => setIndex(-1)}
|
||||
/>
|
||||
<Gallery
|
||||
images={images}
|
||||
onClick={handleClick}
|
||||
enableImageSelection={selectable}
|
||||
thumbnailImageComponent={LazyGridImage}
|
||||
onSelect={handleSelect}
|
||||
<RowsPhotoAlbum
|
||||
photos={images}
|
||||
targetRowHeight={150}
|
||||
onClick={({ index, event, photo }) => handleClick(index, photo, event)}
|
||||
render={{ image: renderImage }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -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<ImageExtended<Image & { isVideo?: boolean, duration?: string }>> {}
|
||||
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<HTMLImageElement>(null)
|
||||
const imageRef = React.useRef<HTMLDivElement>(null)
|
||||
|
||||
const setupObserver = () => {
|
||||
const observer = new IntersectionObserver((entries) => {
|
||||
@@ -38,15 +41,15 @@ export default function LazyGridImage(
|
||||
}, [])
|
||||
|
||||
if (!isVisible) return (
|
||||
<div style={{ height: props.height }} ref={imageRef} />
|
||||
<div style={{ height, width }} ref={imageRef} />
|
||||
)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<img {...props.imageProps} alt={props.imageProps.alt || ""} title="" />
|
||||
{props.item.isVideo && <div className="absolute bottom-2 right-2 bg-black/50 p-1 rounded-full flex items-center gap-1">
|
||||
<div style={{ position: 'relative', width, height }}>
|
||||
<img {...imageProps} alt={imageProps.alt || ""} title="" style={{ ...imageProps.style, width, height, objectFit: 'cover' }} />
|
||||
{photo.isVideo && <div className="absolute bottom-2 right-2 bg-black/50 p-1 rounded-full flex items-center gap-1">
|
||||
<PlayIcon className="w-3 h-3 text-white" />
|
||||
{!!props.item.duration && <span className="text-xs text-white">{humanizeDuration(props.item.duration)}</span>}
|
||||
{!!photo.duration && <span className="text-xs text-white">{humanizeDuration(photo.duration)}</span>}
|
||||
</div>}
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user