From c2b97ea8ff556e89886d1afbe07bcbe13d586887 Mon Sep 17 00:00:00 2001 From: Joshua Ryder Date: Mon, 8 Dec 2025 15:16:38 -0500 Subject: [PATCH] More favorites fixes --- frontend/src/components/SectionsManager.tsx | 32 +++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/SectionsManager.tsx b/frontend/src/components/SectionsManager.tsx index 24276345..9b8fee36 100644 --- a/frontend/src/components/SectionsManager.tsx +++ b/frontend/src/components/SectionsManager.tsx @@ -9,10 +9,12 @@ interface SectionsManagerProps { } const SectionsManager: React.FC = ({ - sections, + sections: propSections, onClose, onSectionChange }) => { + // Local state for optimistic updates + const [localSections, setLocalSections] = useState(propSections); const [editingId, setEditingId] = useState(null); const [editName, setEditName] = useState(''); const [editColor, setEditColor] = useState(''); @@ -22,6 +24,11 @@ const SectionsManager: React.FC = ({ const [showColorPicker, setShowColorPicker] = useState(null); const [error, setError] = useState(''); + // Sync local state when props change + React.useEffect(() => { + setLocalSections(propSections); + }, [propSections]); + const createSection = async () => { if (!newSectionName.trim()) { setError('Section name is required'); @@ -115,18 +122,21 @@ const SectionsManager: React.FC = ({ }; const moveSection = async (id: number, direction: 'up' | 'down') => { - const currentIndex = sections.findIndex(s => s.id === id); + const currentIndex = localSections.findIndex(s => s.id === id); if ( (direction === 'up' && currentIndex === 0) || - (direction === 'down' && currentIndex === sections.length - 1) + (direction === 'down' && currentIndex === localSections.length - 1) ) { return; } - const newSections = [...sections]; + const newSections = [...localSections]; const swapIndex = direction === 'up' ? currentIndex - 1 : currentIndex + 1; [newSections[currentIndex], newSections[swapIndex]] = [newSections[swapIndex], newSections[currentIndex]]; + // Optimistic update - immediately show the reorder + setLocalSections(newSections); + const sectionIds = newSections.map(s => s.id); try { @@ -139,8 +149,14 @@ const SectionsManager: React.FC = ({ if (response.ok) { onSectionChange(); + } else { + // Revert on failure + setLocalSections(localSections); + setError('Failed to reorder sections'); } } catch (err) { + // Revert on failure + setLocalSections(localSections); setError('Failed to reorder sections'); } }; @@ -196,13 +212,13 @@ const SectionsManager: React.FC = ({ {/* Sections list */}
- {sections.length === 0 ? ( + {localSections.length === 0 ? (

No sections yet. Create one to organize your favorites!

) : (
- {sections.map((section, index) => ( + {localSections.map((section, index) => (
= ({ {section.name} - {section.is_default && ( + {!!section.is_default && ( default @@ -274,7 +290,7 @@ const SectionsManager: React.FC = ({