fix: restore gallery grid selection UI and enable starting selection

This commit is contained in:
Varun committed 2026-04-23 14:48:06 +05:30
1 parent 04edb99217
commit 23333c51d5
4 files changed
+42 -9

No files matched your search

+3 -1
View File
@@ -121,7 +121,7 @@ const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal
const handleClick = (index: number, asset: AssetPhoto, event: React.MouseEvent) => {
if (selectedIds.length > 0) {
if (selectable && (event.metaKey || event.ctrlKey || selectedIds.length > 0)) {
handleSelect(index, asset, event);
} else {
setIndex(index);
@@ -214,6 +214,8 @@ const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal
photo={context.photo}
width={context.width}
height={context.height}
selectable={selectable}
onSelect={(event) => handleSelect(context.index, context.photo, event)}
/>
);
};
@@ -113,12 +113,12 @@ const ResponsiveVirtualizedAssetGrid = forwardRef<ResponsiveVirtualizedAssetGrid
}, [assets]);
const handleClick = useCallback((index: number, asset: IAsset, event: React.MouseEvent<HTMLElement>) => {
if (selectedIds.length > 0) {
if (selectable && (event.metaKey || event.ctrlKey || selectedIds.length > 0)) {
handleSelect(index, asset, event);
} else {
setIndex(index);
}
}, [selectedIds]);
}, [selectedIds, selectable, handleSelect]);
const handleSelect = useCallback((_idx: number, asset: IAsset, event: React.MouseEvent<HTMLElement>) => {
event.stopPropagation();
@@ -200,11 +200,15 @@ const ResponsiveVirtualizedAssetGrid = forwardRef<ResponsiveVirtualizedAssetGrid
)}
{selectable && (
<div
className={`absolute top-2 left-2 w-4 h-4 rounded-full border-2 ${
className={`absolute top-2 left-2 w-4 h-4 rounded-full border-2 cursor-pointer z-10 ${
isSelected
? 'bg-blue-500 border-blue-500'
: 'bg-white/80 border-gray-300'
}`}
onClick={(e) => {
e.stopPropagation();
handleSelect(assetIndex, asset, e);
}}
/>
)}
</div>
@@ -77,12 +77,12 @@ const VirtualizedAssetGrid = forwardRef<VirtualizedAssetGridRef, VirtualizedAsse
}, [assets]);
const handleClick = useCallback((index: number, asset: IAsset, event: React.MouseEvent<HTMLElement>) => {
if (selectedIds.length > 0) {
if (selectable && (event.metaKey || event.ctrlKey || selectedIds.length > 0)) {
handleSelect(index, asset, event);
} else {
setIndex(index);
}
}, [selectedIds]);
}, [selectedIds, selectable, handleSelect]);
const handleSelect = useCallback((_idx: number, asset: IAsset, event: React.MouseEvent<HTMLElement>) => {
event.stopPropagation();
@@ -166,11 +166,15 @@ const VirtualizedAssetGrid = forwardRef<VirtualizedAssetGridRef, VirtualizedAsse
)}
{selectable && (
<div
className={`absolute top-2 left-2 w-4 h-4 rounded-full border-2 ${
className={`absolute top-2 left-2 w-4 h-4 rounded-full border-2 cursor-pointer z-10 ${
isSelected
? 'bg-blue-500 border-blue-500'
: 'bg-white/80 border-gray-300'
}`}
onClick={(e) => {
e.stopPropagation();
handleSelect(assetIndex, asset, e);
}}
/>
)}
</div>
+25 -2
View File
@@ -1,6 +1,7 @@
/* eslint-disable @next/next/no-img-element */
import { humanizeDuration } from '@/helpers/string.helper'
import { PlayIcon } from '@radix-ui/react-icons'
import { CircleCheck } from 'lucide-react'
import React, { useEffect } from 'react'
import type { RenderImageProps } from 'react-photo-album'
import type { AssetPhoto } from '../shared/AssetGrid'
@@ -10,9 +11,11 @@ interface LazyGridImageProps {
photo: AssetPhoto;
width: number;
height: number;
selectable?: boolean;
onSelect?: (event: React.MouseEvent) => void;
}
export default function LazyGridImage({ imageProps, photo, width, height }: LazyGridImageProps) {
export default function LazyGridImage({ imageProps, photo, width, height, selectable, onSelect }: LazyGridImageProps) {
const [isVisible, setIsVisible] = React.useState(false)
const imageRef = React.useRef<HTMLDivElement>(null)
@@ -45,12 +48,32 @@ export default function LazyGridImage({ imageProps, photo, width, height }: Lazy
)
return (
<div style={{ position: 'relative', width, height }}>
<div
style={{
position: 'relative',
width,
height,
}}
className={`group ${photo.isSelected ? 'ring-4 ring-blue-500 ring-inset' : ''}`}
>
<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" />
{!!photo.duration && <span className="text-xs text-white">{humanizeDuration(photo.duration)}</span>}
</div>}
{selectable && (
<div
className={`absolute top-2 left-2 z-10 cursor-pointer transition-opacity ${photo.isSelected ? 'opacity-100' : 'opacity-0 group-hover:opacity-100'}`}
onClick={(e) => {
e.stopPropagation();
onSelect?.(e);
}}
>
<div className={`rounded-full p-0.5 ${photo.isSelected ? 'bg-blue-500 text-white' : 'bg-black/20 text-white/50'}`}>
<CircleCheck className="w-5 h-5" />
</div>
</div>
)}
</div>
)
}