SegmentCreate: prompt after save instead of immediate redirect; update plan
After saving, show "Saved! Add another from this activity?" with two buttons: "Add another" (resets name/handles, keeps map loaded) and "Done" (navigates to /segments/).
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
let segSport = '';
|
||||
let saving = false;
|
||||
let saveError = '';
|
||||
let justSaved = false;
|
||||
let lastSavedName = '';
|
||||
|
||||
// ── Map ───────────────────────────────────────────────────────────────────
|
||||
let mapEl: HTMLDivElement;
|
||||
@@ -251,14 +253,29 @@
|
||||
}),
|
||||
});
|
||||
const d = await r.json();
|
||||
if (r.ok) { window.location.href = `${base}segments/`; }
|
||||
else { saveError = d.detail ?? 'Failed to save segment'; saving = false; }
|
||||
if (r.ok) {
|
||||
lastSavedName = segName.trim();
|
||||
justSaved = true;
|
||||
saving = false;
|
||||
} else {
|
||||
saveError = d.detail ?? 'Failed to save segment';
|
||||
saving = false;
|
||||
}
|
||||
} catch {
|
||||
saveError = 'Could not reach server';
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
function addAnother() {
|
||||
justSaved = false;
|
||||
segName = '';
|
||||
segSport = selectedActivity?.sport ?? '';
|
||||
startIdx = 0;
|
||||
endIdx = maxIdx;
|
||||
saveError = '';
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||
function polylineDistance(pts: [number, number][]): number {
|
||||
let d = 0;
|
||||
@@ -406,17 +423,36 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{#if saveError}
|
||||
<p class="text-red-400 text-sm mb-3">{saveError}</p>
|
||||
{/if}
|
||||
{#if justSaved}
|
||||
<div class="rounded-lg bg-zinc-800 border border-zinc-700 px-4 py-3 flex flex-col gap-3">
|
||||
<p class="text-sm text-white">
|
||||
<span class="text-green-400 font-medium">✓ "{lastSavedName}" saved.</span>
|
||||
Add another segment from this activity?
|
||||
</p>
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
on:click={addAnother}
|
||||
class="flex-1 py-2 rounded-lg text-sm font-medium bg-blue-600 hover:bg-blue-500 text-white transition-colors"
|
||||
>Add another</button>
|
||||
<a
|
||||
href="{base}segments/"
|
||||
class="flex-1 py-2 rounded-lg text-sm font-medium text-center bg-zinc-700 hover:bg-zinc-600 text-white transition-colors"
|
||||
>Done</a>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
{#if saveError}
|
||||
<p class="text-red-400 text-sm mb-3">{saveError}</p>
|
||||
{/if}
|
||||
|
||||
<button
|
||||
on:click={save}
|
||||
disabled={!canSave}
|
||||
class="w-full py-2.5 rounded-lg text-sm font-medium transition-colors
|
||||
bg-blue-600 hover:bg-blue-500 text-white
|
||||
disabled:opacity-40 disabled:cursor-not-allowed"
|
||||
>{saving ? 'Saving…' : 'Save segment'}</button>
|
||||
<button
|
||||
on:click={save}
|
||||
disabled={!canSave}
|
||||
class="w-full py-2.5 rounded-lg text-sm font-medium transition-colors
|
||||
bg-blue-600 hover:bg-blue-500 text-white
|
||||
disabled:opacity-40 disabled:cursor-not-allowed"
|
||||
>{saving ? 'Saving…' : 'Save segment'}</button>
|
||||
{/if}
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user