feat(*): Enable displaying history using localstorage

This commit is contained in:
Josh Creek
2025-04-16 23:39:43 +01:00
parent e75fbb6694
commit bbeb29dea5
3 changed files with 89 additions and 6 deletions
+24 -4
View File
@@ -1,13 +1,31 @@
<script lang="ts">
import AssessmentFeedback from '$lib/components/AssessmentFeedback.svelte';
import AssessmentHistory from '$lib/components/AssessmentHistory.svelte';
import { onMount } from 'svelte';
let feedback: any = null;
let history: any[] = [];
function saveToHistory(entry: any) {
let prev = [];
try {
prev = JSON.parse(localStorage.getItem('assessmentHistory') || '[]');
} catch {}
prev.unshift(entry); // latest first
localStorage.setItem('assessmentHistory', JSON.stringify(prev.slice(0, 50)));
}
onMount(() => {
// For hackathon simplicity, get feedback from history state
if (window.history.state && window.history.state.feedback) {
feedback = window.history.state.feedback;
try {
history = JSON.parse(localStorage.getItem('assessmentHistory') || '[]');
if (history && history.length > 0) {
feedback = history[0]; // Show latest as most prominent feedback
} else {
feedback = null;
}
} catch {
history = [];
feedback = null;
}
});
</script>
@@ -17,7 +35,9 @@ onMount(() => {
<p class="mb-6">View detailed feedback and recommendations for each student submission.</p>
{#if feedback}
<AssessmentFeedback {...feedback} />
{:else}
{/if}
{#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>
{/if}
<AssessmentHistory {history} hideIfEmpty={true} />
</section>