Skip to content

Create local storage-based state, use for markbook ordering - #2307

Merged
barna-isaac merged 3 commits into
mainfrom
feature/local-storage-state-markbook
Aug 24, 2026
Merged

Create local storage-based state, use for markbook ordering#2307
barna-isaac merged 3 commits into
mainfrom
feature/local-storage-state-markbook

Conversation

@jacbn

@jacbn jacbn commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Creates a useState wrapper (very much along the lines of useHistoryState) 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.

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.41667% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.51%. Comparing base (0e86a70) to head (8c5bfbd).
⚠️ Report is 63 commits behind head on main.

Files with missing lines Patch % Lines
src/app/services/storage.ts 60.00% 6 Missing ⚠️
...es/assignment_progress/AssignmentProgressGroup.tsx 80.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@barna-isaac barna-isaac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";

@barna-isaac barna-isaac Aug 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, all good points. Have moved this and history to services – but services/history.ts already existed, so have merged those.

Comment thread src/app/services/progress.ts Outdated
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what uses this! Did you intend to also persist the state of the dropdown on the screenshot? If so, that's unfortunately stored in AssignmentProgressGroup.tsx:99.

Image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@barna-isaac barna-isaac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@barna-isaac
barna-isaac merged commit a71f50e into main Aug 24, 2026
10 checks passed
@barna-isaac
barna-isaac deleted the feature/local-storage-state-markbook branch August 24, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants