Added saved preference for sort order.

This commit is contained in:
Andrew Lalis 2025-01-05 19:05:10 -05:00
parent f06a83aa1b
commit 9a51266fd3
1 changed files with 19 additions and 0 deletions

View File

@ -47,7 +47,9 @@ onMounted(async () => {
} else if (sortingChoice.value === 'desk') { } else if (sortingChoice.value === 'desk') {
students.value.sort(sortEntriesByDeskNumber) students.value.sort(sortEntriesByDeskNumber)
} }
saveSortPreference()
}) })
attemptSortByStoredPreference()
}) })
async function loadEntries() { async function loadEntries() {
@ -84,6 +86,23 @@ function sortEntriesByDeskNumber(a: EntriesResponseStudent, b: EntriesResponseSt
return sortEntriesByName(a, b) return sortEntriesByName(a, b)
} }
function attemptSortByStoredPreference() {
const storedPreferences = localStorage.getItem(`entries-table.${props.classId}.preferences`)
if (storedPreferences !== null) {
const preferences: Record<string, string> = 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) { function shiftDateRange(days: number) {
toDate.value.setDate(toDate.value.getDate() + days) toDate.value.setDate(toDate.value.getDate() + days)
fromDate.value.setDate(fromDate.value.getDate() + days) fromDate.value.setDate(fromDate.value.getDate() + days)