Skip to content

Migrate tree sort order from localStorage to Redux Toolkit#650

Draft
Copilot wants to merge 7 commits intomainfrom
copilot/fix-issue-649-plan-execute
Draft

Migrate tree sort order from localStorage to Redux Toolkit#650
Copilot wants to merge 7 commits intomainfrom
copilot/fix-issue-649-plan-execute

Conversation

Copy link

Copilot AI commented Feb 11, 2026

The useTreeSortOrder hook was using localStorage directly while the rest of the application uses Redux Toolkit with redux-persist for state management. This migration standardizes state persistence and enables better debugging through Redux DevTools.

Challenge

Sort orders must persist across projects (not reset on ProjectActions.changeProject), unlike most Redux slices in the codebase which reset their state when switching projects.

Changes

New global Redux slice (treeSortOrderSlice.ts)

  • Stores sort orders keyed by {projectId}-{storageKey} for multi-project isolation
  • Explicitly omits ProjectActions.changeProject handler to preserve state across project switches
  • Uses redux-persist with localStorage as storage engine

Updated hook (useTreeSortOrder.ts)

  • Replaced localStorage calls with Redux useAppSelector and dispatch
  • Maintains identical API - no component changes required
// Hook API unchanged - backward compatible
const { sortOrder, updateSortOrder } = useTreeSortOrder(
  "code-sort-order",
  projectId,
  allItemIds
);

Store integration (store.ts)

  • Added treeSortOrder reducer to persisted reducers section

Migration Impact

Existing users will lose their current sort orders once (stored under old localStorage keys). Sort orders can be quickly re-created via drag-and-drop.

Pattern Established

This creates a reusable pattern for global cross-project state:

  1. Omit ProjectActions.changeProject from extraReducers
  2. Use composite keys: {projectId}-{key}
  3. Persist via redux-persist

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits February 11, 2026 11:12
…agExplorer

Co-authored-by: bigabig <642805+bigabig@users.noreply.github.com>
Co-authored-by: bigabig <642805+bigabig@users.noreply.github.com>
…ndling

Co-authored-by: bigabig <642805+bigabig@users.noreply.github.com>
Co-authored-by: bigabig <642805+bigabig@users.noreply.github.com>
Co-authored-by: bigabig <642805+bigabig@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue #649 by implementing plan and execute Add drag-and-drop reordering for Code and Tag trees Feb 11, 2026
Copilot AI requested a review from bigabig February 11, 2026 11:25
Co-authored-by: bigabig <642805+bigabig@users.noreply.github.com>
Copilot AI changed the title Add drag-and-drop reordering for Code and Tag trees Migrate tree sort order from localStorage to Redux Toolkit Feb 11, 2026
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