fix(webapp): add delete button to workout history cards
Previously only the bot's /delete command could remove a workout — the Mini App history view had an edit pencil but no delete button. Added a trash-icon button next to the pencil with a native Telegram confirm dialog before deleting. Also added the per-user workout number to each history card header (e.g. "#3 · Sun 19 Apr 2026, 14:30") so users can correlate with the number shown in save toasts and /history. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
24b8ceaac2
commit
9636d6870e
2 changed files with 34 additions and 1 deletions
|
|
@ -785,10 +785,11 @@ async function loadHistory(append = false) {
|
||||||
|
|
||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
<div class="history-header">
|
<div class="history-header">
|
||||||
<span class="history-date">${dateStr}</span>
|
<span class="history-date">#${w.user_number} · ${dateStr}</span>
|
||||||
<div class="history-header-right">
|
<div class="history-header-right">
|
||||||
<span class="history-volume">${Math.round(volume)} kg vol</span>
|
<span class="history-volume">${Math.round(volume)} kg vol</span>
|
||||||
<button class="btn-remove btn-edit btn-history-edit" title="Edit">✎</button>
|
<button class="btn-remove btn-edit btn-history-edit" title="Edit">✎</button>
|
||||||
|
<button class="btn-remove btn-history-delete" title="Delete">🗑</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
${groupsHtml}
|
${groupsHtml}
|
||||||
|
|
@ -799,6 +800,11 @@ async function loadHistory(append = false) {
|
||||||
editSavedWorkout(w);
|
editSavedWorkout(w);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
card.querySelector(".btn-history-delete").addEventListener("click", (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
confirmDeleteWorkout(w);
|
||||||
|
});
|
||||||
|
|
||||||
container.appendChild(card);
|
container.appendChild(card);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -813,6 +819,28 @@ document.getElementById("btn-load-more").addEventListener("click", () => {
|
||||||
loadHistory(true);
|
loadHistory(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function confirmDeleteWorkout(w) {
|
||||||
|
const label = "Workout #" + (w.user_number ?? w.id);
|
||||||
|
const prompt = "Delete " + label + "? This can't be undone.";
|
||||||
|
const onConfirm = async (ok) => {
|
||||||
|
if (!ok) return;
|
||||||
|
try {
|
||||||
|
await api("DELETE", "/workouts/" + w.id);
|
||||||
|
showToast(label + " deleted");
|
||||||
|
tg.HapticFeedback.notificationOccurred("success");
|
||||||
|
loadHistory();
|
||||||
|
} catch (e) {
|
||||||
|
showToast(e.message || "Delete failed");
|
||||||
|
tg.HapticFeedback.notificationOccurred("error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (tg && typeof tg.showConfirm === "function") {
|
||||||
|
tg.showConfirm(prompt, onConfirm);
|
||||||
|
} else {
|
||||||
|
onConfirm(window.confirm(prompt));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Stats View ──────────────────────────────────────────────────
|
// ── Stats View ──────────────────────────────────────────────────
|
||||||
|
|
||||||
async function loadStats() {
|
async function loadStats() {
|
||||||
|
|
|
||||||
|
|
@ -392,6 +392,11 @@ details[open] .raw-toggle::before {
|
||||||
font-size: 14px !important;
|
font-size: 14px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-history-delete {
|
||||||
|
font-size: 14px !important;
|
||||||
|
color: var(--tg-theme-destructive-text-color, #d33) !important;
|
||||||
|
}
|
||||||
|
|
||||||
.history-group {
|
.history-group {
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue