Move segment rescan button from segments list to athlete/segments tab
This commit is contained in:
@@ -33,6 +33,8 @@
|
||||
let segmentSummary: SegmentSummaryItem[] = [];
|
||||
let segmentsLoading = false;
|
||||
let segmentsHandle = '';
|
||||
let rescanning = false;
|
||||
let rescanMsg: string | null = null;
|
||||
|
||||
const editUrl = import.meta.env.PUBLIC_EDIT_URL ?? '';
|
||||
const editEnabled = editUrl !== '' || import.meta.env.PUBLIC_EDIT_ENABLED === 'true';
|
||||
@@ -177,6 +179,29 @@
|
||||
|
||||
<!-- Segments tab -->
|
||||
{:else if activeTab === 'segments'}
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<span></span>
|
||||
<div class="flex items-center gap-3">
|
||||
{#if rescanMsg}<span class="text-xs text-zinc-400">{rescanMsg}</span>{/if}
|
||||
<button
|
||||
on:click={async () => {
|
||||
rescanning = true; rescanMsg = null;
|
||||
try {
|
||||
const r = await fetch('/api/me/segment-rescan', { method: 'POST', credentials: 'include' });
|
||||
const d = await r.json();
|
||||
if (r.ok) {
|
||||
rescanMsg = `Found ${d.efforts_found} effort${d.efforts_found !== 1 ? 's' : ''}.`;
|
||||
// Refresh the summary
|
||||
segmentSummary = [];
|
||||
} else rescanMsg = d.detail ?? 'Rescan failed.';
|
||||
} catch { rescanMsg = 'Could not reach server.'; }
|
||||
rescanning = false;
|
||||
}}
|
||||
disabled={rescanning}
|
||||
class="text-xs px-3 py-1.5 rounded-lg border border-zinc-700 text-zinc-400 hover:border-zinc-500 hover:text-white transition-colors disabled:opacity-40"
|
||||
>{rescanning ? 'Scanning…' : 'Rescan all activities'}</button>
|
||||
</div>
|
||||
</div>
|
||||
{#if segmentsLoading}
|
||||
<p class="text-zinc-500 text-sm">Loading segments…</p>
|
||||
{:else if segmentSummary.length === 0}
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
let loading = false;
|
||||
let selectedId: string | null = null;
|
||||
let fetchTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
let rescanning = false;
|
||||
let rescanMsg: string | null = null;
|
||||
|
||||
const TILE_STYLE = 'https://tiles.openfreemap.org/styles/positron';
|
||||
const SEG_COLOR = '#f59e0b';
|
||||
@@ -125,20 +123,6 @@
|
||||
['case', ['==', ['get', 'id'], selectedId ?? ''], 5, 3]);
|
||||
}
|
||||
|
||||
async function rescanAll() {
|
||||
rescanning = true;
|
||||
rescanMsg = null;
|
||||
try {
|
||||
const r = await fetch('/api/me/segment-rescan', { method: 'POST', credentials: 'include' });
|
||||
const d = await r.json();
|
||||
if (r.ok) rescanMsg = `Found ${d.efforts_found} effort${d.efforts_found !== 1 ? 's' : ''}.`;
|
||||
else rescanMsg = d.detail ?? 'Rescan failed.';
|
||||
} catch {
|
||||
rescanMsg = 'Could not reach server.';
|
||||
}
|
||||
rescanning = false;
|
||||
}
|
||||
|
||||
async function deleteSegment(id: string) {
|
||||
if (!confirm('Delete this segment? This cannot be undone.')) return;
|
||||
try {
|
||||
@@ -160,22 +144,11 @@
|
||||
<div class="flex items-center justify-between px-4 py-3 border-b shrink-0"
|
||||
style="border-color: var(--border)">
|
||||
<h1 class="text-lg font-bold text-white">Segments</h1>
|
||||
<div class="flex items-center gap-2">
|
||||
{#if rescanMsg}
|
||||
<span class="text-xs text-zinc-400">{rescanMsg}</span>
|
||||
{/if}
|
||||
<button
|
||||
on:click={rescanAll}
|
||||
disabled={rescanning}
|
||||
title="Rescan all your activities against all segments"
|
||||
class="px-3 py-1.5 rounded-lg text-sm border border-zinc-700 text-zinc-400 hover:border-zinc-500 hover:text-white transition-colors disabled:opacity-40"
|
||||
>{rescanning ? 'Scanning…' : 'Rescan all'}</button>
|
||||
<a href="{base}segments/new/"
|
||||
class="px-3 py-1.5 rounded-lg text-sm bg-blue-600 hover:bg-blue-500 text-white transition-colors">
|
||||
+ New segment
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Map -->
|
||||
<div class="relative" style="height: 400px;">
|
||||
|
||||
Reference in New Issue
Block a user