From 917f694db7b009a681423071afa89e7d03083e6e Mon Sep 17 00:00:00 2001 From: Varun Raj Date: Mon, 21 Jul 2025 09:40:27 +0530 Subject: [PATCH 1/7] refactor: enhance AlbumImages and AssetOffsetDialog components for improved asset management - Integrated PhotoSelectionContext into AlbumImages for better state management of selected assets. - Replaced local asset state with context-driven updates, allowing for seamless asset fetching and selection. - Added image gallery functionality using react-grid-gallery and yet-another-react-lightbox for enhanced user experience. - Updated AssetOffsetDialog to include timezone options for date adjustments, improving flexibility in asset date management. - Refactored UI elements for better layout and usability across both components. --- src/components/albums/info/AlbumImages.tsx | 142 ++++++++++--- .../assets-options/AssetOffsetDialog.tsx | 192 +++++++++++++++--- src/pages/albums/[albumId].tsx | 121 ++++++++++- 3 files changed, 384 insertions(+), 71 deletions(-) diff --git a/src/components/albums/info/AlbumImages.tsx b/src/components/albums/info/AlbumImages.tsx index 9240e0d..e789a83 100644 --- a/src/components/albums/info/AlbumImages.tsx +++ b/src/components/albums/info/AlbumImages.tsx @@ -3,14 +3,15 @@ import { listAlbumAssets } from "@/handlers/api/album.handler"; import { useConfig } from "@/contexts/ConfigContext"; import { IAlbum } from "@/types/album"; import { IAsset } from "@/types/asset"; -import React, { useEffect, useMemo, useRef, useState } from "react"; +import React, { useEffect, useMemo, useRef, useState, MouseEvent } from "react"; import { Hourglass } from "lucide-react"; import { useRouter } from "next/router"; import { Button } from "@/components/ui/button"; -import AssetGrid from "@/components/shared/AssetGrid"; -import PhotoSelectionContext, { - IPhotoSelectionContext, -} from "@/contexts/PhotoSelectionContext"; +import { Gallery } from "react-grid-gallery"; +import Lightbox from "yet-another-react-lightbox"; +import Captions from "yet-another-react-lightbox/plugins/captions"; +import LazyGridImage from "@/components/ui/lazy-grid-image"; +import { usePhotoSelectionContext } from "@/contexts/PhotoSelectionContext"; interface AlbumImagesProps { album: IAlbum; @@ -20,11 +21,15 @@ interface IAssetFilter { faceId?: string; page: number; } + export default function AlbumImages({ album }: AlbumImagesProps) { const { exImmichUrl } = useConfig(); const router = useRouter(); const { faceId } = router.query as { faceId: string }; - const [assets, setAssets] = useState([]); + + // Use context from parent instead of managing own + const { selectedIds, updateContext, assets } = usePhotoSelectionContext(); + const [loading, setLoading] = useState(false); const [errorMessage, setErrorMessage] = useState(null); const [filters, setFilters] = useState({ @@ -32,32 +37,17 @@ export default function AlbumImages({ album }: AlbumImagesProps) { page: 1, }); const [hasMore, setHasMore] = useState(true); - - // Initialize context state - const [contextState, setContextState] = useState({ - selectedIds: [], - assets: [], - config: {}, - updateContext: (newConfig: Partial) => { - setContextState((prevState) => ({ - ...prevState, - ...newConfig, - // No deep merge needed for config here as it's simple - config: newConfig.config - ? { ...prevState.config, ...newConfig.config } - : prevState.config, - })); - }, - }); + const [index, setIndex] = useState(-1); + const [lastSelectedIndex, setLastSelectedIndex] = useState(-1); const fetchAssets = async () => { setLoading(true); return listAlbumAssets(album.id, filters) .then((newAssets) => { if (filters.page === 1) { - setAssets(newAssets); + updateContext({ assets: newAssets }); } else { - setAssets((prevAssets) => [...prevAssets, ...newAssets]); + updateContext({ assets: [...assets, ...newAssets] }); } setHasMore(newAssets.length === 100); }) @@ -65,6 +55,76 @@ export default function AlbumImages({ album }: AlbumImagesProps) { .finally(() => setLoading(false)); }; + const images = useMemo(() => { + return assets.map((p) => ({ + ...p, + src: p.url as string, + original: p.previewUrl as string, + width: p.exifImageWidth as number, + height: p.exifImageHeight as number, + isSelected: selectedIds.includes(p.id), + orientation: 1, + tags: [ + { + title: "Immich Link", + value: ( + + Open in Immich + + ), + }, + ], + })); + }, [assets, selectedIds, exImmichUrl]); + + const slides = useMemo( + () => + images.map(({ original, width, height }) => ({ + src: original, + width, + height, + })), + [images] + ); + + const handleClick = (idx: number, asset: IAsset, event: MouseEvent) => { + if (selectedIds.length > 0) { + handleSelect(idx, asset, event); + } else { + setIndex(idx); + } + }; + + const handleSelect = (_idx: number, asset: IAsset, event: MouseEvent) => { + event.stopPropagation(); + const isPresent = selectedIds.includes(asset.id); + if (isPresent) { + updateContext({ + selectedIds: selectedIds.filter((id) => id !== asset.id), + }); + } else { + const clickedIndex = images.findIndex((image) => { + return image.id === asset.id; + }); + if (event.shiftKey && lastSelectedIndex !== -1) { + const startIndex = Math.min(clickedIndex, lastSelectedIndex); + const endIndex = Math.max(clickedIndex, lastSelectedIndex); + if (startIndex >= 0 && endIndex < images.length) { + const newSelectedIds = images.slice(startIndex, endIndex + 1).map((image) => image.id); + const allSelectedIds = [...selectedIds, ...newSelectedIds]; + const uniqueSelectedIds = [...new Set(allSelectedIds)]; + updateContext({ selectedIds: uniqueSelectedIds }); + } else { + console.warn("Shift-select index out of bounds"); + updateContext({ selectedIds: [...selectedIds, asset.id] }); + } + } else { + updateContext({ selectedIds: [...selectedIds, asset.id] }); + } + setLastSelectedIndex(clickedIndex); + } + }; + useEffect(() => { if (album.id) { fetchAssets(); @@ -76,7 +136,7 @@ export default function AlbumImages({ album }: AlbumImagesProps) { faceId, page: 1, }); - setAssets([]); + updateContext({ assets: [], selectedIds: [] }); setHasMore(true); }, [faceId]); @@ -97,11 +157,29 @@ export default function AlbumImages({ album }: AlbumImagesProps) { } return ( - -
- + <> + = 0} + index={index} + close={() => setIndex(-1)} + /> +
+ {hasMore && (
- + ); } diff --git a/src/components/assets/assets-options/AssetOffsetDialog.tsx b/src/components/assets/assets-options/AssetOffsetDialog.tsx index bc21585..60bcea6 100644 --- a/src/components/assets/assets-options/AssetOffsetDialog.tsx +++ b/src/components/assets/assets-options/AssetOffsetDialog.tsx @@ -4,6 +4,7 @@ import { Dialog, DialogTitle, DialogHeader, DialogContent, DialogTrigger } from import { Label } from '@/components/ui/label'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { formatDate, offsetDate } from '@/helpers/date.helper'; import Image from 'next/image'; import { updateAssets } from '@/handlers/api/asset.handler'; @@ -14,21 +15,132 @@ interface IProps { onComplete: () => void; } +// Comprehensive timezone options +const TIMEZONE_OPTIONS = [ + { value: 'none', label: 'No timezone change' }, + + // GMT -12 to -9 + { value: 'Pacific/Kwajalein', label: '(GMT -12:00) Eniwetok, Kwajalein' }, + { value: 'Pacific/Midway', label: '(GMT -11:00) Midway Island, Samoa' }, + { value: 'Pacific/Honolulu', label: '(GMT -10:00) Hawaii' }, + { value: 'Pacific/Marquesas', label: '(GMT -9:30) Taiohae' }, + { value: 'America/Anchorage', label: '(GMT -9:00) Alaska' }, + + // GMT -8 to -4 + { value: 'America/Los_Angeles', label: '(GMT -8:00) Pacific Time (US & Canada)' }, + { value: 'America/Denver', label: '(GMT -7:00) Mountain Time (US & Canada)' }, + { value: 'America/Chicago', label: '(GMT -6:00) Central Time (US & Canada), Mexico City' }, + { value: 'America/New_York', label: '(GMT -5:00) Eastern Time (US & Canada), Bogota, Lima' }, + { value: 'America/Caracas', label: '(GMT -4:30) Caracas' }, + { value: 'America/Halifax', label: '(GMT -4:00) Atlantic Time (Canada), La Paz' }, + + // GMT -3 to 0 + { value: 'America/St_Johns', label: '(GMT -3:30) Newfoundland' }, + { value: 'America/Sao_Paulo', label: '(GMT -3:00) Brazil, Buenos Aires, Georgetown' }, + { value: 'Atlantic/South_Georgia', label: '(GMT -2:00) Mid-Atlantic' }, + { value: 'Atlantic/Azores', label: '(GMT -1:00) Azores, Cape Verde Islands' }, + { value: 'UTC', label: '(GMT) UTC' }, + { value: 'Europe/London', label: '(GMT) Western Europe Time, London, Lisbon, Casablanca' }, + + // GMT +1 to +4 + { value: 'Europe/Paris', label: '(GMT +1:00) Brussels, Copenhagen, Madrid, Paris' }, + { value: 'Europe/Berlin', label: '(GMT +1:00) Berlin, Rome, Amsterdam' }, + { value: 'Africa/Cairo', label: '(GMT +2:00) Cairo, South Africa' }, + { value: 'Europe/Moscow', label: '(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg' }, + { value: 'Asia/Tehran', label: '(GMT +3:30) Tehran' }, + { value: 'Asia/Dubai', label: '(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi' }, + { value: 'Asia/Kabul', label: '(GMT +4:30) Kabul' }, + + // GMT +5 to +8 + { value: 'Asia/Karachi', label: '(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent' }, + { value: 'Asia/Kolkata', label: '(GMT +5:30) Bombay, Calcutta, Madras, New Delhi' }, + { value: 'Asia/Kathmandu', label: '(GMT +5:45) Kathmandu, Pokhara' }, + { value: 'Asia/Dhaka', label: '(GMT +6:00) Almaty, Dhaka, Colombo' }, + { value: 'Asia/Yangon', label: '(GMT +6:30) Yangon, Mandalay' }, + { value: 'Asia/Bangkok', label: '(GMT +7:00) Bangkok, Hanoi, Jakarta' }, + { value: 'Asia/Shanghai', label: '(GMT +8:00) Beijing, Perth, Singapore, Hong Kong' }, + { value: 'Australia/Eucla', label: '(GMT +8:45) Eucla' }, + + // GMT +9 to +12 + { value: 'Asia/Tokyo', label: '(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk' }, + { value: 'Australia/Adelaide', label: '(GMT +9:30) Adelaide, Darwin' }, + { value: 'Australia/Sydney', label: '(GMT +10:00) Eastern Australia, Guam, Vladivostok' }, + { value: 'Australia/Lord_Howe', label: '(GMT +10:30) Lord Howe Island' }, + { value: 'Pacific/Noumea', label: '(GMT +11:00) Magadan, Solomon Islands, New Caledonia' }, + { value: 'Pacific/Norfolk', label: '(GMT +11:30) Norfolk Island' }, + { value: 'Pacific/Auckland', label: '(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka' }, + { value: 'Pacific/Chatham', label: '(GMT +12:45) Chatham Islands' }, + + // GMT +13 to +14 + { value: 'Pacific/Apia', label: '(GMT +13:00) Apia, Nukualofa' }, + { value: 'Pacific/Kiritimati', label: '(GMT +14:00) Line Islands, Tokelau' }, +]; + +const offsetDateWithTimezone = ( + date: string, + offset: { + years: number, + days: number, + hours: number, + minutes: number, + seconds: number + }, + timezone?: string +): string => { + // First apply the standard offset + const offsettedDate = offsetDate(date, offset); + + // If no timezone specified or "none" selected, return the offset date + if (!timezone || timezone === 'none') { + return offsettedDate; + } + + // Convert timezone + try { + const parsedDate = new Date(offsettedDate); + + // Get the current timezone offset + const currentOffset = parsedDate.getTimezoneOffset(); + + // Get the target timezone offset + const targetDate = new Date(parsedDate.toLocaleString('en-US', { timeZone: timezone })); + const utcDate = new Date(parsedDate.toLocaleString('en-US', { timeZone: 'UTC' })); + const targetOffset = (utcDate.getTime() - targetDate.getTime()) / 60000; + + // Calculate the difference and apply it + const offsetDifference = targetOffset - currentOffset; + const finalDate = new Date(parsedDate.getTime() + (offsetDifference * 60000)); + + return finalDate.toISOString(); + } catch (error) { + console.warn('Timezone conversion failed, using offset date:', error); + return offsettedDate; + } +}; + export default function AssetOffsetDialog({ assets: _assets, onComplete }: IProps) { const { toast } = useToast(); const [open, setOpen] = useState(false); const [assets, setAssets] = useState(_assets); - const [offsetData, setOffsetData] = useState<{ days: number, hours: number, minutes: number, seconds: number, years: number }>({ + const [offsetData, setOffsetData] = useState<{ + days: number, + hours: number, + minutes: number, + seconds: number, + years: number, + timezone: string + }>({ days: 0, hours: 0, minutes: 0, seconds: 0, - years: 0 + years: 0, + timezone: 'none' }); const [loading, setLoading] = useState(false); const [assetStatus, setAssetStatus] = useState>({}); - const handleChange = (key: keyof typeof offsetData, value: number) => { + const handleChange = (key: keyof typeof offsetData, value: number | string) => { setOffsetData({ ...offsetData, [key]: value }); } @@ -39,7 +151,7 @@ export default function AssetOffsetDialog({ assets: _assets, onComplete }: IProp setAssetStatus({ [asset.id]: 'pending' }); await updateAssets({ ids: [asset.id], - dateTimeOriginal: offsetDate(asset.dateTimeOriginal, offsetData) + dateTimeOriginal: offsetDateWithTimezone(asset.dateTimeOriginal, offsetData, offsetData.timezone) }) .then(() => { setLoading(false); @@ -60,7 +172,6 @@ export default function AssetOffsetDialog({ assets: _assets, onComplete }: IProp }) } - useEffect(() => { setAssets(_assets); }, [_assets]); @@ -72,32 +183,53 @@ export default function AssetOffsetDialog({ assets: _assets, onComplete }: IProp Offset Dates - + Offset Asset Dates -
-
- - handleChange("years", parseInt(e.target.value))} /> + +
+
+ + handleChange("years", parseInt(e.target.value) || 0)} /> +
+
+ + handleChange("days", parseInt(e.target.value) || 0)} /> +
+
+ + handleChange("hours", parseInt(e.target.value) || 0)} /> +
+
+ + handleChange("minutes", parseInt(e.target.value) || 0)} /> +
-
- - handleChange("days", parseInt(e.target.value))} /> +
+
+ + handleChange("seconds", parseInt(e.target.value) || 0)} /> +
+
+ + +
+
+ +
-
- - handleChange("hours", parseInt(e.target.value))} /> -
-
- - handleChange("minutes", parseInt(e.target.value))} /> -
-
- - handleChange("seconds", parseInt(e.target.value))} /> -
-
{assets.map((asset) => ( @@ -106,7 +238,9 @@ export default function AssetOffsetDialog({ assets: _assets, onComplete }: IProp {assetStatus[asset.id] === 'pending' ?

Offsetting...

: ( -
{formatDate(offsetDate(asset.dateTimeOriginal, offsetData), 'PPpp')}
+
+ {formatDate(offsetDateWithTimezone(asset.dateTimeOriginal, offsetData, offsetData.timezone), 'PPpp')} +
)} -
{formatDate(asset.dateTimeOriginal, 'PPpp')}
+
+ {formatDate(asset.dateTimeOriginal, 'PPpp')} +
))} diff --git a/src/pages/albums/[albumId].tsx b/src/pages/albums/[albumId].tsx index 13574e8..c4a3738 100644 --- a/src/pages/albums/[albumId].tsx +++ b/src/pages/albums/[albumId].tsx @@ -3,14 +3,20 @@ import Header from '@/components/shared/Header' import Loader from '@/components/ui/loader' import { useConfig } from '@/contexts/ConfigContext' import { getAlbumInfo } from '@/handlers/api/album.handler' +import { deleteAssets, updateAssets } from '@/handlers/api/asset.handler' import { IAlbum } from '@/types/album' import Link from 'next/link' -import React, { useEffect, useState } from 'react' +import React, { useEffect, useState, useMemo } from 'react' import { useRouter } from 'next/router' import AlbumPeople from '@/components/albums/info/AlbumPeople' import AlbumImages from '@/components/albums/info/AlbumImages' import { Camera, ExternalLink, Users } from 'lucide-react' import { humanizeNumber } from '@/helpers/string.helper' +import PhotoSelectionContext, { IPhotoSelectionContext } from '@/contexts/PhotoSelectionContext' +import FloatingBar from '@/components/shared/FloatingBar' +import { Button } from '@/components/ui/button' +import { AlertDialog } from '@/components/ui/alert-dialog' +import AssetOffsetDialog from '@/components/assets/assets-options/AssetOffsetDialog' export default function AlbumListPage() { const { exImmichUrl } = useConfig() @@ -20,7 +26,29 @@ export default function AlbumListPage() { const [albumInfo, setAlbumInfo] = useState() const [loading, setLoading] = useState(false) const [errorMessage, setErrorMessage] = useState('') - const [selectedAlbums, setSelectedAlbums] = useState([]) + + // PhotoSelection context state + const [contextState, setContextState] = useState({ + selectedIds: [], + assets: [], + config: { + albumId: albumId, + sort: "fileOriginalDate", + sortOrder: "asc" + }, + updateContext: (newConfig: Partial) => { + setContextState(prevState => ({ + ...prevState, + ...newConfig, + config: newConfig.config ? { ...prevState.config, ...newConfig.config } : prevState.config + })); + } + }); + + const selectedAssets = useMemo(() => + contextState.assets.filter((a) => contextState.selectedIds.includes(a.id)), + [contextState.assets, contextState.selectedIds] + ); const fetchAlbumInfo = async () => { setLoading(true) @@ -38,13 +66,12 @@ export default function AlbumListPage() { fetchAlbumInfo() }, []) - const handleSelect = (checked: boolean, albumId: string) => { - if (checked) { - setSelectedAlbums([...selectedAlbums, albumId]) - } else { - setSelectedAlbums(selectedAlbums.filter((id) => id !== albumId)) - } - } + // Update context albumId when router albumId changes + useEffect(() => { + contextState.updateContext({ + config: { ...contextState.config, albumId: albumId } + }); + }, [albumId]); const handleSelectPerson = (personId: string) => { if (faceId === personId) { @@ -65,6 +92,22 @@ export default function AlbumListPage() { } } + const handleDelete = () => { + return deleteAssets(contextState.selectedIds).then(() => { + const newAssets = contextState.assets.filter((a) => !contextState.selectedIds.includes(a.id)); + contextState.updateContext({ + selectedIds: [], + assets: newAssets, + }); + }) + } + + const handleOffsetComplete = () => { + contextState.updateContext({ + selectedIds: [], + }); + } + const renderContent = () => { if (loading) { return @@ -83,8 +126,9 @@ export default function AlbumListPage() {
) } + return ( - +
- {renderContent()} + + {renderContent()} + {selectedAssets.length > 0 && + +
+

+ {contextState.selectedIds.length} Selected +

+
+ {contextState.selectedIds.length === contextState.assets.length ? ( + + ) : ( + + )} + +
+ + + +
+
+
+ } +
) } From 8dab4ced5ba350cd072287c76aa008699b83682e Mon Sep 17 00:00:00 2001 From: Varun Raj Date: Sun, 27 Jul 2025 10:56:54 +0530 Subject: [PATCH 2/7] refactor: improve AlbumPeople component to categorize known and unknown individuals - Introduced useMemo to separate known and unknown people based on their names. - Enhanced rendering logic to display known and unknown people distinctly. - Updated UI elements for better layout and usability, including search input and person rendering. - Adjusted padding and spacing for a more consistent design across the component. --- src/components/albums/info/AlbumPeople.tsx | 100 ++++++++++-------- .../potential-albums/PotentialAlbumsDates.tsx | 2 +- .../missing-location/MissingLocationDates.tsx | 2 +- src/components/shared/Header.tsx | 2 +- src/components/shared/Sidebar.tsx | 8 +- src/pages/people/[personId].tsx | 2 +- 6 files changed, 66 insertions(+), 50 deletions(-) diff --git a/src/components/albums/info/AlbumPeople.tsx b/src/components/albums/info/AlbumPeople.tsx index 4981c04..e37386f 100644 --- a/src/components/albums/info/AlbumPeople.tsx +++ b/src/components/albums/info/AlbumPeople.tsx @@ -47,6 +47,13 @@ export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeoplePr return people.filter((person) => person.name.toLowerCase().includes(searchQuery.toLowerCase())) }, [people, searchQuery]) + const { knownPeople, unknownPeople } = useMemo(() => { + return { + knownPeople: people.filter((person) => person.name), + unknownPeople: people.filter((person) => !person.name) + } + }, [people]) + const fetchPeople = async () => { return getAlbumPeople(album.id).then((people) => { setPeople(people) @@ -102,8 +109,46 @@ export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeoplePr return
{errorMessage}
} + const renderPerson = (person: IAlbumPerson) => ( +
{ + if (selectionMode) { + handleBulkSelect(person.id) + } else { + onSelect(person.id) + } + }} + > + {selectionMode && ( + handleBulkSelect(person.id)} + /> + )} + +
+

{person.name || "No Name"}

+

{person.numberOfPhotos} photos

+
+
+ ) + return ( -
+
setSearchQuery(e.target.value)} /> {selectedPerson && ( -
+
)} +
-

People

+

Known People

{!readOnly && ( <> {!selectedPerson && ( @@ -178,45 +224,15 @@ export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeoplePr )}
-
- {filteredPeople.map((person) => ( -
{ - if (selectionMode) { - handleBulkSelect(person.id) - } else { - onSelect(person.id) - } - }} - > - {selectionMode && ( - handleBulkSelect(person.id)} - /> - )} - -
-

{person.name || "No Name"}

-

{person.numberOfPhotos} photos

-
-
- ))} +
+ {knownPeople.map(renderPerson)} +
+ {unknownPeople.length > 0 && ( +
+

Unknown People

+ {unknownPeople.map(renderPerson)} +
+ )}
) diff --git a/src/components/albums/potential-albums/PotentialAlbumsDates.tsx b/src/components/albums/potential-albums/PotentialAlbumsDates.tsx index 984e030..a2fd261 100644 --- a/src/components/albums/potential-albums/PotentialAlbumsDates.tsx +++ b/src/components/albums/potential-albums/PotentialAlbumsDates.tsx @@ -51,7 +51,7 @@ export default function PotentialAlbumsDates() { }, [filters, minAssets]); return ( -
+
handleNameChange(e.target.value)} + /> +
+ + + + + +
); } \ No newline at end of file diff --git a/src/components/assets/missing-location/TagMissingLocationDialog/RecentSearches.tsx b/src/components/assets/missing-location/TagMissingLocationDialog/RecentSearches.tsx new file mode 100644 index 0000000..7c12eeb --- /dev/null +++ b/src/components/assets/missing-location/TagMissingLocationDialog/RecentSearches.tsx @@ -0,0 +1,79 @@ +import { Button } from "@/components/ui/button"; +import { cn } from "@/lib/utils"; +import { getRecentSearchesByType, RecentSearch } from "@/lib/utils"; +import { IPlace } from "@/types/common"; +import { Clock, MapPin } from "lucide-react"; +import React from "react"; + +interface RecentSearchesProps { + searchType: RecentSearch['searchType']; + onSelect: (place: IPlace) => void; + selectedPlace?: IPlace | null; +} + +export default function RecentSearches({ searchType, onSelect, selectedPlace }: RecentSearchesProps) { + const recentSearches = getRecentSearchesByType(searchType); + + if (recentSearches.length === 0) { + return null; + } + + const formatTimeAgo = (timestamp: number) => { + const now = Date.now(); + const diff = now - timestamp; + const minutes = Math.floor(diff / (1000 * 60)); + const hours = Math.floor(diff / (1000 * 60 * 60)); + const days = Math.floor(diff / (1000 * 60 * 60 * 24)); + + if (days > 0) return `${days}d ago`; + if (hours > 0) return `${hours}h ago`; + if (minutes > 0) return `${minutes}m ago`; + return 'Just now'; + }; + + return ( +
+
+ +

Recent Searches

+
+
+ {recentSearches.map((search, index) => ( +
onSelect({ + name: search.name, + latitude: search.latitude, + longitude: search.longitude + })} + className={cn( + "hover:bg-zinc-200 dark:hover:bg-zinc-800 flex justify-between items-center px-3 py-2 rounded-lg cursor-pointer border", + { + "bg-zinc-200 dark:bg-zinc-800 border-primary": + selectedPlace && + selectedPlace.name === search.name && + selectedPlace.latitude === search.latitude && + selectedPlace.longitude === search.longitude, + } + )} + > +
+
+ +

{search.name}

+
+
+ + {search.latitude.toFixed(4)}, {search.longitude.toFixed(4)} + + + {formatTimeAgo(search.timestamp)} + +
+
+
+ ))} +
+
+ ); +} \ No newline at end of file diff --git a/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationDialog.tsx b/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationDialog.tsx index d8eb4a9..374550d 100644 --- a/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationDialog.tsx +++ b/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationDialog.tsx @@ -15,6 +15,8 @@ import TagMissingLocationSearchLatLong from "./TagMissingLocationSearchLatLong"; import TagMissingLocationOSMSearchAndAdd from "./TagMissingLocationOSMSearchAndAdd"; import dynamic from "next/dynamic"; import { usePhotoSelectionContext } from "@/contexts/PhotoSelectionContext"; +import { addRecentSearch } from "@/lib/utils"; +import RecentSearches from "./RecentSearches"; const LazyMap = dynamic(() => import("./Map"), { ssr: false @@ -31,9 +33,15 @@ export default function TagMissingLocationDialog({ const [mapPosition, setMapPosition] = useState({ latitude: 48.210033, longitude: 16.363449, - name: "Vienna, Austria" + name: "" }); + const handleMapSubmit = async (place: IPlace) => { + // Save to recent searches + addRecentSearch(place, 'map'); + return onSubmit(place); + }; + return ( @@ -64,11 +72,39 @@ export default function TagMissingLocationDialog({
+ {/* Recent Searches */} + { + setMapPosition(place); + }} + selectedPlace={mapPosition.name ? mapPosition : null} + /> + +
+ + +
diff --git a/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationOSMSearchAndAdd.tsx b/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationOSMSearchAndAdd.tsx index 9f74c1d..d5ffe1f 100644 --- a/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationOSMSearchAndAdd.tsx +++ b/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationOSMSearchAndAdd.tsx @@ -4,11 +4,12 @@ import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import Loader from "@/components/ui/loader"; import { useToast } from "@/components/ui/use-toast"; -import { cn } from "@/lib/utils"; +import { cn, addRecentSearch } from "@/lib/utils"; import { IPlace } from "@/types/common"; import axios from "axios"; import { Check } from "lucide-react"; import React, { useRef, useState } from "react"; +import RecentSearches from "./RecentSearches"; interface ITagMissingLocationSearchAndAddProps { onSubmit: (place: IPlace) => Promise; @@ -107,6 +108,8 @@ export default function TagMissingLocationOSMSearchAndAdd( setSubmitting(true); onSubmit(selectedPlace) .then(() => { + // Save to recent searches + addRecentSearch(selectedPlace, 'osm'); toast({ title: "Location updated", description: "Location updated successfully", @@ -136,6 +139,19 @@ export default function TagMissingLocationOSMSearchAndAdd( handleSearch(e.target.value); }} /> + + {/* Recent Searches */} + {!loading && !searchedPlaces && ( + { + setSelectedPlace(place); + onLocationChange(place); + }} + selectedPlace={selectedPlace} + /> + )} +
{loading && } {!loading && searchedPlaces && searchedPlaces.length === 0 && ( diff --git a/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationSearchAndAdd.tsx b/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationSearchAndAdd.tsx index 85e455c..0e1df55 100644 --- a/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationSearchAndAdd.tsx +++ b/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationSearchAndAdd.tsx @@ -5,10 +5,11 @@ import { Input } from "@/components/ui/input"; import Loader from "@/components/ui/loader"; import { useToast } from "@/components/ui/use-toast"; import { searchPlaces } from "@/handlers/api/common.handler"; -import { cn } from "@/lib/utils"; +import { cn, addRecentSearch } from "@/lib/utils"; import { IPlace } from "@/types/common"; import { Check } from "lucide-react"; import React, { useRef, useState } from "react"; +import RecentSearches from "./RecentSearches"; interface ITagMissingLocationSearchAndAddProps { onSubmit: (place: IPlace) => Promise; @@ -70,6 +71,8 @@ export default function TagMissingLocationSearchAndAdd( setSubmitting(true); onSubmit(selectedPlace) .then(() => { + // Save to recent searches + addRecentSearch(selectedPlace, 'immich'); toast({ title: "Location updated", description: "Location updated successfully", @@ -101,6 +104,18 @@ export default function TagMissingLocationSearchAndAdd( }} />
+ + {/* Recent Searches */} + {!loading && !searchedPlaces && ( + { + setSelectedPlace(place); + }} + selectedPlace={selectedPlace} + /> + )} +
{loading && } {!loading && searchedPlaces && searchedPlaces.length === 0 && ( @@ -113,9 +128,9 @@ export default function TagMissingLocationSearchAndAdd( key={place.name} onClick={() => handleSelect(place)} className={cn( - "hover:bg-zinc-200 dark:hover:bg-zinc-800 flex justify-between items-center px-2 py-1 rounded-lg cursor-pointer", + "hover:bg-gray-300 dark:hover:bg-gray-700 flex justify-between items-center px-2 py-1 rounded-lg cursor-pointer", { - "bg-zinc-900 dark:bg-zinc-200": + "bg-gray-300 dark:bg-gray-700": selectedPlace && selectedPlace.name === place.name, } )} diff --git a/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationSearchLatLong.tsx b/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationSearchLatLong.tsx index 81b222c..9ac6183 100644 --- a/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationSearchLatLong.tsx +++ b/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationSearchLatLong.tsx @@ -4,8 +4,10 @@ import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { useToast } from "@/components/ui/use-toast"; +import { addRecentSearch } from "@/lib/utils"; import { IPlace } from "@/types/common"; import React, { useEffect, useMemo, useState } from "react"; +import RecentSearches from "./RecentSearches"; interface TagMissingLocationSearchLatLongProps { onSubmit: (place: IPlace) => Promise; @@ -52,6 +54,8 @@ export default function TagMissingLocationSearchLatLong( setSubmitting(true); onSubmit(formData) .then(() => { + // Save to recent searches + addRecentSearch(formData, 'latlong'); toast({ title: "Location updated", description: "Location updated successfully", @@ -119,6 +123,17 @@ export default function TagMissingLocationSearchLatLong(
+ {/* Recent Searches */} + { + setFormData(place); + onLocationChange(place); + setLatLong(`${place.latitude}, ${place.longitude}`); + }} + selectedPlace={formData.name ? formData : null} + /> +
@@ -230,7 +239,7 @@ export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeoplePr )} {selectedPeople.length > 0 && (
-
@@ -257,4 +266,8 @@ export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeoplePr
) -} +}) + +AlbumPeople.displayName = "AlbumPeople" + +export default AlbumPeople diff --git a/src/components/albums/info/AlbumPersonNameBar.tsx b/src/components/albums/info/AlbumPersonNameBar.tsx new file mode 100644 index 0000000..5852ea1 --- /dev/null +++ b/src/components/albums/info/AlbumPersonNameBar.tsx @@ -0,0 +1,114 @@ +import FloatingBar from '@/components/shared/FloatingBar' +import { AlertDialog, IAlertDialogActions } from '@/components/ui/alert-dialog' +import { Autocomplete, AutocompleteOption } from '@/components/ui/autocomplete' +import { Button } from '@/components/ui/button' +import { Input } from '@/components/ui/input' +import { useToast } from '@/components/ui/use-toast' +import { mergePerson, searchPeople, updatePerson } from '@/handlers/api/people.handler' +import { IAlbumPerson } from '@/types/album' +import { useRef, useState } from 'react' +import { Toaster } from 'react-hot-toast' + +interface AlbumPersonNameBarProps { + selectedPerson: IAlbumPerson | null + faceId: string + onUpdate: (person: IAlbumPerson | null) => void + onMerge: (oldPerson: IAlbumPerson, newPerson: IAlbumPerson) => void +} + +export default function AlbumPersonNameBar({ selectedPerson, faceId, onUpdate, onMerge }: AlbumPersonNameBarProps) { + + const [newName, setNewName] = useState(selectedPerson?.name) + const [loading, setLoading] = useState(false) + const mergeDialogRef = useRef(null); + const selectedPersonRef = useRef(null); + + const { toast } = useToast() + + + const handleFormSubmit = () => { + if (!faceId) return + setLoading(true) + updatePerson(faceId, { + name: newName + }) + .then((person) => { + onUpdate(person) + }) + .catch((error) => { + toast({ + title: "Error updating person", + description: error.message, + variant: "destructive" + }) + }) + .finally(() => { + setLoading(false) + }) + } + + const handleMerge = async (option: AutocompleteOption) => { + if (!selectedPerson) return + return mergePerson(option.value, [selectedPerson.id]).then(() => { + onMerge(selectedPerson, { + ...selectedPerson, + id: option.value, + name: option.label, + }) + }) + .catch((error) => { + toast({ + title: "Error merging person", + description: error.message, + variant: "destructive" + }) + }) + .finally(() => { + setLoading(false) + }) + }; + + return ( + <> + +
+ searchPeople(query).then((people) => people.map((person: any) => ({ + label: person.name, value: person.id, + imageUrl: person.thumbnailPath + })))} + type="text" + defaultValue={newName} + placeholder="Enter name" + autoFocus + onChange={(e) => { + setNewName(e.target.value); + }} + value={newName || ""} + onOptionSelect={(value) => { + mergeDialogRef.current?.open(); + selectedPersonRef.current = value; + }} + createNewLabel="Create" + disabled={loading} + onCreateNew={() => { + console.log("create new") + handleFormSubmit(); + }} + /> +
+
+ { + if (selectedPersonRef.current) { + handleMerge(selectedPersonRef.current); + } + }} + /> + + ) +} \ No newline at end of file diff --git a/src/components/shared/FloatingBar.tsx b/src/components/shared/FloatingBar.tsx index 06d1a4c..7793795 100644 --- a/src/components/shared/FloatingBar.tsx +++ b/src/components/shared/FloatingBar.tsx @@ -6,10 +6,8 @@ interface FloatingBarProps { export default function FloatingBar({ children }: FloatingBarProps) { return ( -
-
+
{children}
-
) } diff --git a/src/components/ui/autocomplete.tsx b/src/components/ui/autocomplete.tsx index 3baa2f0..83eb5ec 100644 --- a/src/components/ui/autocomplete.tsx +++ b/src/components/ui/autocomplete.tsx @@ -20,6 +20,7 @@ export interface AutocompleteProps extends React.InputHTMLAttributes void createNewLabel?: string + position?: "top" | "bottom" } const Autocomplete = React.forwardRef( @@ -34,6 +35,7 @@ const Autocomplete = React.forwardRef( isLoading: externalLoading, onCreateNew, createNewLabel = "Create new", + position = "top", ...props }, forwardedRef) => { const [open, setOpen] = React.useState(false) @@ -193,7 +195,7 @@ const Autocomplete = React.forwardRef( }} /> {open && (filteredOptions.length > 0 || isLoading || showCreateNew) && ( -
+
{isLoading ? (
Loading... diff --git a/src/pages/albums/[albumId].tsx b/src/pages/albums/[albumId].tsx index c4a3738..7012e8c 100644 --- a/src/pages/albums/[albumId].tsx +++ b/src/pages/albums/[albumId].tsx @@ -4,11 +4,11 @@ import Loader from '@/components/ui/loader' import { useConfig } from '@/contexts/ConfigContext' import { getAlbumInfo } from '@/handlers/api/album.handler' import { deleteAssets, updateAssets } from '@/handlers/api/asset.handler' -import { IAlbum } from '@/types/album' +import { IAlbum, IAlbumPerson } from '@/types/album' import Link from 'next/link' -import React, { useEffect, useState, useMemo } from 'react' +import React, { useEffect, useState, useMemo, useRef } from 'react' import { useRouter } from 'next/router' -import AlbumPeople from '@/components/albums/info/AlbumPeople' +import AlbumPeople, { IAlbumPeopleRef } from '@/components/albums/info/AlbumPeople' import AlbumImages from '@/components/albums/info/AlbumImages' import { Camera, ExternalLink, Users } from 'lucide-react' import { humanizeNumber } from '@/helpers/string.helper' @@ -17,6 +17,8 @@ import FloatingBar from '@/components/shared/FloatingBar' import { Button } from '@/components/ui/button' import { AlertDialog } from '@/components/ui/alert-dialog' import AssetOffsetDialog from '@/components/assets/assets-options/AssetOffsetDialog' +import { Input } from '@/components/ui/input' +import AlbumPersonNameBar from '@/components/albums/info/AlbumPersonNameBar' export default function AlbumListPage() { const { exImmichUrl } = useConfig() @@ -26,6 +28,8 @@ export default function AlbumListPage() { const [albumInfo, setAlbumInfo] = useState() const [loading, setLoading] = useState(false) const [errorMessage, setErrorMessage] = useState('') + const [selectedPerson, setSelectedPerson] = useState(null) + const albumPeopleRef = useRef(null) // PhotoSelection context state const [contextState, setContextState] = useState({ @@ -73,8 +77,9 @@ export default function AlbumListPage() { }); }, [albumId]); - const handleSelectPerson = (personId: string) => { - if (faceId === personId) { + const handleSelectPerson = (person: IAlbumPerson) => { + setSelectedPerson(person) + if (faceId === person.id) { router.push({ pathname, query: { @@ -86,12 +91,24 @@ export default function AlbumListPage() { pathname, query: { albumId, - faceId: personId + faceId: person.id } }) } } + const handleUpdatePerson = (person: IAlbumPerson | null) => { + setSelectedPerson(person) + if (person) { + albumPeopleRef.current?.updatePerson(person) + } + } + + const handleMergePerson = (oldPerson: IAlbumPerson, newPerson: IAlbumPerson) => { + setSelectedPerson(newPerson) + albumPeopleRef.current?.mergePerson(oldPerson, newPerson) + } + const handleDelete = () => { return deleteAssets(contextState.selectedIds).then(() => { const newAssets = contextState.assets.filter((a) => !contextState.selectedIds.includes(a.id)); @@ -119,7 +136,7 @@ export default function AlbumListPage() {
{albumInfo && ( <> - + )} @@ -210,6 +227,10 @@ export default function AlbumListPage() {
} + + {!selectedAssets.length && faceId && !selectedPerson?.name && ( + + )} ) diff --git a/src/types/album.d.ts b/src/types/album.d.ts index 0e3f281..5ca8201 100644 --- a/src/types/album.d.ts +++ b/src/types/album.d.ts @@ -38,4 +38,11 @@ export interface IAlbumCreate { role: string; userId: string; }[]; +} + +export interface IAlbumPerson { + id: string + name: string + numberOfPhotos: number + } \ No newline at end of file From aef4e6ee860ea57cfaa3e10f7301e9a56904c9b0 Mon Sep 17 00:00:00 2001 From: Varun Raj Date: Sun, 27 Jul 2025 17:30:23 +0530 Subject: [PATCH 6/7] feat: better ux for tagging people in album --- src/components/albums/info/AlbumImages.tsx | 8 +- src/components/albums/info/AlbumPeople.tsx | 119 +++++++++++------- .../albums/info/AlbumPersonNameBar.tsx | 5 +- src/components/shared/FloatingBar.tsx | 2 +- src/pages/albums/[albumId].tsx | 4 +- src/pages/api/albums/[id]/assets.ts | 5 +- 6 files changed, 88 insertions(+), 55 deletions(-) diff --git a/src/components/albums/info/AlbumImages.tsx b/src/components/albums/info/AlbumImages.tsx index e789a83..0736e9f 100644 --- a/src/components/albums/info/AlbumImages.tsx +++ b/src/components/albums/info/AlbumImages.tsx @@ -1,7 +1,7 @@ import "yet-another-react-lightbox/styles.css"; import { listAlbumAssets } from "@/handlers/api/album.handler"; import { useConfig } from "@/contexts/ConfigContext"; -import { IAlbum } from "@/types/album"; +import { IAlbum, IAlbumPerson } from "@/types/album"; import { IAsset } from "@/types/asset"; import React, { useEffect, useMemo, useRef, useState, MouseEvent } from "react"; import { Hourglass } from "lucide-react"; @@ -12,9 +12,12 @@ import Lightbox from "yet-another-react-lightbox"; import Captions from "yet-another-react-lightbox/plugins/captions"; import LazyGridImage from "@/components/ui/lazy-grid-image"; import { usePhotoSelectionContext } from "@/contexts/PhotoSelectionContext"; +import { PERSON_THUBNAIL_PATH } from "@/config/routes"; +import Image from "next/image"; interface AlbumImagesProps { album: IAlbum; + selectedPerson: IAlbumPerson | null; } interface IAssetFilter { @@ -22,7 +25,7 @@ interface IAssetFilter { page: number; } -export default function AlbumImages({ album }: AlbumImagesProps) { +export default function AlbumImages({ album, selectedPerson }: AlbumImagesProps) { const { exImmichUrl } = useConfig(); const router = useRouter(); const { faceId } = router.query as { faceId: string }; @@ -158,6 +161,7 @@ export default function AlbumImages({ album }: AlbumImagesProps) { return ( <> + (({ album const [selectionMode, setSelectionMode] = useState(false) const [selectedPeople, setSelectedPeople] = useState([]) const [searchQuery, setSearchQuery] = useState("") - + const selectedPerson = useMemo(() => { return people.find((person) => query.faceId === person.id) }, [people, query.faceId]) @@ -108,7 +111,7 @@ const AlbumPeople = React.forwardRef(({ album } }) } - + useEffect(() => { fetchPeople() @@ -157,7 +160,7 @@ const AlbumPeople = React.forwardRef(({ album @@ -172,12 +175,29 @@ const AlbumPeople = React.forwardRef(({ album return (
- setSearchQuery(e.target.value)} - /> +
+ setSearchQuery(e.target.value)} + /> + {!readOnly && !selectedPerson && ( + + )} +
{selectedPerson && (
@@ -189,6 +209,7 @@ const AlbumPeople = React.forwardRef(({ album className="rounded-full" /> + {selectedPerson.name || "No Name"} @@ -224,45 +245,51 @@ const AlbumPeople = React.forwardRef(({ album )}
- -
-

Known People

- {!readOnly && ( - <> - {!selectedPerson && ( - - )} - {selectedPeople.length > 0 && ( -
- + + + +
+

Known ({knownPeople.length})

- )} - - )} -
-
- {knownPeople.map(renderPerson)} -
- {unknownPeople.length > 0 && ( -
-
-

Unknown People

- + + +
+ {knownPeople.map(renderPerson)} +
+
+ + + {unknownPeople.length > 0 && ( + + +
+

Unknown ({unknownPeople.length})

+ { + handleUnknownPeopleCheck(checked) + }} + onClick={(e) => e.stopPropagation()} + /> +
+
+ +
+ {unknownPeople.map(renderPerson)} +
+
+
+ )} + + + {selectedPeople.length > 0 && ( +
+
- {unknownPeople.map(renderPerson)} -
- )} + )}
) diff --git a/src/components/albums/info/AlbumPersonNameBar.tsx b/src/components/albums/info/AlbumPersonNameBar.tsx index 5852ea1..900f2ef 100644 --- a/src/components/albums/info/AlbumPersonNameBar.tsx +++ b/src/components/albums/info/AlbumPersonNameBar.tsx @@ -1,13 +1,12 @@ import FloatingBar from '@/components/shared/FloatingBar' import { AlertDialog, IAlertDialogActions } from '@/components/ui/alert-dialog' import { Autocomplete, AutocompleteOption } from '@/components/ui/autocomplete' -import { Button } from '@/components/ui/button' -import { Input } from '@/components/ui/input' import { useToast } from '@/components/ui/use-toast' +import { PERSON_THUBNAIL_PATH } from '@/config/routes' import { mergePerson, searchPeople, updatePerson } from '@/handlers/api/people.handler' import { IAlbumPerson } from '@/types/album' +import Image from 'next/image' import { useRef, useState } from 'react' -import { Toaster } from 'react-hot-toast' interface AlbumPersonNameBarProps { selectedPerson: IAlbumPerson | null diff --git a/src/components/shared/FloatingBar.tsx b/src/components/shared/FloatingBar.tsx index 7793795..701d509 100644 --- a/src/components/shared/FloatingBar.tsx +++ b/src/components/shared/FloatingBar.tsx @@ -6,7 +6,7 @@ interface FloatingBarProps { export default function FloatingBar({ children }: FloatingBarProps) { return ( -
+
{children}
) diff --git a/src/pages/albums/[albumId].tsx b/src/pages/albums/[albumId].tsx index 7012e8c..2cf9e87 100644 --- a/src/pages/albums/[albumId].tsx +++ b/src/pages/albums/[albumId].tsx @@ -68,8 +68,8 @@ export default function AlbumListPage() { useEffect(() => { fetchAlbumInfo() - }, []) + }, []) // Update context albumId when router albumId changes useEffect(() => { contextState.updateContext({ @@ -137,7 +137,7 @@ export default function AlbumListPage() { {albumInfo && ( <> - + )}
diff --git a/src/pages/api/albums/[id]/assets.ts b/src/pages/api/albums/[id]/assets.ts index 78b68bb..78e5b2e 100644 --- a/src/pages/api/albums/[id]/assets.ts +++ b/src/pages/api/albums/[id]/assets.ts @@ -3,7 +3,7 @@ import { NextApiRequest } from "next"; import { db } from "@/config/db"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; import { NextApiResponse } from "next"; -import { and, eq, isNotNull } from "drizzle-orm"; +import { and, desc, eq, isNotNull } from "drizzle-orm"; import { assets } from "@/schema/assets.schema"; import { albumsAssetsAssets } from "@/schema/albumAssetsAssets.schema"; import { assetFaces, exif, person } from "@/schema"; @@ -56,6 +56,7 @@ export default async function handler( eq(assets.status, "active"), faceId ? eq(assetFaces.personId, faceId) : undefined, )) + .orderBy(desc(assets.id), desc(assets.localDateTime)) .limit(100) .offset(100 * (page - 1)); @@ -71,6 +72,8 @@ export default async function handler( orientation: asset?.orientation, downloadUrl: asset?.id ? ASSET_VIDEO_PATH(asset.id) : null, }; + }).sort((b, a) => { + return new Date(b.localDateTime || 0).getTime() - new Date(a.localDateTime || 0).getTime(); }); res.status(200).json(cleanedAssets); } \ No newline at end of file From 263212c8b9cd21e9435a04145df2a459045d3fd9 Mon Sep 17 00:00:00 2001 From: Varun Raj Date: Sun, 27 Jul 2025 18:04:35 +0530 Subject: [PATCH 7/7] fix: album creation flow Signed-off-by: Varun Raj --- src/config/constants/sidebarNavs.tsx | 10 +++++----- src/lib/api.ts | 1 - src/pages/albums/potential-albums.tsx | 2 ++ src/pages/api/immich-proxy/[...path].ts | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/config/constants/sidebarNavs.tsx b/src/config/constants/sidebarNavs.tsx index 32570bc..ebe8d2a 100644 --- a/src/config/constants/sidebarNavs.tsx +++ b/src/config/constants/sidebarNavs.tsx @@ -1,11 +1,11 @@ import { GalleryHorizontal, GalleryVerticalEnd, Image as ImageIcon, MapPin, MapPinX, Rewind, Search, User } from "lucide-react"; export const sidebarNavs = [ - { - title: "Rewind 2024", - link: "/rewind", - icon: , - }, + // { + // title: "Rewind 2024", + // link: "/rewind", + // icon: , + // }, { title: "Find Assets", link: "/find", diff --git a/src/lib/api.ts b/src/lib/api.ts index eee6dd2..0bf6edf 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -19,7 +19,6 @@ export class APIError extends Error { } const handleErrors = (error: AxiosError | any) => { - let errorObject = {} if (error.response && error.response.data) { return Promise.reject({ diff --git a/src/pages/albums/potential-albums.tsx b/src/pages/albums/potential-albums.tsx index 120cc51..322559a 100644 --- a/src/pages/albums/potential-albums.tsx +++ b/src/pages/albums/potential-albums.tsx @@ -79,6 +79,8 @@ export default function PotentialAlbums() { }); const newAssets = contextState.assets.filter(a => !contextState.selectedIds.includes(a.id)); updateContext({ selectedIds: [], assets: newAssets }); + }).catch((error) => { + console.log("Error", error); }) } diff --git a/src/pages/api/immich-proxy/[...path].ts b/src/pages/api/immich-proxy/[...path].ts index 95afe27..3beaf92 100644 --- a/src/pages/api/immich-proxy/[...path].ts +++ b/src/pages/api/immich-proxy/[...path].ts @@ -28,9 +28,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) res.setHeader(key, value) }) - // Stream the response body - const reader = response.body?.getReader() - if (reader) { + // Only stream the response body if it exists and has content + if (response.body) { + const reader = response.body.getReader() while (true) { const { done, value } = await reader.read() if (done) break