fixes trail multi save bug
This commit is contained in:
@@ -184,9 +184,11 @@ export async function trails_create(trail: Trail, photos: File[], gpx: File | Bl
|
||||
|
||||
trail.author = pb.authStore.model!.id
|
||||
|
||||
let r = await f('/api/v1/trail', {
|
||||
let r = await f(`/api/v1/trail?` + new URLSearchParams({
|
||||
expand: "category,waypoints,summit_logs,trail_share_via_trail",
|
||||
}), {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ ...trail, expand: undefined }),
|
||||
body: JSON.stringify({ ...trail }),
|
||||
})
|
||||
|
||||
if (!r.ok) {
|
||||
@@ -216,7 +218,7 @@ export async function trails_create(trail: Trail, photos: File[], gpx: File | Bl
|
||||
throw new APIError(r.status, response.message, response.detail)
|
||||
}
|
||||
|
||||
return await r.json();
|
||||
return model;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,16 @@ export async function GET(event: RequestEvent) {
|
||||
export async function PUT(event: RequestEvent) {
|
||||
try {
|
||||
const r = await create<Trail>(event, TrailCreateSchema, Collection.trails)
|
||||
enrichRecord(r);
|
||||
return json(r);
|
||||
} catch (e) {
|
||||
throw handleError(e)
|
||||
}
|
||||
}
|
||||
|
||||
function enrichRecord(r: Trail) {
|
||||
r.date = r.date?.substring(0, 10) ?? "";
|
||||
for (const log of r.expand?.summit_logs ?? []) {
|
||||
log.date = log.date.substring(0, 10);
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@
|
||||
|
||||
let autoRouting = $state(true);
|
||||
|
||||
let listAddEnabled = $state(false);
|
||||
let savedAtLeastOnce = $state(false);
|
||||
|
||||
const {
|
||||
form,
|
||||
@@ -182,13 +182,14 @@
|
||||
?.trkpt?.at(0)?.$.lon;
|
||||
}
|
||||
|
||||
if (page.params.id === "new") {
|
||||
if (page.params.id === "new" && !savedAtLeastOnce) {
|
||||
const createdTrail = await trails_create(
|
||||
form as Trail,
|
||||
photoFiles,
|
||||
gpxFile,
|
||||
);
|
||||
form.id = createdTrail.id;
|
||||
setFields(createdTrail);
|
||||
trail.set(createdTrail);
|
||||
} else {
|
||||
const updatedTrail = await trails_update(
|
||||
$trail,
|
||||
@@ -199,7 +200,7 @@
|
||||
setFields(updatedTrail);
|
||||
}
|
||||
|
||||
listAddEnabled = true;
|
||||
savedAtLeastOnce = true;
|
||||
show_toast({
|
||||
type: "success",
|
||||
icon: "check",
|
||||
@@ -456,9 +457,6 @@
|
||||
log,
|
||||
];
|
||||
}
|
||||
|
||||
console.log($formData.expand?.summit_logs);
|
||||
|
||||
}
|
||||
|
||||
function handleSummitLogMenuClick(
|
||||
@@ -1093,7 +1091,7 @@
|
||||
<Button
|
||||
secondary={true}
|
||||
tooltip={$_("save-your-trail-first")}
|
||||
disabled={page.params.id == "new" && !listAddEnabled}
|
||||
disabled={page.params.id == "new" && !savedAtLeastOnce}
|
||||
type="button"
|
||||
onclick={() => listSelectModal.openModal()}
|
||||
><i class="fa fa-plus mr-2"></i>{$_("add-to-list")}</Button
|
||||
|
||||
Reference in New Issue
Block a user