commit
0c37a08542
4 files changed
+42
-23
No files matched your search
@@ -13,11 +13,8 @@ interface IMissingLocationDatesProps {
|
|||||||
|
|
||||||
}
|
}
|
||||||
export default function MissingLocationDates({ groupBy }: IMissingLocationDatesProps) {
|
export default function MissingLocationDates({ groupBy }: IMissingLocationDatesProps) {
|
||||||
const { updateContext } = useMissingLocationContext();
|
const { dates, updateContext } = useMissingLocationContext();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [dateRecords, setDateRecords] = React.useState<
|
|
||||||
IMissingLocationDatesResponse[]
|
|
||||||
>([]);
|
|
||||||
const [filters, setFilters] = useState<{ sortBy: string, sortOrder: string }>({ sortBy: "date", sortOrder: "desc" });
|
const [filters, setFilters] = useState<{ sortBy: string, sortOrder: string }>({ sortBy: "date", sortOrder: "desc" });
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
@@ -25,12 +22,12 @@ export default function MissingLocationDates({ groupBy }: IMissingLocationDatesP
|
|||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
const func = groupBy === "album" ? listMissingLocationAlbums : listMissingLocationDates
|
const func = groupBy === "album" ? listMissingLocationAlbums : listMissingLocationDates
|
||||||
setDateRecords([])
|
updateContext({ dates: [] })
|
||||||
return func({
|
return func({
|
||||||
sortBy: filters.sortBy,
|
sortBy: filters.sortBy,
|
||||||
sortOrder: filters.sortOrder,
|
sortOrder: filters.sortOrder,
|
||||||
})
|
})
|
||||||
.then(setDateRecords)
|
.then((r) => updateContext({ dates: r }))
|
||||||
.catch(setErrorMessage)
|
.catch(setErrorMessage)
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
@@ -96,7 +93,7 @@ export default function MissingLocationDates({ groupBy }: IMissingLocationDatesP
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="overflow-y-auto flex flex-col gap-2">
|
<div className="overflow-y-auto flex flex-col gap-2">
|
||||||
{dateRecords.map((record) => (
|
{dates.map((record) => (
|
||||||
<MissingLocationDateItem
|
<MissingLocationDateItem
|
||||||
key={record.value}
|
key={record.value}
|
||||||
record={record}
|
record={record}
|
||||||
|
|||||||
+4
-5
@@ -96,7 +96,6 @@ export default function TagMissingLocationOSMSearchAndAdd(
|
|||||||
setSelectedPlace(null);
|
setSelectedPlace(null);
|
||||||
} else {
|
} else {
|
||||||
setSelectedPlace(place);
|
setSelectedPlace(place);
|
||||||
debugger;
|
|
||||||
onLocationChange(place);
|
onLocationChange(place);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -150,21 +149,21 @@ export default function TagMissingLocationOSMSearchAndAdd(
|
|||||||
key={place.name}
|
key={place.name}
|
||||||
onClick={() => handleSelect(place)}
|
onClick={() => handleSelect(place)}
|
||||||
className={cn(
|
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,
|
selectedPlace && selectedPlace.name === place.name,
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<p className="text-sm">{place.name}</p>
|
<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}
|
{place.latitude}, {place.longitude}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{selectedPlace && selectedPlace.name === place.name && (
|
{selectedPlace && selectedPlace.name === place.name && (
|
||||||
<Check className="text-green-500" />
|
<Check className="text-green-500 dark:text-green-400" />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { IMissingLocationDatesResponse } from "@/handlers/api/asset.handler";
|
||||||
import { IAsset } from "@/types/asset";
|
import { IAsset } from "@/types/asset";
|
||||||
import { createContext, useContext } from "react";
|
import { createContext, useContext } from "react";
|
||||||
|
|
||||||
@@ -8,6 +9,7 @@ export interface IMissingLocationConfig {
|
|||||||
assets: IAsset[];
|
assets: IAsset[];
|
||||||
sort: "fileOriginalDate";
|
sort: "fileOriginalDate";
|
||||||
sortOrder: "asc"|"desc";
|
sortOrder: "asc"|"desc";
|
||||||
|
dates: IMissingLocationDatesResponse[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MissingLocationContext extends IMissingLocationConfig {
|
export interface MissingLocationContext extends IMissingLocationConfig {
|
||||||
@@ -16,6 +18,7 @@ export interface MissingLocationContext extends IMissingLocationConfig {
|
|||||||
const MissingLocationContext = createContext<MissingLocationContext>({
|
const MissingLocationContext = createContext<MissingLocationContext>({
|
||||||
startDate: undefined,
|
startDate: undefined,
|
||||||
albumId: undefined,
|
albumId: undefined,
|
||||||
|
dates: [],
|
||||||
selectedIds: [],
|
selectedIds: [],
|
||||||
assets: [],
|
assets: [],
|
||||||
updateContext: () => { },
|
updateContext: () => { },
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ import { deleteAssets, updateAssets } from "@/handlers/api/asset.handler";
|
|||||||
|
|
||||||
import { IPlace } from "@/types/common";
|
import { IPlace } from "@/types/common";
|
||||||
import { SortDesc, SortAsc } from "lucide-react";
|
import { SortDesc, SortAsc } from "lucide-react";
|
||||||
|
import { isSameDay } from "date-fns";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import React, { useMemo } from "react";
|
import React, { useMemo } from "react";
|
||||||
import FloatingBar from "@/components/shared/FloatingBar";
|
import FloatingBar from "@/components/shared/FloatingBar";
|
||||||
import { Select, SelectValue, SelectTrigger, SelectContent, SelectItem } from "@/components/ui/select";
|
import { Select, SelectValue, SelectTrigger, SelectContent, SelectItem } from "@/components/ui/select";
|
||||||
import { AlertDialog } from "@/components/ui/alert-dialog";
|
import { AlertDialog } from "@/components/ui/alert-dialog";
|
||||||
import AssetOffsetDialog from "@/components/assets/assets-options/AssetOffsetDialog";
|
import AssetOffsetDialog from "@/components/assets/assets-options/AssetOffsetDialog";
|
||||||
import { Input } from "@/components/ui/input";
|
|
||||||
|
|
||||||
export default function MissingLocations() {
|
export default function MissingLocations() {
|
||||||
const { query, push } = useRouter();
|
const { query, push } = useRouter();
|
||||||
@@ -30,21 +30,41 @@ export default function MissingLocations() {
|
|||||||
assets: [],
|
assets: [],
|
||||||
sort: "fileOriginalDate",
|
sort: "fileOriginalDate",
|
||||||
sortOrder: "asc",
|
sortOrder: "asc",
|
||||||
|
dates: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const selectedAssets = useMemo(() => config.assets.filter((a) => config.selectedIds.includes(a.id)), [config.assets, config.selectedIds]);
|
const selectedAssets = useMemo(() => config.assets.filter((a) => config.selectedIds.includes(a.id)), [config.assets, config.selectedIds]);
|
||||||
|
|
||||||
const handleSubmit = (place: IPlace) => {
|
const handleSubmit = async (place: IPlace) => {
|
||||||
return updateAssets({
|
await updateAssets({
|
||||||
ids: config.selectedIds,
|
ids: config.selectedIds,
|
||||||
latitude: place.latitude,
|
latitude: Number(place.latitude),
|
||||||
longitude: place.longitude,
|
longitude: Number(place.longitude),
|
||||||
}).then(() => {
|
});
|
||||||
setConfig({
|
|
||||||
...config,
|
const newAssets = config.assets.filter(asset => !config.selectedIds.includes(asset.id));
|
||||||
selectedIds: [],
|
|
||||||
});
|
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 = () => {
|
const handleDelete = () => {
|
||||||
|
|||||||
Reference in new issue
Block a user