fix: re-sync company sidebar order from localStorage on data load

The orderedIds state was initialized at mount time when companies was
still an empty array (React Query hadn't resolved yet). When companies
data arrived, orderedIds remained empty so the sidebar fell back to
API-returned order, ignoring the user's saved drag order.

Add a useEffect that re-derives orderedIds from localStorage whenever
the companies array changes, ensuring the user's custom sort order
persists across data refetches and live update invalidations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Forgotten
2026-02-23 14:43:35 -06:00
parent 21c506dcae
commit b05ac91aa7

View File

@@ -158,6 +158,14 @@ export function CompanyRail() {
sortByStoredOrder(companies).map((c) => c.id)
);
// Re-sync orderedIds from localStorage whenever companies changes.
// Handles initial data load (companies starts as [] before query resolves)
// and subsequent refetches triggered by live updates.
useEffect(() => {
if (companies.length === 0) return;
setOrderedIds(sortByStoredOrder(companies).map((c) => c.id));
}, [companies]);
// Sync order across tabs via the native storage event
useEffect(() => {
const handleStorage = (e: StorageEvent) => {