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
|
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',
|
method: 'PUT',
|
||||||
body: JSON.stringify({ ...trail, expand: undefined }),
|
body: JSON.stringify({ ...trail }),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!r.ok) {
|
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)
|
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) {
|
export async function PUT(event: RequestEvent) {
|
||||||
try {
|
try {
|
||||||
const r = await create<Trail>(event, TrailCreateSchema, Collection.trails)
|
const r = await create<Trail>(event, TrailCreateSchema, Collection.trails)
|
||||||
|
enrichRecord(r);
|
||||||
return json(r);
|
return json(r);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw handleError(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 autoRouting = $state(true);
|
||||||
|
|
||||||
let listAddEnabled = $state(false);
|
let savedAtLeastOnce = $state(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
form,
|
form,
|
||||||
@@ -182,13 +182,14 @@
|
|||||||
?.trkpt?.at(0)?.$.lon;
|
?.trkpt?.at(0)?.$.lon;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page.params.id === "new") {
|
if (page.params.id === "new" && !savedAtLeastOnce) {
|
||||||
const createdTrail = await trails_create(
|
const createdTrail = await trails_create(
|
||||||
form as Trail,
|
form as Trail,
|
||||||
photoFiles,
|
photoFiles,
|
||||||
gpxFile,
|
gpxFile,
|
||||||
);
|
);
|
||||||
form.id = createdTrail.id;
|
setFields(createdTrail);
|
||||||
|
trail.set(createdTrail);
|
||||||
} else {
|
} else {
|
||||||
const updatedTrail = await trails_update(
|
const updatedTrail = await trails_update(
|
||||||
$trail,
|
$trail,
|
||||||
@@ -199,7 +200,7 @@
|
|||||||
setFields(updatedTrail);
|
setFields(updatedTrail);
|
||||||
}
|
}
|
||||||
|
|
||||||
listAddEnabled = true;
|
savedAtLeastOnce = true;
|
||||||
show_toast({
|
show_toast({
|
||||||
type: "success",
|
type: "success",
|
||||||
icon: "check",
|
icon: "check",
|
||||||
@@ -456,9 +457,6 @@
|
|||||||
log,
|
log,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log($formData.expand?.summit_logs);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSummitLogMenuClick(
|
function handleSummitLogMenuClick(
|
||||||
@@ -1093,7 +1091,7 @@
|
|||||||
<Button
|
<Button
|
||||||
secondary={true}
|
secondary={true}
|
||||||
tooltip={$_("save-your-trail-first")}
|
tooltip={$_("save-your-trail-first")}
|
||||||
disabled={page.params.id == "new" && !listAddEnabled}
|
disabled={page.params.id == "new" && !savedAtLeastOnce}
|
||||||
type="button"
|
type="button"
|
||||||
onclick={() => listSelectModal.openModal()}
|
onclick={() => listSelectModal.openModal()}
|
||||||
><i class="fa fa-plus mr-2"></i>{$_("add-to-list")}</Button
|
><i class="fa fa-plus mr-2"></i>{$_("add-to-list")}</Button
|
||||||
|
|||||||
Reference in New Issue
Block a user