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,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>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user