diff --git a/src/components/albums/list/AlbumThumbnail.tsx b/src/components/albums/list/AlbumThumbnail.tsx index 2278ccd..e8019be 100644 --- a/src/components/albums/list/AlbumThumbnail.tsx +++ b/src/components/albums/list/AlbumThumbnail.tsx @@ -36,7 +36,7 @@ export default function AlbumThumbnail({ album, onSelect, selected }: IAlbumThum }} />
- {formatDate(album.firstPhotoDate.toString(), 'MMM d, yyyy')} - {formatDate(album.lastPhotoDate.toString(), 'MMM d, yyyy')} + {album.firstPhotoDate ? formatDate(album.firstPhotoDate?.toString(), 'MMM d, yyyy') : ''} - {album.lastPhotoDate ? formatDate(album.lastPhotoDate?.toString(), 'MMM d, yyyy') : ''}
([]); @@ -26,6 +26,7 @@ export default function PotentialAlbumsDates() { return listPotentialAlbumsDates({ sortBy: filters.sortBy, sortOrder: filters.sortOrder, + minAssets, }) .then(setDateRecords) .catch(setErrorMessage) @@ -43,7 +44,7 @@ export default function PotentialAlbumsDates() { useEffect(() => { fetchData(); - }, [filters]); + }, [filters, minAssets]); return (
diff --git a/src/components/assets/missing-location/MissingLocationAssets.tsx b/src/components/assets/missing-location/MissingLocationAssets.tsx index e5545e4..69312f7 100644 --- a/src/components/assets/missing-location/MissingLocationAssets.tsx +++ b/src/components/assets/missing-location/MissingLocationAssets.tsx @@ -81,7 +81,15 @@ export default function MissingLocationAssets({ groupBy }: IProps) { [images] ); - const handleClick = (idx: number) => setIndex(idx); + 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(); diff --git a/src/components/assets/missing-location/MissingLocationDateItem.tsx b/src/components/assets/missing-location/MissingLocationDateItem.tsx index 4e4378e..64b3047 100644 --- a/src/components/assets/missing-location/MissingLocationDateItem.tsx +++ b/src/components/assets/missing-location/MissingLocationDateItem.tsx @@ -3,14 +3,26 @@ import { useMissingLocationContext } from "@/contexts/MissingLocationContext"; import { IMissingLocationDatesResponse } from "@/handlers/api/asset.handler"; import { parseDate, formatDate } from "@/helpers/date.helper"; import { cn } from "@/lib/utils"; -import React, { useMemo } from "react"; +import React, { useEffect, useMemo, useRef } from "react"; interface IProps { record: IMissingLocationDatesResponse; onSelect: (date: string) => void; groupBy: "date" | "album"; } + export default function MissingLocationDateItem({ record, onSelect, groupBy }: IProps) { + // Effect to handle scrolling after rendering + useEffect(() => { + if (startDate === record.label) { + itemsRef.current?.scrollIntoView({ + behavior: "smooth", // Smooth scrolling + block: "center", // Center the item in the view + }); + } + }, []); + + const itemsRef = useRef(null); const { startDate } = useMissingLocationContext() const dateLabel = useMemo(() => { @@ -34,9 +46,10 @@ export default function MissingLocationDateItem({ record, onSelect, groupBy }: I cn("flex gap-1 flex-col p-1 rounded-lg hover:dark:bg-zinc-800 border border-transparent hover:bg-zinc-100", startDate === record.label ? "bg-zinc-100 dark:bg-zinc-800 border-gray-300 dark:border-zinc-700" : "") } + ref={itemsRef} >

{dateLabel}

-

{record.asset_count} Orphan Assets

+

{record.asset_count} Assets

); } diff --git a/src/components/assets/missing-location/MissingLocationDates.tsx b/src/components/assets/missing-location/MissingLocationDates.tsx index e9a24e3..e99bc59 100644 --- a/src/components/assets/missing-location/MissingLocationDates.tsx +++ b/src/components/assets/missing-location/MissingLocationDates.tsx @@ -13,11 +13,8 @@ interface IMissingLocationDatesProps { } export default function MissingLocationDates({ groupBy }: IMissingLocationDatesProps) { - const { updateContext } = useMissingLocationContext(); + const { dates, updateContext } = useMissingLocationContext(); const router = useRouter(); - const [dateRecords, setDateRecords] = React.useState< - IMissingLocationDatesResponse[] - >([]); const [filters, setFilters] = useState<{ sortBy: string, sortOrder: string }>({ sortBy: "date", sortOrder: "desc" }); const [loading, setLoading] = useState(false); @@ -25,12 +22,12 @@ export default function MissingLocationDates({ groupBy }: IMissingLocationDatesP const fetchData = async () => { const func = groupBy === "album" ? listMissingLocationAlbums : listMissingLocationDates - setDateRecords([]) + updateContext({ dates: [] }) return func({ sortBy: filters.sortBy, sortOrder: filters.sortOrder, }) - .then(setDateRecords) + .then((r) => updateContext({ dates: r })) .catch(setErrorMessage) .finally(() => setLoading(false)); }; @@ -96,7 +93,7 @@ export default function MissingLocationDates({ groupBy }: IMissingLocationDatesP
- {dateRecords.map((record) => ( + {dates.map((record) => ( - + - Immich Search - OSM Search - Lat & Long - Map + Open Street Map + Immich Geo + Lat & Long + Map - - - + + + diff --git a/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationOSMSearchAndAdd.tsx b/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationOSMSearchAndAdd.tsx index e064ac2..26a4dbb 100644 --- a/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationOSMSearchAndAdd.tsx +++ b/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationOSMSearchAndAdd.tsx @@ -96,7 +96,6 @@ export default function TagMissingLocationOSMSearchAndAdd( setSelectedPlace(null); } else { setSelectedPlace(place); - debugger; onLocationChange(place); } }; @@ -132,15 +131,12 @@ export default function TagMissingLocationOSMSearchAndAdd( return (
-
- { handleSearch(e.target.value); }} /> -
{loading && } {!loading && searchedPlaces && searchedPlaces.length === 0 && ( @@ -153,21 +149,21 @@ export default function TagMissingLocationOSMSearchAndAdd( key={place.name} onClick={() => handleSelect(place)} className={cn( - "hover:bg-gray-300 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-gray-300": + "bg-gray-300 dark:bg-gray-700": selectedPlace && selectedPlace.name === place.name, } )} >
-

{place.name}

- +

{place.name}

+ {place.latitude}, {place.longitude}
{selectedPlace && selectedPlace.name === place.name && ( - + )}
))} @@ -176,11 +172,11 @@ export default function TagMissingLocationOSMSearchAndAdd(
diff --git a/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationSearchAndAdd.tsx b/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationSearchAndAdd.tsx index 949bf79..3619fee 100644 --- a/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationSearchAndAdd.tsx +++ b/src/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationSearchAndAdd.tsx @@ -96,7 +96,6 @@ export default function TagMissingLocationSearchAndAdd( return (
- { @@ -116,21 +115,21 @@ export default function TagMissingLocationSearchAndAdd( key={place.name} onClick={() => handleSelect(place)} className={cn( - "hover:bg-zinc-900 flex justify-between items-center px-2 py-1 rounded-lg cursor-pointer", + "hover:bg-zinc-200 dark:hover:bg-zinc-800 flex justify-between items-center px-2 py-1 rounded-lg cursor-pointer", { - "bg-zinc-900": + "bg-zinc-900 dark:bg-zinc-200": selectedPlace && selectedPlace.name === place.name, } )} >

{place.name}

- + {place.latitude}, {place.longitude}
{selectedPlace && selectedPlace.name === place.name && ( - + )}
))} @@ -139,11 +138,11 @@ export default function TagMissingLocationSearchAndAdd(
diff --git a/src/components/people/PeopleFilters.tsx b/src/components/people/PeopleFilters.tsx index c64a39c..6915039 100644 --- a/src/components/people/PeopleFilters.tsx +++ b/src/components/people/PeopleFilters.tsx @@ -15,20 +15,27 @@ import { import { Input } from "../ui/input"; import { IPersonListFilters } from "@/handlers/api/people.handler"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select"; +import { removeNullOrUndefinedProperties } from "@/helpers/data.helper"; +import { ParsedUrlQueryInput } from "querystring"; export function PeopleFilters() { const router = useRouter(); - const { updateContext, page, maximumAssetCount, type = "all", query ="" } = usePeopleFilterContext(); + const { updateContext, page, maximumAssetCount, type = "all", query = "", visibility = "all" } = usePeopleFilterContext(); const handleChange = (data: Partial) => { updateContext(data); router.push({ pathname: router.pathname, - query: { + query: { ...router.query, - ...data, + ...data, page: data.page || undefined, type: data.type || undefined, + visibility: data.visibility || undefined, + query: data.query || undefined, + maximumAssetCount: data.maximumAssetCount || undefined, + sort: data.sort || undefined, + sortOrder: data.sortOrder || undefined, }, }); } @@ -73,6 +80,17 @@ export function PeopleFilters() { + + diff --git a/src/components/shared/AlbumDropdown.tsx b/src/components/shared/AlbumDropdown.tsx new file mode 100644 index 0000000..8ff4f3f --- /dev/null +++ b/src/components/shared/AlbumDropdown.tsx @@ -0,0 +1,63 @@ +import { listAlbums } from '@/handlers/api/album.handler'; +import { IAlbum } from '@/types/album'; +import React, { useEffect, useState } from 'react' +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select'; +import { X } from 'lucide-react'; + +interface IAlbumDropdownProps { + albumIds?: string[]; + onChange: (albumIds: string[]) => void; +} +export default function AlbumDropdown({ albumIds, onChange }: IAlbumDropdownProps) { + const [albums, setAlbums] = useState([]); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + const [selectedAlbumIds, setSelectedAlbumIds] = useState(albumIds); + + const fetchAlbums = async () => { + setLoading(true); + return listAlbums({ + sortBy: "createdAt", + sortOrder: "desc", + }).then((albums) => setAlbums(albums)).catch((error) => setError(error)).finally(() => setLoading(false)) ; + } + + useEffect(() => { + fetchAlbums(); + }, []); + + + useEffect(() => { + if (albumIds) { + setSelectedAlbumIds(albumIds); + } else { + setSelectedAlbumIds([]); + } + }, [albumIds]); + + return ( +
+ +
+ ) +} \ No newline at end of file diff --git a/src/components/shared/AssetGrid.tsx b/src/components/shared/AssetGrid.tsx index bd5a74b..ffac294 100644 --- a/src/components/shared/AssetGrid.tsx +++ b/src/components/shared/AssetGrid.tsx @@ -20,6 +20,15 @@ export default function AssetGrid({ assets, isInternal = true, selectable = fals const [selectedIds, setSelectedIds] = useState([]); const [lastSelectedIndex, setLastSelectedIndex] = useState(-1); + + const handleClick = (index: number, asset: IAsset, event: React.MouseEvent) => { + if (selectedIds.length > 0) { + handleSelect(index, asset, event); + } else { + setIndex(index); + } + } + const handleSelect = (_idx: number, asset: IAsset, event: React.MouseEvent) => { event.stopPropagation(); @@ -55,13 +64,13 @@ export default function AssetGrid({ assets, isInternal = true, selectable = fals type: (asset.type === "VIDEO" ? "video" : "image") as any, sources: asset.type === "VIDEO" - ? [ - { - src: asset.downloadUrl as string, - type: "video/mp4", - }, - ] - : undefined, + ? [ + { + src: asset.downloadUrl as string, + type: "video/mp4", + }, + ] + : undefined, height: asset.exifImageHeight as number, width: asset.exifImageWidth as number, downloadUrl: asset.downloadUrl as string, @@ -104,7 +113,7 @@ export default function AssetGrid({ assets, isInternal = true, selectable = fals /> void; +} +export default function PeopleDropdown({ peopleIds, onChange }: IPeopleDropdownProps) { + const [people, setPeople] = useState([]); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + const [selectedPeopleIds, setSelectedPeopleIds] = useState(peopleIds); + const [filters, setFilters] = useState({ + page: 1, + perPage: 10000, + sort: "createdAt", + sortOrder: "desc", + visibility: "visible", + type: "named", + }); + + const fetchPeople = async () => { + setLoading(true); + return listPeople(filters).then((people) => setPeople(people.people)).catch((error) => setError(error)).finally(() => setLoading(false)); + } + + useEffect(() => { + fetchPeople(); + }, [filters]); + + useEffect(() => { + if (peopleIds) { + setSelectedPeopleIds(peopleIds); + } else { + setSelectedPeopleIds([]); + } + }, [peopleIds]); + + return ( +
+ +
+ ) +} \ No newline at end of file diff --git a/src/components/shared/ProfileInfo.tsx b/src/components/shared/ProfileInfo.tsx index 0e84a25..87e8e73 100644 --- a/src/components/shared/ProfileInfo.tsx +++ b/src/components/shared/ProfileInfo.tsx @@ -5,6 +5,7 @@ import { useConfig } from "@/contexts/ConfigContext"; import { logoutUser } from "@/handlers/api/user.handler" import { useCurrentUser } from "@/contexts/CurrentUserContext"; import { useToast } from "../ui/use-toast"; +import { HandshakeIcon } from "lucide-react"; export default function ProfileInfo() { const { updateContext, ...user } = useCurrentUser() @@ -36,11 +37,19 @@ export default function ProfileInfo() { {user && ( <>

{user?.name}

- {!user.isUsingAPIKey && ( - - )} +
+ {!user.isUsingAPIKey && ( + + )} + +
)} diff --git a/src/components/ui/combobox.tsx b/src/components/ui/combobox.tsx index b7fd690..4277f28 100644 --- a/src/components/ui/combobox.tsx +++ b/src/components/ui/combobox.tsx @@ -26,21 +26,27 @@ export interface IComboBoxProps { onSelect?: (value: string) => void onOpenChange?: (open: boolean) => void closeOnSelect?: boolean + label?: string + onTextChange?: (text: string) => void } export function Combobox( - { options, onSelect, onOpenChange, closeOnSelect }: IComboBoxProps + { options, onSelect, onOpenChange, closeOnSelect, label, onTextChange }: IComboBoxProps ) { const [open, setOpen] = React.useState(false) const [value, setValue] = React.useState("") + return ( { setOpen(openState) onOpenChange?.(openState) }}> - +
+ + {label} +
diff --git a/src/contexts/MissingLocationContext.tsx b/src/contexts/MissingLocationContext.tsx index 2e77eb2..573b90f 100644 --- a/src/contexts/MissingLocationContext.tsx +++ b/src/contexts/MissingLocationContext.tsx @@ -1,3 +1,4 @@ +import { IMissingLocationDatesResponse } from "@/handlers/api/asset.handler"; import { IAsset } from "@/types/asset"; import { createContext, useContext } from "react"; @@ -8,6 +9,7 @@ export interface IMissingLocationConfig { assets: IAsset[]; sort: "fileOriginalDate"; sortOrder: "asc"|"desc"; + dates: IMissingLocationDatesResponse[]; } export interface MissingLocationContext extends IMissingLocationConfig { @@ -16,6 +18,7 @@ export interface MissingLocationContext extends IMissingLocationConfig { const MissingLocationContext = createContext({ startDate: undefined, albumId: undefined, + dates: [], selectedIds: [], assets: [], updateContext: () => { }, diff --git a/src/contexts/PotentialAlbumContext.tsx b/src/contexts/PotentialAlbumContext.tsx index a02d408..c4c01aa 100644 --- a/src/contexts/PotentialAlbumContext.tsx +++ b/src/contexts/PotentialAlbumContext.tsx @@ -5,6 +5,7 @@ export interface IPotentialAlbumConfig { startDate?: string; selectedIds: string[]; assets: IAsset[]; + minAssets?: number; } export interface IPotentialAlbumContext extends IPotentialAlbumConfig { @@ -14,6 +15,7 @@ const PotentialAlbumContext = createContext({ startDate: undefined, selectedIds: [], assets: [], + minAssets: 1, updateContext: () => { }, }); diff --git a/src/handlers/api/album.handler.ts b/src/handlers/api/album.handler.ts index 6cb08d7..32541f7 100644 --- a/src/handlers/api/album.handler.ts +++ b/src/handlers/api/album.handler.ts @@ -9,6 +9,7 @@ interface IPotentialAlbumsDatesFilters { endDate?: string; sortBy?: string; sortOrder?: string; + minAssets?: number; } export interface IPotentialAlbumsDatesResponse { date: string; diff --git a/src/handlers/api/asset.handler.ts b/src/handlers/api/asset.handler.ts index 4ea921a..13ba4a2 100644 --- a/src/handlers/api/asset.handler.ts +++ b/src/handlers/api/asset.handler.ts @@ -61,8 +61,12 @@ export const findAssets = async (query: string) => { return API.post(FIND_ASSETS, { query }); } -export const getAssetGeoHeatmap = async () => { - return API.get(ASSET_GEO_HEATMAP_PATH); +export interface IHeatMapParams { + albumIds?: string; + peopleIds?: string; +} +export const getAssetGeoHeatmap = async (filters: IHeatMapParams) => { + return API.get(ASSET_GEO_HEATMAP_PATH, filters); } export const deleteAssets = async (ids: string[]) => { diff --git a/src/handlers/api/people.handler.ts b/src/handlers/api/people.handler.ts index bd901c6..f1d1d29 100644 --- a/src/handlers/api/people.handler.ts +++ b/src/handlers/api/people.handler.ts @@ -14,6 +14,7 @@ export interface IPersonListFilters { sortOrder?: "asc" | "desc"; type?: string; query?: string; + visibility?: "all" | "visible" | "hidden"; } export const listPeople = (filters: IPersonListFilters): Promise => { return API.get(LIST_PEOPLE_PATH, filters).then((response) => { diff --git a/src/pages/albums/potential-albums.tsx b/src/pages/albums/potential-albums.tsx index e11536e..e715b5a 100644 --- a/src/pages/albums/potential-albums.tsx +++ b/src/pages/albums/potential-albums.tsx @@ -8,6 +8,7 @@ import Header from "@/components/shared/Header"; import { AlertDialog } from "@/components/ui/alert-dialog"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; import { useToast } from "@/components/ui/use-toast"; import { useCurrentUser } from "@/contexts/CurrentUserContext"; import PotentialAlbumContext, { @@ -29,6 +30,7 @@ export default function PotentialAlbums() { startDate: startDate || undefined, selectedIds: [], assets: [], + minAssets: 1, }); const selectedAssets = useMemo(() => config.assets.filter((a) => config.selectedIds.includes(a.id)), [config.assets, config.selectedIds]); @@ -108,6 +110,19 @@ export default function PotentialAlbums() {
+ { + if (e.target.value) { + setConfig({ ...config, minAssets: parseInt(e.target.value) }); + } + }} + /> + + )} /> - -
-

- {config.selectedIds.length} Selected -

-
- {config.selectedIds.length && config.selectedIds.length > 0 ? ( - - ) : ( - - )} - - -
+ {selectedAssets.length && + +
+

+ {config.selectedIds.length} Selected +

+
+ + + - + > + Select all + + + +
+ + + + +
-
- + + } ); diff --git a/src/pages/api/albums/potential-albums-dates.ts b/src/pages/api/albums/potential-albums-dates.ts index 041cb27..ebbd867 100644 --- a/src/pages/api/albums/potential-albums-dates.ts +++ b/src/pages/api/albums/potential-albums-dates.ts @@ -3,52 +3,49 @@ import { db } from "@/config/db"; import { IPotentialAlbumsDatesResponse } from "@/handlers/api/album.handler"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; import { parseDate } from "@/helpers/date.helper"; -import { sql } from "drizzle-orm"; +import { albumsAssetsAssets } from "@/schema/albumAssetsAssets.schema"; +import { albums } from "@/schema/albums.schema"; +import { assets } from "@/schema/assets.schema"; +import { exif } from "@/schema/exif.schema"; +import { and, count, desc, eq, gte, isNotNull, isNull, sql } from "drizzle-orm"; import type { NextApiRequest, NextApiResponse } from "next"; +import { number } from "zod"; -const SELECT_ORPHAN_PHOTOS = (ownerId: string) => sql` -SELECT - DATE(e."dateTimeOriginal") AS "date", - COUNT(a."id") AS "asset_count" -FROM - "assets" a -LEFT JOIN - "albums_assets_assets" aaa ON a."id" = aaa."assetsId" -LEFT JOIN - "exif" e ON a."id" = e."assetId" -WHERE - aaa."albumsId" IS NULL - AND a."ownerId" = ${ownerId} - AND a."isVisible" = true - AND e."dateTimeOriginal" IS NOT NULL -GROUP BY - DATE(e."dateTimeOriginal") -ORDER BY - "asset_count" DESC; -`; export default async function handler( req: NextApiRequest, res: NextApiResponse ) { try { - const { sortBy = "date", sortOrder = "desc" } = req.query; + const { sortBy = "date", sortOrder = "desc", minAssets = 1 } = req.query as any; const currentUser = await getCurrentUser(req) - const data = await db.execute(SELECT_ORPHAN_PHOTOS(currentUser.id)) as any; - const rows = data.rows as IPotentialAlbumsDatesResponse[]; + const rows = await db.select({ + date: sql`DATE(${exif.dateTimeOriginal})`, + asset_count: desc(count(assets.id)), + }).from(assets) + .leftJoin(albumsAssetsAssets, eq(assets.id, albumsAssetsAssets.assetsId)) + .leftJoin(exif, eq(assets.id, exif.assetId)) + .where(and ( + eq(assets.ownerId, currentUser.id), + eq(assets.isVisible, true), + isNull(albumsAssetsAssets.albumsId), + isNotNull(exif.dateTimeOriginal), + + )) + .groupBy(sql`DATE(${exif.dateTimeOriginal})`) as IPotentialAlbumsDatesResponse[]; + + const filteredRows = rows.filter((row) => Number(row.asset_count) >= Number(minAssets)); if (sortBy === "date") { - rows.sort((a, b) => { - const aDate = parseDate(a.date, "yyyy-MM-dd"); - const bDate = parseDate(b.date, "yyyy-MM-dd"); + filteredRows.sort((a, b) => { + const aDate = parseDate(a.date as string, "yyyy-MM-dd"); + const bDate = parseDate(b.date as string, "yyyy-MM-dd"); return sortOrder === "asc" ? aDate.getTime() - bDate.getTime() : bDate.getTime() - aDate.getTime(); }); } else if (sortBy === "asset_count") { - rows.sort((a, b) => { - return sortOrder === "asc" ? a.asset_count - b.asset_count : b.asset_count - a.asset_count; - }); + filteredRows.sort((a, b) => sortOrder === "asc" ? a.asset_count - b.asset_count : b.asset_count - a.asset_count); } - return res.status(200).json(rows); + return res.status(200).json(filteredRows); } catch (error: any) { res.status(500).json({ error: error?.message, diff --git a/src/pages/api/assets/geo-heatmap.ts b/src/pages/api/assets/geo-heatmap.ts index ba5870a..e3d6eb0 100644 --- a/src/pages/api/assets/geo-heatmap.ts +++ b/src/pages/api/assets/geo-heatmap.ts @@ -3,26 +3,34 @@ import { NextApiResponse } from "next"; import { db } from "@/config/db"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; import { NextApiRequest } from "next"; -import { assets, exif } from "@/schema"; -import { and, eq, isNotNull } from "drizzle-orm"; +import { assetFaces, assets, exif, person } from "@/schema"; +import { and, eq, inArray, isNotNull } from "drizzle-orm"; +import { albumsAssetsAssets } from "@/schema/albumAssetsAssets.schema"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { const currentUser = await getCurrentUser(req); + const { albumIds, peopleIds } = req.query as { albumIds: string, peopleIds: string }; if (!currentUser) { return res.status(401).json({ message: 'Unauthorized' }); } + const dbAssets = await db.select({ assetId: assets.id, latitude: exif.latitude, longitude: exif.longitude, }).from(assets) .innerJoin(exif, eq(assets.id, exif.assetId)) + .innerJoin(albumsAssetsAssets, eq(assets.id, albumsAssetsAssets.assetsId)) + .innerJoin(assetFaces, eq(albumsAssetsAssets.assetsId, assetFaces.assetId)) + .innerJoin(person, eq(assetFaces.personId, person.id)) .where( and( eq(assets.ownerId, currentUser.id), isNotNull(exif.latitude), - isNotNull(exif.longitude) + isNotNull(exif.longitude), + albumIds?.length > 0 ? inArray(albumsAssetsAssets.albumsId, [albumIds]) : undefined, + peopleIds?.length > 0 ? inArray(person.id, [peopleIds]) : undefined ) ); const heatmapData = dbAssets.map((asset) => [ diff --git a/src/pages/api/people/list.ts b/src/pages/api/people/list.ts index 4dabcd0..8789d5f 100644 --- a/src/pages/api/people/list.ts +++ b/src/pages/api/people/list.ts @@ -29,6 +29,7 @@ interface IQuery { sort: ISortField; sortOrder: "asc" | "desc"; query: string; + visibility: "all" | "visible" | "hidden"; } export default async function handler( req: NextApiRequest, @@ -43,19 +44,21 @@ export default async function handler( sortOrder = "desc", type = "all", query = "", + visibility = "all", } = req.query as any as IQuery; const currentUser = await getCurrentUser(req); const maximumAssetCount = !maxValue || maxValue <= 0 ? 1000000 : maxValue; + const whereClause = and( - eq(person.isHidden, false), isNull(assets.duplicateId), eq(assets.isVisible, true), eq(assets.isArchived, false), eq(assets.ownerId, currentUser.id), type === "all" ? undefined : (type === "nameless" ? eq(person.name, "") : ne(person.name, "")), - query && query.length > 0 ? ilike(person.name, `%${query}%`) : undefined + query && query.length > 0 ? ilike(person.name, `%${query}%`) : undefined, + visibility === "visible" ? eq(person.isHidden, false) : visibility === "hidden" ? eq(person.isHidden, true) : undefined ); let dbQuery = db diff --git a/src/pages/assets/geo-heatmap.tsx b/src/pages/assets/geo-heatmap.tsx index fc1339c..94b376b 100644 --- a/src/pages/assets/geo-heatmap.tsx +++ b/src/pages/assets/geo-heatmap.tsx @@ -4,13 +4,19 @@ import React, { useEffect, useMemo, useState } from 'react' import { useMap, useMapsLibrary } from '@vis.gl/react-google-maps'; import { APIProvider, Map } from '@vis.gl/react-google-maps'; import PageLayout from '@/components/layouts/PageLayout'; -import { getAssetGeoHeatmap } from '@/handlers/api/asset.handler'; +import { getAssetGeoHeatmap, IHeatMapParams } from '@/handlers/api/asset.handler'; import { useTheme } from 'next-themes'; -import { MapPinX } from 'lucide-react'; +import { MapPinX, X } from 'lucide-react'; +import AlbumDropdown from '@/components/shared/AlbumDropdown'; +import PeopleDropdown from '@/components/shared/PeopleDropdown'; +import { Button } from '@/components/ui/button'; +interface IHeatMapProps { + filters: IHeatMapParams; +} + +const HeatMap = ({ filters }: IHeatMapProps) => { -const HeatMap = () => { - const map = useMap(); const visualization = useMapsLibrary('visualization'); @@ -27,14 +33,15 @@ const HeatMap = () => { useEffect(() => { if (!heatmap) return; - getAssetGeoHeatmap().then((data) => { + getAssetGeoHeatmap(filters).then((data) => { + heatmap.setData([]); heatmap.setData(data.map(([lng, lat]: [number, number]) => ({ location: new google.maps.LatLng(lat, lng), weight: 10 }))); }); - }, [heatmap]); + }, [heatmap, filters]); useEffect(() => { if (!heatmap) return; @@ -53,6 +60,10 @@ export default function GeoHeatmap() { const { googleMapsApiKey } = useConfig(); const { theme } = useTheme(); const [mapId, setMapId] = useState('7a9e2ebecd32a903'); + const [filters, setFilters] = useState<{ + albumIds?: string + peopleIds?: string + }>({ }); useEffect(() => { if (theme === 'light') { @@ -65,21 +76,42 @@ export default function GeoHeatmap() { return ( -
+
+ { + setFilters({ + ...filters, + albumIds: albumIds?.[0] + }) + }} /> + { + setFilters({ + ...filters, + peopleIds: peopleIds?.[0] + }) + }} /> + + + } />
{googleMapsApiKey ? ( - + - - + + ) : (
diff --git a/src/pages/assets/missing-locations.tsx b/src/pages/assets/missing-locations.tsx index cbdc167..2105088 100644 --- a/src/pages/assets/missing-locations.tsx +++ b/src/pages/assets/missing-locations.tsx @@ -13,6 +13,7 @@ import { deleteAssets, updateAssets } from "@/handlers/api/asset.handler"; import { IPlace } from "@/types/common"; import { SortDesc, SortAsc } from "lucide-react"; +import { isSameDay } from "date-fns"; import { useRouter } from "next/router"; import React, { useMemo } from "react"; import FloatingBar from "@/components/shared/FloatingBar"; @@ -29,21 +30,41 @@ export default function MissingLocations() { assets: [], sort: "fileOriginalDate", sortOrder: "asc", + dates: [] }); const selectedAssets = useMemo(() => config.assets.filter((a) => config.selectedIds.includes(a.id)), [config.assets, config.selectedIds]); - const handleSubmit = (place: IPlace) => { - return updateAssets({ + const handleSubmit = async (place: IPlace) => { + await updateAssets({ ids: config.selectedIds, - latitude: place.latitude, - longitude: place.longitude, - }).then(() => { - setConfig({ - ...config, - selectedIds: [], - }); - }) + latitude: Number(place.latitude), + longitude: Number(place.longitude), + }); + + const newAssets = config.assets.filter(asset => !config.selectedIds.includes(asset.id)); + + if (config.startDate) { + const dayRecord = config.dates.filter(f => isSameDay(new Date(f.value), new Date(config.startDate!))); + + if (dayRecord.length === 1) { + if (newAssets.length > 0) + dayRecord[0].asset_count = newAssets.length; + else { + const indexToRemove = config.dates.findIndex(v=>isSameDay(v.value, dayRecord[0].value)); + + if (indexToRemove !== -1) { + config.dates.splice(indexToRemove, 1); + } + } + } + } + + setConfig({ + ...config, + selectedIds: [], + assets: newAssets + }); }; const handleDelete = () => { @@ -110,57 +131,58 @@ export default function MissingLocations() {
- -
-

- {config.selectedIds.length} Selected -

-
- {config.selectedIds.length === config.assets.length ? ( - + ) : ( + + )} + {/* Seperator */} + + +
+ - Unselect all - - ) : ( - - )} - {/* Seperator */} - - - -
- - - + +
+
-
- + + } ); diff --git a/src/styles/globals.scss b/src/styles/globals.scss index fc4c145..afc4d8c 100644 --- a/src/styles/globals.scss +++ b/src/styles/globals.scss @@ -92,4 +92,10 @@ #ReactGridGallery img { max-width: none !important; height: none !important; +} + +.dark { + .ReactGridGallery_tile { + @apply bg-zinc-800 !important; + } } \ No newline at end of file