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) => (
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.latitude}, {place.longitude}
{selectedPlace && selectedPlace.name === place.name && (
-
+
)}
))}
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/pages/assets/missing-locations.tsx b/src/pages/assets/missing-locations.tsx
index a395a77..2105088 100644
--- a/src/pages/assets/missing-locations.tsx
+++ b/src/pages/assets/missing-locations.tsx
@@ -13,13 +13,13 @@ 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";
import { Select, SelectValue, SelectTrigger, SelectContent, SelectItem } from "@/components/ui/select";
import { AlertDialog } from "@/components/ui/alert-dialog";
import AssetOffsetDialog from "@/components/assets/assets-options/AssetOffsetDialog";
-import { Input } from "@/components/ui/input";
export default function MissingLocations() {
const { query, push } = useRouter();
@@ -30,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 = () => {