Skip to content

feat: add generic localStorage preference helpers (#458)#468

Merged
Chucks1093 merged 1 commit into
accesslayerorg:devfrom
Kaycee276:fix/458-localStorage-preferences
Jun 26, 2026
Merged

feat: add generic localStorage preference helpers (#458)#468
Chucks1093 merged 1 commit into
accesslayerorg:devfrom
Kaycee276:fix/458-localStorage-preferences

Conversation

@Kaycee276

Copy link
Copy Markdown
Contributor

Description

Closes #458

This PR introduces a central localStorage utility for managing user preferences (e.g., preserving creator list sort orders across page reloads). The goal is to provide a unified, strictly-typed interface for reading and writing user preferences, eliminating the need for raw localStorage boilerplate scattered across components.

These shared helpers handle JSON serialization and deserialization seamlessly under the hood. They also ensure robustness by catching potential errors—such as malformed JSON payloads or restricted storage environments—and safely failing back to a provided default value instead of throwing runtime errors.

Changes Made

  • Added getPreference<T> and setPreference<T> utility functions in src/utils/preferences.utils.ts
  • Implemented a comprehensive unit test suite in src/utils/__tests__/preferences.utils.test.ts to ensure edge cases are fully covered.

Verification

The following acceptance criteria have been fully verified via unit tests:

  • getPreference correctly returns the stored value for a key that exists.
  • getPreference gracefully returns the default value if the key is missing.
  • getPreference safely intercepts JSON.parse errors from malformed data and returns the default value without crashing.
  • setPreference and getPreference can successfully round-trip complex JSON objects.

All tests validate locally via pnpm test src/utils/__tests__/preferences.utils.test.ts.

@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

@Kaycee276 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Chucks1093 Chucks1093 merged commit bf3e745 into accesslayerorg:dev Jun 26, 2026
1 check passed
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.

Add helper for reading and writing user preferences to localStorage

2 participants