feat: added orphan assets and new info panel for the asset dialog

Signed-off-by: Varun <varun@skcript.com>
This commit is contained in:
Varun committed 2026-04-06 19:55:38 +05:30
1 parent 11e88526c7
commit a2916b6ee7
10 files changed
+1437 -5

No files matched your search

+96 -3
View File
@@ -1,7 +1,7 @@
import "yet-another-react-lightbox/styles.css";
import { IAsset } from '@/types/asset';
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useState } from 'react'
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useState, useCallback } from 'react'
import Lightbox from 'yet-another-react-lightbox';
import { Gallery } from "react-grid-gallery";
import LazyGridImage from "../ui/lazy-grid-image";
@@ -9,6 +9,10 @@ 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';
import dynamic from 'next/dynamic';
import { Heart, Info, Trash2, ExternalLink } from 'lucide-react';
const AssetInfoPanel = dynamic(() => import('@/components/asset-info/AssetInfoPanel'), { ssr: false });
interface AssetGridProps {
@@ -16,6 +20,8 @@ interface AssetGridProps {
isInternal?: boolean;
selectable?: boolean;
onSelectionChange?: (ids: string[]) => void;
onDeleteAsset?: (id: string) => void;
onFavoriteAsset?: (id: string, isFavorite: boolean) => void;
}
interface AssetGridRef {
@@ -24,13 +30,16 @@ interface AssetGridRef {
unselectAll: () => void;
}
const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal = true, selectable = false, onSelectionChange }, ref) => {
const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal = true, selectable = false, onSelectionChange, onDeleteAsset, onFavoriteAsset }, ref) => {
const [index, setIndex] = useState(-1);
const [lastSelectedIndex, setLastSelectedIndex] = useState(-1);
const [showInfoPanel, setShowInfoPanel] = useState(false);
const { exImmichUrl } = useConfig();
// Use context for selection state
const { selectedIds, updateContext } = usePhotoSelectionContext();
const currentAsset = index >= 0 && index < assets.length ? assets[index] : null;
useImperativeHandle(ref, () => ({
getSelectedIds: () => selectedIds,
selectAll: () => {
@@ -139,6 +148,61 @@ const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal
return () => window.removeEventListener("keydown", handleEsc);
}, [images]);
const handleOpenInImmich = useCallback(() => {
if (currentAsset) {
window.open(exImmichUrl + "/photos/" + currentAsset.id, "_blank");
}
}, [currentAsset, exImmichUrl]);
const toolbarButtons = useMemo(() => {
if (!currentAsset) return [];
return [
<button
key="favorite"
type="button"
className="yarl__button"
title={currentAsset.isFavorite ? "Unfavorite" : "Favorite"}
onClick={() => onFavoriteAsset?.(currentAsset.id, !currentAsset.isFavorite)}
>
<Heart
className={`h-6 w-6 ${currentAsset.isFavorite ? 'fill-red-500 text-red-500' : 'text-white'}`}
/>
</button>,
<button
key="info"
type="button"
className="yarl__button"
title="Info"
onClick={() => setShowInfoPanel((v) => !v)}
>
<Info className={`h-6 w-6 ${showInfoPanel ? 'text-blue-400' : 'text-white'}`} />
</button>,
<button
key="open-immich"
type="button"
className="yarl__button"
title="Open in Immich"
onClick={handleOpenInImmich}
>
<ExternalLink className="h-6 w-6 text-white" />
</button>,
...(onDeleteAsset ? [
<button
key="delete"
type="button"
className="yarl__button"
title="Delete"
onClick={() => {
onDeleteAsset(currentAsset.id);
setIndex(-1);
}}
>
<Trash2 className="h-6 w-6 text-white" />
</button>,
] : []),
];
}, [currentAsset, showInfoPanel, onDeleteAsset, onFavoriteAsset, handleOpenInImmich]);
return (
<div>
<Lightbox
@@ -146,7 +210,36 @@ const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal
plugins={[Download, Video]}
open={index >= 0}
index={index}
close={() => setIndex(-1)}
close={() => { setIndex(-1); setShowInfoPanel(false); }}
on={{
view: ({ index }) => setIndex(index),
}}
toolbar={{
buttons: [
...toolbarButtons,
"download",
"close",
],
}}
render={{
slideContainer: ({ children }) => (
<div className="flex h-full w-full">
<div className="flex-1 flex items-center justify-center overflow-hidden">
{children}
</div>
{showInfoPanel && currentAsset && (
<AssetInfoPanel
assetId={currentAsset.id}
/>
)}
</div>
),
}}
styles={{
container: {
backgroundColor: "rgba(0, 0, 0, 0.95)",
},
}}
/>
<Gallery
images={images}