Skip to content

Commit

Permalink
fix: conflicts resolved
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Raj <[email protected]>
  • Loading branch information
varun-raj committed Jan 26, 2025
2 parents f173562 + 80d2cce commit 0c37a08
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
11 changes: 4 additions & 7 deletions src/components/assets/missing-location/MissingLocationDates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,21 @@ 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);

const [errorMessage, setErrorMessage] = useState<string | null>(null);

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));
};
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export default function TagMissingLocationOSMSearchAndAdd(
setSelectedPlace(null);
} else {
setSelectedPlace(place);
debugger;
onLocationChange(place);
}
};
Expand Down Expand Up @@ -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>
))}
Expand Down
3 changes: 3 additions & 0 deletions src/contexts/MissingLocationContext.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IMissingLocationDatesResponse } from "@/handlers/api/asset.handler";
import { IAsset } from "@/types/asset";
import { createContext, useContext } from "react";

Expand All @@ -8,6 +9,7 @@ export interface IMissingLocationConfig {
assets: IAsset[];
sort: "fileOriginalDate";
sortOrder: "asc"|"desc";
dates: IMissingLocationDatesResponse[];
}

export interface MissingLocationContext extends IMissingLocationConfig {
Expand All @@ -16,6 +18,7 @@ export interface MissingLocationContext extends IMissingLocationConfig {
const MissingLocationContext = createContext<MissingLocationContext>({
startDate: undefined,
albumId: undefined,
dates: [],
selectedIds: [],
assets: [],
updateContext: () => { },
Expand Down
42 changes: 31 additions & 11 deletions src/pages/assets/missing-locations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 = () => {
Expand Down

0 comments on commit 0c37a08

Please sign in to comment.