EditDrawer: show sub_sport badge immediately after save without page reload
This commit is contained in:
@@ -39,7 +39,9 @@
|
|||||||
// Local overrides applied immediately after a save (no re-fetch needed)
|
// Local overrides applied immediately after a save (no re-fetch needed)
|
||||||
let localTitle = '';
|
let localTitle = '';
|
||||||
let localDescription = '';
|
let localDescription = '';
|
||||||
|
let localSubSport: string | null | undefined = undefined;
|
||||||
$: displayTitle = localTitle || activity.title;
|
$: displayTitle = localTitle || activity.title;
|
||||||
|
$: displaySubSport = localSubSport !== undefined ? localSubSport : activity.sub_sport;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
fetch('/api/me', { credentials: 'include' })
|
fetch('/api/me', { credentials: 'include' })
|
||||||
@@ -81,10 +83,11 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function onSaved(e: CustomEvent<{ title: string; description: string }>) {
|
function onSaved(e: CustomEvent<{ title: string; description: string; sub_sport: string | null }>) {
|
||||||
editOpen = false;
|
editOpen = false;
|
||||||
localTitle = e.detail.title;
|
localTitle = e.detail.title;
|
||||||
localDescription = e.detail.description;
|
localDescription = e.detail.description;
|
||||||
|
localSubSport = e.detail.sub_sport;
|
||||||
}
|
}
|
||||||
|
|
||||||
$: trackUrl = activity.track_url
|
$: trackUrl = activity.track_url
|
||||||
@@ -267,12 +270,12 @@
|
|||||||
>
|
>
|
||||||
{sportIcon(activity.sport)} {sportLabel(activity.sport)}
|
{sportIcon(activity.sport)} {sportLabel(activity.sport)}
|
||||||
</span>
|
</span>
|
||||||
{#if activity.sub_sport && activity.sub_sport !== 'generic'}
|
{#if displaySubSport && displaySubSport !== 'generic'}
|
||||||
<span
|
<span
|
||||||
class="text-xs font-medium px-2 py-0.5 rounded-full"
|
class="text-xs font-medium px-2 py-0.5 rounded-full"
|
||||||
style="background:{color}11;color:{color}cc"
|
style="background:{color}11;color:{color}cc"
|
||||||
>
|
>
|
||||||
{sportLabel(activity.sport, activity.sub_sport).split(' ')[0]}
|
{sportLabel(activity.sport, displaySubSport).split(' ')[0]}
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
<span class="text-xs text-zinc-500">
|
<span class="text-xs text-zinc-500">
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
export let activityId: string;
|
export let activityId: string;
|
||||||
export let editUrl: string;
|
export let editUrl: string;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher<{ saved: { title: string; description: string }; close: void; deleted: void }>();
|
const dispatch = createEventDispatcher<{ saved: { title: string; description: string; sub_sport: string | null }; close: void; deleted: void }>();
|
||||||
|
|
||||||
const SPORTS: Sport[] = ['cycling', 'running', 'hiking', 'walking', 'swimming', 'skiing', 'other'];
|
const SPORTS: Sport[] = ['cycling', 'running', 'hiking', 'walking', 'swimming', 'skiing', 'other'];
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@
|
|||||||
saveStatus = 'Saved';
|
saveStatus = 'Saved';
|
||||||
saveOk = true;
|
saveOk = true;
|
||||||
await new Promise(r => setTimeout(r, 900));
|
await new Promise(r => setTimeout(r, 900));
|
||||||
dispatch('saved', { title, description });
|
dispatch('saved', { title, description, sub_sport: subSport || null });
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
saveStatus = e.message;
|
saveStatus = e.message;
|
||||||
saveOk = false;
|
saveOk = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user