feat(*): Add confirmation dialogs

This commit is contained in:
Josh Creek
2025-04-16 23:54:14 +01:00
parent eb932ba379
commit 1be2268e54
+8 -3
View File
@@ -42,26 +42,31 @@ onMount(() => {
{#if !feedback && (!history || history.length === 0)} {#if !feedback && (!history || history.length === 0)}
<div class="border rounded p-6 text-gray-500">No results yet. Upload submissions to see feedback here.</div> <div class="border rounded p-6 text-gray-500">No results yet. Upload submissions to see feedback here.</div>
{/if} {/if}
{#if history.length > 0}
<div class="flex justify-end mt-6"> <div class="flex justify-end mt-6">
<button class="bg-red-100 text-red-700 px-3 py-1 rounded hover:bg-red-200 transition" on:click={clearHistory} disabled={history.length === 0}>Clear History</button> <button class="bg-red-100 text-red-700 px-3 py-1 rounded hover:bg-red-200 transition" on:click={confirmClearHistory}>Clear History</button>
</div> </div>
{/if}
<AssessmentHistory {history} hideIfEmpty={true} on:delete={deleteEntry} /> <AssessmentHistory {history} hideIfEmpty={true} on:delete={deleteEntry} />
</section> </section>
<script lang="ts" context="module"> <script lang="ts" context="module">
export function clearHistory() { export function confirmClearHistory() {
if (window.confirm('Are you sure you want to clear all assessment history? This action cannot be undone.')) {
localStorage.removeItem('assessmentHistory'); localStorage.removeItem('assessmentHistory');
window.location.reload(); window.location.reload();
} }
}
export function deleteEntry(event: CustomEvent) { export function deleteEntry(event: CustomEvent) {
const timestamp = event.detail; const timestamp = event.detail;
if (window.confirm('Delete this assessment entry? This action cannot be undone.')) {
let prev = []; let prev = [];
try { try {
prev = JSON.parse(localStorage.getItem('assessmentHistory') || '[]'); prev = JSON.parse(localStorage.getItem('assessmentHistory') || '[]');
} catch {} } catch {}
prev = prev.filter((entry: any) => entry.timestamp !== timestamp); prev = prev.filter((entry: any) => entry.timestamp !== timestamp);
localStorage.setItem('assessmentHistory', JSON.stringify(prev)); localStorage.setItem('assessmentHistory', JSON.stringify(prev));
window.location.reload(); window.location.reload();
} }
}
</script> </script>