Merge pull request #136 from varun-raj/pre-release

Feb Release
This commit is contained in:
Varun Raj Manoharan authored and GitHub committed 2025-02-06 20:30:30 +05:30
commit 4f94bcf0cb
27 files changed
+497 -221

No files matched your search

@@ -36,7 +36,7 @@ export default function AlbumThumbnail({ album, onSelect, selected }: IAlbumThum
}}
/>
<div className="absolute bottom-0 w-full bg-gray-800/70 text-white text-center text-xs font-bold py-1 group-hover:hidden">
{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') : ''}
</div>
<Checkbox
defaultChecked={isSelected}
@@ -12,7 +12,7 @@ import { ArrowDown, ArrowUp, ArrowUpDownIcon, SortAsc, SortDesc } from "lucide-r
export default function PotentialAlbumsDates() {
const router = useRouter();
const { updateContext } = usePotentialAlbumContext();
const { updateContext, minAssets } = usePotentialAlbumContext();
const [dateRecords, setDateRecords] = React.useState<
IPotentialAlbumsDatesResponse[]
>([]);
@@ -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 (
<div className="min-w-[200px] py-4 max-h-[calc(100vh-60px)] min-h-[calc(100vh-60px)] border-r border-gray-200 dark:border-zinc-800 flex flex-col gap-2 px-1">
@@ -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<HTMLElement>) => {
if (selectedIds.length > 0) {
handleSelect(idx, asset, event);
}
else
{
setIndex(idx);
}
};
const handleSelect = (_idx: number, asset: IAsset, event: MouseEvent<HTMLElement>) => {
event.stopPropagation();
@@ -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<HTMLDivElement | null>(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}
>
<p className="text-sm truncate">{dateLabel}</p>
<p className="text-xs text-foreground/50">{record.asset_count} Orphan Assets</p>
<p className="text-xs text-foreground/50">{record.asset_count} Assets</p>
</div>
);
}
@@ -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
</div>
</div>
<div className="overflow-y-auto flex flex-col gap-2">
{dateRecords.map((record) => (
{dates.map((record) => (
<MissingLocationDateItem
key={record.value}
record={record}
@@ -46,19 +46,19 @@ export default function TagMissingLocationDialog({
Tagging a location will add the location to the selected assets.
</DialogDescription>
</DialogHeader>
<Tabs defaultValue="search" className="border rounded-lg">
<Tabs defaultValue="searchOsm" className="border rounded-lg">
<TabsList className="flex justify-between">
<TabsTrigger value="search">Immich Search</TabsTrigger>
<TabsTrigger value="searchOsm">OSM Search</TabsTrigger>
<TabsTrigger value="latlong">Lat &amp; Long</TabsTrigger>
<TabsTrigger value="maps">Map</TabsTrigger>
<TabsTrigger value="searchOsm" className="w-full">Open Street Map</TabsTrigger>
<TabsTrigger value="search" className="w-full">Immich Geo</TabsTrigger>
<TabsTrigger value="latlong" className="w-full">Lat &amp; Long</TabsTrigger>
<TabsTrigger value="maps" className="w-full">Map</TabsTrigger>
</TabsList>
<TabsContent value="search">
<TagMissingLocationSearchAndAdd onSubmit={onSubmit} onOpenChange={setOpen} />
</TabsContent>
<TabsContent value="searchOsm">
<TagMissingLocationOSMSearchAndAdd onSubmit={onSubmit} onOpenChange={setOpen} location={mapPosition} onLocationChange={setMapPosition} />
</TabsContent>
<TabsContent value="search">
<TagMissingLocationSearchAndAdd onSubmit={onSubmit} onOpenChange={setOpen} />
</TabsContent>
<TabsContent value="latlong">
<TagMissingLocationSearchLatLong onSubmit={onSubmit} onOpenChange={setOpen} location={mapPosition} onLocationChange={setMapPosition} />
</TabsContent>
@@ -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 (
<div className="flex flex-col gap-4 py-4 px-2">
<div className="flex flex-col gap-2">
<Label>Search Location</Label>
<Input
placeholder="Search location"
onChange={(e) => {
handleSearch(e.target.value);
}}
/>
</div>
<div>
{loading && <Loader />}
{!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,
}
)}
>
<div>
<p>{place.name}</p>
<span className="text-xs text-gray-600">
<p className="text-sm">{place.name}</p>
<span className="text-xs text-gray-600 dark:text-gray-400">
{place.latitude}, {place.longitude}
</span>
</div>
{selectedPlace && selectedPlace.name === place.name && (
<Check className="text-green-500" />
<Check className="text-green-500 dark:text-green-400" />
)}
</div>
))}
@@ -176,11 +172,11 @@ export default function TagMissingLocationOSMSearchAndAdd(
</div>
<div className="self-end">
<Button
variant="outline"
variant="default"
onClick={handleSubmit}
disabled={!selectedPlace || submitting}
>
Add New Location
Tag Location
</Button>
</div>
</div>
@@ -96,7 +96,6 @@ export default function TagMissingLocationSearchAndAdd(
return (
<div className="flex flex-col gap-4 py-4 px-2">
<div className="flex flex-col gap-2">
<Label>Search Location</Label>
<Input
placeholder="Search location"
onChange={(e) => {
@@ -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,
}
)}
>
<div>
<p>{place.name}</p>
<span className="text-xs text-gray-600">
<span className="text-xs text-gray-600 dark:text-gray-200">
{place.latitude}, {place.longitude}
</span>
</div>
{selectedPlace && selectedPlace.name === place.name && (
<Check className="text-green-500" />
<Check className="text-green-500 dark:text-green-400" />
)}
</div>
))}
@@ -139,11 +138,11 @@ export default function TagMissingLocationSearchAndAdd(
</div>
<div className="self-end">
<Button
variant="outline"
variant="default"
onClick={handleSubmit}
disabled={!selectedPlace || submitting}
>
Add New Location
Tag Location
</Button>
</div>
</div>
+21 -3
View File
@@ -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<IPersonListFilters>) => {
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() {
</SelectContent>
</Select>
<Select value={visibility} onValueChange={(value) => handleChange({ visibility: value as "all" | "visible" | "hidden" })}>
<SelectTrigger>
<SelectValue placeholder="Visibility" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">All</SelectItem>
<SelectItem value="visible">Visible</SelectItem>
<SelectItem value="hidden">Hidden</SelectItem>
</SelectContent>
</Select>
<Button
disabled={prevPage < 1}
onClick={() => handleChange({ page: prevPage })}
+1 -1
View File
@@ -107,7 +107,7 @@ export default function PersonItem({ person, onRemove }: IProps) {
<Button variant="outline" className="!py-0.5 !px-2 text-xs h-7" onClick={() => {
handleHide(!formData.isHidden);
}}>
Hide
{formData.isHidden ? "Show" : "Hide"}
</Button>
<ShareAssetsTrigger filters={{ personIds: [person.id] }} buttonProps={{ variant: "outline", className: "!py-0.5 !px-2 text-xs h-7" }} />
</div>
+63
View File
@@ -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<IAlbum[]>([]);
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 (
<div>
<Select
onValueChange={(value) => {
if (value) {
setSelectedAlbumIds([value])
onChange([value])
} else {
setSelectedAlbumIds([])
onChange([])
}
}}
value={selectedAlbumIds?.[0] ?? ""}
>
<SelectTrigger className='!p-2'>
<SelectValue placeholder={'Select album'} />
</SelectTrigger>
<SelectContent>
{albums.map((album) => (
<SelectItem key={album.id} value={album.id}>{album.albumName}</SelectItem>
))}
</SelectContent>
</Select>
</div>
)
}
+17 -8
View File
@@ -20,6 +20,15 @@ export default function AssetGrid({ assets, isInternal = true, selectable = fals
const [selectedIds, setSelectedIds] = useState<string[]>([]);
const [lastSelectedIndex, setLastSelectedIndex] = useState(-1);
const handleClick = (index: number, asset: IAsset, event: React.MouseEvent<HTMLElement>) => {
if (selectedIds.length > 0) {
handleSelect(index, asset, event);
} else {
setIndex(index);
}
}
const handleSelect = (_idx: number, asset: IAsset, event: React.MouseEvent<HTMLElement>) => {
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
/>
<Gallery
images={images}
onClick={setIndex}
onClick={handleClick}
enableImageSelection={selectable}
thumbnailImageComponent={LazyGridImage}
onSelect={handleSelect}
+63
View File
@@ -0,0 +1,63 @@
import React, { useEffect, useState } from 'react'
import { IPerson } from '@/types/person';
import { IPersonListFilters, listPeople } from '@/handlers/api/people.handler';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
interface IPeopleDropdownProps {
peopleIds?: string[];
onChange: (peopleIds: string[]) => void;
}
export default function PeopleDropdown({ peopleIds, onChange }: IPeopleDropdownProps) {
const [people, setPeople] = useState<IPerson[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const [selectedPeopleIds, setSelectedPeopleIds] = useState(peopleIds);
const [filters, setFilters] = useState<IPersonListFilters>({
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 (
<div>
<Select onValueChange={(value) => {
if (value) {
setSelectedPeopleIds([value])
onChange([value])
} else {
setSelectedPeopleIds([])
onChange([])
}
}} value={selectedPeopleIds?.[0] ?? ""}>
<SelectTrigger className='!p-2'>
<SelectValue placeholder={'Select people'} />
</SelectTrigger>
<SelectContent >
{people.map((person) => (
<SelectItem key={person.id} value={person.id}>{person.name}</SelectItem>
))}
</SelectContent>
</Select>
</div>
)
}
+14 -5
View File
@@ -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 && (
<>
<p className="text-sm">{user?.name}</p>
{!user.isUsingAPIKey && (
<Button variant="destructive" className="mx-4 h-6 text-xs" onClick={handleLogout}>
Log Out
</Button>
)}
<div className="flex items-center justify-between gap-2 px-2">
{!user.isUsingAPIKey && (
<Button variant="destructive" className="h-6 flex-1 text-xs" onClick={handleLogout}>
Log Out
</Button>
)}
<Button asChild variant="secondary" className="h-6 flex-1 text-xs flex items-center justify-center gap-2" onClick={handleLogout}>
<Link href="https://buymeacoffee.com/varunraj" target="_blank">
<HandshakeIcon className="w-4 h-4" />
Support
</Link>
</Button>
</div>
</>
)}
</div>
+8 -2
View File
@@ -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 (
<Popover open={open} onOpenChange={(openState) => {
setOpen(openState)
onOpenChange?.(openState)
}}>
<PopoverTrigger asChild>
<Filter />
<div className="flex items-center text-sm gap-2 cursor-pointer">
<Filter size={16} />
<span>{label}</span>
</div>
</PopoverTrigger>
<PopoverContent className="w-[200px] p-0">
<Command>
+3
View File
@@ -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<MissingLocationContext>({
startDate: undefined,
albumId: undefined,
dates: [],
selectedIds: [],
assets: [],
updateContext: () => { },
+2
View File
@@ -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<IPotentialAlbumContext>({
startDate: undefined,
selectedIds: [],
assets: [],
minAssets: 1,
updateContext: () => { },
});
+1
View File
@@ -9,6 +9,7 @@ interface IPotentialAlbumsDatesFilters {
endDate?: string;
sortBy?: string;
sortOrder?: string;
minAssets?: number;
}
export interface IPotentialAlbumsDatesResponse {
date: string;
+6 -2
View File
@@ -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[]) => {
+1
View File
@@ -14,6 +14,7 @@ export interface IPersonListFilters {
sortOrder?: "asc" | "desc";
type?: string;
query?: string;
visibility?: "all" | "visible" | "hidden";
}
export const listPeople = (filters: IPersonListFilters): Promise<IPeopleListResponse> => {
return API.get(LIST_PEOPLE_PATH, filters).then((response) => {
+64 -49
View File
@@ -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() {
<PageLayout className="!p-0 !mb-0 relative">
<Header
leftComponent="Potential Albums"
rightComponent={(
<div className="flex items-center gap-2">
<Input
placeholder="Minimum Assets Count"
defaultValue={config.minAssets}
onChange={(e) => {
if (e.target.value) {
setConfig({ ...config, minAssets: parseInt(e.target.value) });
}
}}
/>
</div>
)}
/>
<PotentialAlbumContext.Provider
value={{
@@ -120,57 +135,57 @@ export default function PotentialAlbums() {
<PotentialAlbumsDates />
<PotentialAlbumsAssets />
</div>
<FloatingBar>
<div className="flex items-center gap-2 justify-between w-full">
<p className="text-sm text-muted-foreground">
{config.selectedIds.length} Selected
</p>
<div className="flex items-center gap-2">
{config.selectedIds.length && config.selectedIds.length > 0 ? (
<Button
variant={"outline"}
size={"sm"}
onClick={() =>
setConfig({
...config,
selectedIds: [],
})
}
>
Unselect all
</Button>
) : (
<Button
variant={"outline"}
size={"sm"}
onClick={() =>
setConfig({
...config,
selectedIds: config.assets.map((a) => a.id),
})
}
>
Select all
</Button>
)}
<AlbumSelectorDialog onSelected={handleSelect} onSubmit={handleCreate}/>
<AssetOffsetDialog assets={selectedAssets} onComplete={handleOffsetComplete} />
<div className="h-[10px] w-[1px] bg-zinc-500 dark:bg-zinc-600"></div>
{selectedAssets.length &&
<FloatingBar>
<div className="flex items-center gap-2 justify-between w-full">
<p className="text-sm text-muted-foreground">
{config.selectedIds.length} Selected
</p>
<div className="flex items-center gap-2">
<Button
variant={"outline"}
size={"sm"}
onClick={() =>
setConfig({
...config,
selectedIds: [],
})
}
>
Unselect all
</Button>
<Button
variant={"outline"}
size={"sm"}
onClick={() =>
setConfig({
...config,
selectedIds: config.assets.map((a) => a.id),
})
}
<AlertDialog
title="Delete the selected assets?"
description="This action will delete the selected assets and cannot be undone."
onConfirm={handleDelete}
disabled={config.selectedIds.length === 0}
>
<Button variant={"destructive"} size={"sm"} disabled={config.selectedIds.length === 0}>
Delete
</Button>
</AlertDialog>
>
Select all
</Button>
<AlbumSelectorDialog onSelected={handleSelect} onSubmit={handleCreate} />
<AssetOffsetDialog assets={selectedAssets} onComplete={handleOffsetComplete} />
<div className="h-[10px] w-[1px] bg-zinc-500 dark:bg-zinc-600"></div>
<AlertDialog
title="Delete the selected assets?"
description="This action will delete the selected assets and cannot be undone."
onConfirm={handleDelete}
disabled={config.selectedIds.length === 0}
>
<Button variant={"destructive"} size={"sm"} disabled={config.selectedIds.length === 0}>
Delete
</Button>
</AlertDialog>
</div>
</div>
</div>
</FloatingBar>
</FloatingBar>
}
</PotentialAlbumContext.Provider>
</PageLayout>
);
+28 -31
View File
@@ -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,
+11 -3
View File
@@ -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) => [
+5 -2
View File
@@ -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
+49 -17
View File
@@ -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 (
<PageLayout className="!p-0 !mb-0">
<Header leftComponent="Geo Heatmap" />
<Header leftComponent="Geo Heatmap" rightComponent={
<>
<AlbumDropdown albumIds={filters.albumIds ? [filters.albumIds] : []} onChange={(albumIds) => {
setFilters({
...filters,
albumIds: albumIds?.[0]
})
}} />
<PeopleDropdown peopleIds={filters.peopleIds ? [filters.peopleIds] : []} onChange={(peopleIds) => {
setFilters({
...filters,
peopleIds: peopleIds?.[0]
})
}} />
<Button
variant="default" size="sm"
disabled={Object.keys(filters).length === 0}
onClick={() => setFilters({})}>
<X size={16} /> Clear
</Button>
</>
} />
<div className='h-full w-full'>
{googleMapsApiKey ? (
<APIProvider apiKey={googleMapsApiKey}>
<Map
defaultCenter={{ lat: 0, lng: 0 }}
mapId={mapId}
defaultZoom={2}
gestureHandling={'greedy'}
disableDefaultUI={true}
className='h-full w-full'
/>
<Map
defaultCenter={{ lat: 0, lng: 0 }}
mapId={mapId}
defaultZoom={2}
gestureHandling={'greedy'}
disableDefaultUI={true}
className='h-full w-full'
/>
<HeatMap />
</APIProvider>
<HeatMap filters={filters} />
</APIProvider>
) : (
<div className='h-full w-full flex items-center justify-center flex-col gap-2'>
<MapPinX className='w-10 h-10 text-muted-foreground' />
+81 -59
View File
@@ -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() {
<MissingLocationDates groupBy={groupBy as "date" | "album"} />
<MissingLocationAssets groupBy={groupBy as "date" | "album"} />
</div>
<FloatingBar>
<div className="flex items-center gap-2 justify-between w-full">
<p className="text-sm text-muted-foreground">
{config.selectedIds.length} Selected
</p>
<div className="flex items-center gap-2">
{config.selectedIds.length === config.assets.length ? (
<Button
variant={"outline"}
size={"sm"}
onClick={() =>
setConfig({
...config,
selectedIds: [],
})
}
{selectedAssets.length &&
<FloatingBar>
<div className="flex items-center gap-2 justify-between w-full">
<p className="text-sm text-muted-foreground">
{config.selectedIds.length} Selected
</p>
<div className="flex items-center gap-2">
{config.selectedIds.length === config.assets.length ? (
<Button
variant={"outline"}
size={"sm"}
onClick={() =>
setConfig({
...config,
selectedIds: [],
})
}
>
Unselect all
</Button>
) : (
<Button
variant={"outline"}
size={"sm"}
onClick={() =>
setConfig({
...config,
selectedIds: config.assets.map((a) => a.id),
})
}
>
Select all
</Button>
)}
{/* Seperator */}
<TagMissingLocationDialog onSubmit={handleSubmit} />
<AssetOffsetDialog assets={selectedAssets} onComplete={handleOffsetComplete} />
<div className="h-[10px] w-[1px] bg-zinc-500 dark:bg-zinc-600"></div>
<AlertDialog
title="Delete the selected assets?"
description="This action will delete the selected assets and cannot be undone."
onConfirm={handleDelete}
disabled={config.selectedIds.length === 0}
>
Unselect all
</Button>
) : (
<Button
variant={"outline"}
size={"sm"}
onClick={() =>
setConfig({
...config,
selectedIds: config.assets.map((a) => a.id),
})
}
>
Select all
</Button>
)}
{/* Seperator */}
<TagMissingLocationDialog onSubmit={handleSubmit} />
<AssetOffsetDialog assets={selectedAssets} onComplete={handleOffsetComplete} />
<div className="h-[10px] w-[1px] bg-zinc-500 dark:bg-zinc-600"></div>
<AlertDialog
title="Delete the selected assets?"
description="This action will delete the selected assets and cannot be undone."
onConfirm={handleDelete}
disabled={config.selectedIds.length === 0}
>
<Button variant={"destructive"} size={"sm"} disabled={config.selectedIds.length === 0}>
Delete
</Button>
</AlertDialog>
<Button variant={"destructive"} size={"sm"} disabled={config.selectedIds.length === 0}>
Delete
</Button>
</AlertDialog>
</div>
</div>
</div>
</FloatingBar>
</FloatingBar>
}
</MissingLocationContext.Provider>
</PageLayout>
);
+6
View File
@@ -92,4 +92,10 @@
#ReactGridGallery img {
max-width: none !important;
height: none !important;
}
.dark {
.ReactGridGallery_tile {
@apply bg-zinc-800 !important;
}
}