import type { Selection } from './useSelection'; import { useState } from 'react'; import { Archive, ArchiveRestore, Heart, Plus, Share2, Trash2, Undo2, X } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { ShareLinkDialog } from './ShareLinkDialog'; import { useAlbums } from './usePhotosData'; import { useAssetActions } from './useAssetActions'; // The bar that replaces the header once anything is selected — Immich does the same, and it keeps the // destructive buttons off screen entirely until they have something to act on. type SelectionBarProps = { selection: Selection; /** Trash swaps the whole action set: restore and delete-forever, not favorite and archive. */ inTrash?: boolean; /** When viewing one album, offer "remove from album" alongside the library-wide actions. */ albumId?: string; /** Currently in the archive view, so the archive button should read "unarchive". */ archived?: boolean; }; export const SelectionBar = ({ selection, inTrash = false, albumId, archived = false }: SelectionBarProps) => { const { ids, count, clear, selectAll } = selection; const { setFavorite, setArchived, trash, restore, deleteForever, addToAlbum, removeFromAlbum, createAlbum } = useAssetActions(); const { data: albums } = useAlbums(); /* The ids are captured when Share is pressed rather than read live, so the dialog keeps acting on what was selected even if the selection changes behind it. Selection is deliberately NOT cleared: a link is usually made to send, and losing the selection makes a second link over the same photos a re-selection job. */ const [sharing, setSharing] = useState(null); const run = (action: () => void) => { action(); clear(); }; return (
{count} selected
{inTrash ? ( <> ) : ( <> { const albumName = window.prompt('New album name'); if (albumName) run(() => createAlbum.mutate({ albumName, assetIds: ids })); }} > New album {albums && albums.length > 0 && } {albums?.map((album) => ( run(() => addToAlbum.mutate({ albumId: album.id, ids }))} > {album.albumName} ))} {albumId && ( )} )} !next && setSharing(null)} target={sharing ? { kind: 'assets', assetIds: sharing } : null} />
); };