diff --git a/src/components/albums/info/AlbumImages.tsx b/src/components/albums/info/AlbumImages.tsx index 9240e0d..0736e9f 100644 --- a/src/components/albums/info/AlbumImages.tsx +++ b/src/components/albums/info/AlbumImages.tsx @@ -1,30 +1,38 @@ 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 } 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"; +import { PERSON_THUBNAIL_PATH } from "@/config/routes"; +import Image from "next/image"; interface AlbumImagesProps { album: IAlbum; + selectedPerson: IAlbumPerson | null; } interface IAssetFilter { faceId?: string; 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 }; - 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 +40,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 +58,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 +139,7 @@ export default function AlbumImages({ album }: AlbumImagesProps) { faceId, page: 1, }); - setAssets([]); + updateContext({ assets: [], selectedIds: [] }); setHasMore(true); }, [faceId]); @@ -97,11 +160,30 @@ export default function AlbumImages({ album }: AlbumImagesProps) { } return ( - -
- + <> + + = 0} + index={index} + close={() => setIndex(-1)} + /> +
+ {hasMore && (
- + ); } diff --git a/src/components/albums/info/AlbumPeople.tsx b/src/components/albums/info/AlbumPeople.tsx index 4981c04..7507537 100644 --- a/src/components/albums/info/AlbumPeople.tsx +++ b/src/components/albums/info/AlbumPeople.tsx @@ -1,5 +1,5 @@ -import React, { useEffect, useMemo, useState } from 'react' -import { IAlbum } from '@/types/album' +import React, { useEffect, useImperativeHandle, useMemo, useState } from 'react' +import { IAlbum, IAlbumPerson } from '@/types/album' import { getAlbumPeople } from '@/handlers/api/album.handler' import Loader from '@/components/ui/loader' import LazyImage from '@/components/ui/lazy-image' @@ -14,20 +14,23 @@ import { Button } from '@/components/ui/button' import { updatePerson } from '@/handlers/api/people.handler' import { Checkbox } from '@/components/ui/checkbox' import { Input } from '@/components/ui/input' +import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion' +import { CheckIcon } from '@radix-ui/react-icons' +import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/components/ui/hover-card' interface AlbumPeopleProps { album: IAlbum - onSelect: (personId: string) => void + onSelect: (person: IAlbumPerson) => void readOnly?: boolean } -interface IAlbumPerson { - id: string - name: string - numberOfPhotos: number - +export interface IAlbumPeopleRef { + updatePerson: (person: IAlbumPerson) => void + mergePerson: (oldPerson: IAlbumPerson, newPerson: IAlbumPerson) => void } -export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeopleProps) { + + +const AlbumPeople = React.forwardRef(({ album, onSelect, readOnly }, ref) => { const { exImmichUrl } = useConfig() const router = useRouter() const { query, pathname } = router @@ -47,6 +50,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: filteredPeople.filter((person) => person.name), + unknownPeople: filteredPeople.filter((person) => !person.name) + } + }, [filteredPeople]) + const fetchPeople = async () => { return getAlbumPeople(album.id).then((people) => { setPeople(people) @@ -91,10 +101,31 @@ export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeoplePr } } + const handleUnknownPeopleCheck = (checked: boolean) => { + setSelectedPeople(checked ? unknownPeople.map((person) => person.id) : []) + router.push({ + pathname, + query: { + ...query, + faceId: null + } + }) + } + + useEffect(() => { fetchPeople() }, []) + useImperativeHandle(ref, () => ({ + updatePerson: (person: IAlbumPerson) => { + setPeople((oldPeople) => oldPeople.map((p) => p.id === person.id ? person : p)) + }, + mergePerson: (oldPerson: IAlbumPerson, newPerson: IAlbumPerson) => { + setPeople((oldPeople) => oldPeople.map((p) => p.id === oldPerson.id ? newPerson : p)) + } + })) + if (loading) { return } @@ -102,16 +133,73 @@ export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeoplePr return
{errorMessage}
} + + + const renderPerson = (person: IAlbumPerson) => ( +
{ + if (selectionMode) { + handleBulkSelect(person.id) + } else { + onSelect(person) + } + }} + > + {selectionMode && ( + handleBulkSelect(person.id)} + /> + )} + +
+

{person.name || "No Name"}

+

{person.numberOfPhotos} photos

+
+
+ ) + return ( -
- setSearchQuery(e.target.value)} - /> +
+
+ setSearchQuery(e.target.value)} + /> + {!readOnly && !selectedPerson && ( + + )} +
{selectedPerson && ( -
+
+ {selectedPerson.name || "No Name"} @@ -147,7 +236,7 @@ export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeoplePr } }) }} /> -
@@ -155,69 +244,57 @@ export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeoplePr
)} - -
-

People

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

Known ({knownPeople.length})

- )} - - )} -
-
- {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 ({unknownPeople.length})

+ { + handleUnknownPeopleCheck(checked) + }} + onClick={(e) => e.stopPropagation()} + /> +
+
+ +
+ {unknownPeople.map(renderPerson)} +
+
+
+ )} + + + {selectedPeople.length > 0 && ( +
+
- ))} + )}
) -} +}) + +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..900f2ef --- /dev/null +++ b/src/components/albums/info/AlbumPersonNameBar.tsx @@ -0,0 +1,113 @@ +import FloatingBar from '@/components/shared/FloatingBar' +import { AlertDialog, IAlertDialogActions } from '@/components/ui/alert-dialog' +import { Autocomplete, AutocompleteOption } from '@/components/ui/autocomplete' +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' + +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/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 ( -
+
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/components/assets/missing-location/MissingLocationDates.tsx b/src/components/assets/missing-location/MissingLocationDates.tsx index d4b0d20..907cf20 100644 --- a/src/components/assets/missing-location/MissingLocationDates.tsx +++ b/src/components/assets/missing-location/MissingLocationDates.tsx @@ -75,7 +75,7 @@ export default function MissingLocationDates({ groupBy }: IMissingLocationDatesP }, [filters]); return ( -
+
{groupBy === "album" ? (

Asset Count

diff --git a/src/components/assets/missing-location/TagMissingLocationDialog/Map.tsx b/src/components/assets/missing-location/TagMissingLocationDialog/Map.tsx index fa3dd29..b5f4673 100644 --- a/src/components/assets/missing-location/TagMissingLocationDialog/Map.tsx +++ b/src/components/assets/missing-location/TagMissingLocationDialog/Map.tsx @@ -11,6 +11,8 @@ import { MapContainer, TileLayer, useMapEvents } from "react-leaflet"; import { useState } from "react"; import { IPlace } from "@/types/common"; import CustomMarker from "./CustomMarker"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; interface MapComponentProps { location: IPlace; @@ -33,6 +35,7 @@ const MapMouseHandler = ({ onMouseDown }: MapMouseHandlerProps) => { export default function Map({ location, onLocationChange }: MapComponentProps) { const [position, setPosition] = useState([location.latitude, location.longitude]); + const [locationName, setLocationName] = useState(location.name || ""); const handleClick = (coords: LatLngExpression) => { const normalized = L.latLng(coords); @@ -41,23 +44,41 @@ export default function Map({ location, onLocationChange }: MapComponentProps) { onLocationChange({ latitude: normalized.lat, longitude: normalized.lng, - name: "" + name: locationName }); }; + const handleNameChange = (name: string) => { + setLocationName(name); + onLocationChange({ + latitude: location.latitude, + longitude: location.longitude, + name: name + }); + }; 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} + /> +
+ ) : ( + + )} + +
+ + + +
+
+ + } + + {!selectedAssets.length && faceId && !selectedPerson?.name && ( + + )} + ) } 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/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 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 diff --git a/src/pages/people/[personId].tsx b/src/pages/people/[personId].tsx index 187dff7..14a5737 100644 --- a/src/pages/people/[personId].tsx +++ b/src/pages/people/[personId].tsx @@ -95,7 +95,7 @@ export default function PersonPage() { } />
-
+