From 9a51266fd38ae7224edb15ef348e3e1597269595 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sun, 5 Jan 2025 19:05:10 -0500 Subject: [PATCH] Added saved preference for sort order. --- .../classroom_compliance/EntriesTable.vue | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/src/apps/classroom_compliance/EntriesTable.vue b/app/src/apps/classroom_compliance/EntriesTable.vue index 9b0b9ba..5ce2a53 100644 --- a/app/src/apps/classroom_compliance/EntriesTable.vue +++ b/app/src/apps/classroom_compliance/EntriesTable.vue @@ -47,7 +47,9 @@ onMounted(async () => { } else if (sortingChoice.value === 'desk') { students.value.sort(sortEntriesByDeskNumber) } + saveSortPreference() }) + attemptSortByStoredPreference() }) async function loadEntries() { @@ -84,6 +86,23 @@ function sortEntriesByDeskNumber(a: EntriesResponseStudent, b: EntriesResponseSt return sortEntriesByName(a, b) } +function attemptSortByStoredPreference() { + const storedPreferences = localStorage.getItem(`entries-table.${props.classId}.preferences`) + if (storedPreferences !== null) { + const preferences: Record = JSON.parse(storedPreferences) + if ('sort' in preferences) { + sortingChoice.value = preferences['sort'] + } + } +} + +function saveSortPreference() { + const preferences = { + 'sort': sortingChoice.value + } + localStorage.setItem(`entries-table.${props.classId}.preferences`, JSON.stringify(preferences)) +} + function shiftDateRange(days: number) { toDate.value.setDate(toDate.value.getDate() + days) fromDate.value.setDate(fromDate.value.getDate() + days)