@@ -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}
|
||||
|
||||
+4
-5
@@ -96,7 +96,6 @@ export default function TagMissingLocationOSMSearchAndAdd(
|
||||
setSelectedPlace(null);
|
||||
} else {
|
||||
setSelectedPlace(place);
|
||||
debugger;
|
||||
onLocationChange(place);
|
||||
}
|
||||
};
|
||||
@@ -150,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 className="text-sm">{place.name}</p>
|
||||
<span className="text-xs text-gray-600">
|
||||
<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>
|
||||
))}
|
||||
|
||||
@@ -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: () => { },
|
||||
|
||||
@@ -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 = () => {
|
||||
|
||||
Reference in New Issue
Block a user