Create local storage-based state, use for markbook ordering - #2307
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2307 +/- ##
==========================================
- Coverage 43.55% 43.51% -0.04%
==========================================
Files 602 602
Lines 25751 25781 +30
Branches 8600 8582 -18
==========================================
+ Hits 11215 11219 +4
- Misses 14479 14505 +26
Partials 57 57 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Tell me whether you agree the file would make more sense elsewhere, but this is a very elegant, react-y implementation, which will make it easier to persist more of these settings.
However, it might be that I misread what you were trying to do, but I think you meant to persist the order of assignments, and this still doesn't work.
| @@ -0,0 +1,24 @@ | |||
| import { useState } from "react"; | |||
There was a problem hiding this comment.
I think this file doesn't belong under state/actions? I think state/actions is for redux action creators, and this is a custom hook that doesn't touch redux at all (useState is for the component, not redux). I think this could just live in src/services? We already have a custom hook there (useSessionExpired). (I realize history.tsx also lives under state/actions, but I think that's an outlier too.)
There was a problem hiding this comment.
Yes, all good points. Have moved this and history to services – but services/history.ts already existed, so have merged those.
| const [attemptedOrCorrect, setAttemptedOrCorrect] = useState<"ATTEMPTED" | "CORRECT">("CORRECT"); | ||
| const [assignmentOrder, setAssignmentOrder] = useState<AssignmentOrderSpec>(AssignmentOrder.startDateDescending); | ||
| const [groupSortOrder, setGroupSortOrder] = useState<GroupSortOrder>(GroupSortOrder.Alphabetical); | ||
| const [assignmentOrder, setAssignmentOrder] = useLocalStorageState<AssignmentOrderSpec>(KEY.ASSIGNMENT_ORDER, AssignmentOrder.startDateDescending); |
There was a problem hiding this comment.
I saw a related useState and copied it without really trying if it worked 😭 It looks like that page is supposed to inherit from the context but doesn't, so I've made it use that instead.
There was a problem hiding this comment.
Looks good! In the meantime, @jsharkey13 has pointed out we'll still loose these when a user signs out, but I still think this is an improvement. If we want to persist the sort orders among a user signing in and out, I think we should modify the code part that clears local storage so it leaves these keys alone.

Creates a
useStatewrapper (very much along the lines ofuseHistoryState) that uses a previous value saved in localStorage, if such a value exists.Uses this function initially for markbook ordering of groups and assignments, as per content request.