diff --git a/src/components/views/ProblemsView.tsx b/src/components/views/ProblemsView.tsx index 4acb7e4..1cde932 100644 --- a/src/components/views/ProblemsView.tsx +++ b/src/components/views/ProblemsView.tsx @@ -1,9 +1,11 @@ -import { useState, useEffect, useRef } from 'react' -import { ChevronDown, ChevronUp, ExternalLink } from 'lucide-react' +import { useState, useCallback } from 'react' +import { motion, AnimatePresence } from 'framer-motion' +import { ChevronDown, ExternalLink } from 'lucide-react' import { problems } from '@/data/problems' import { consultations } from '@/data/consultations' import type { Problem, Consultation } from '@/types/pmr' import { useBreakpoint } from '@/hooks/useBreakpoint' +import { useAccessibility } from '@/contexts/AccessibilityContext' interface ProblemsViewProps { onNavigate?: (view: 'consultations', itemId?: string) => void @@ -27,11 +29,13 @@ function TrafficLight({ status }: { status: ProblemStatus }) { aria-label={`Status: ${label}`} role="img" /> - {label} + {label} ) } +const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches + function ProblemRow({ problem, isExpanded, @@ -45,18 +49,6 @@ function ProblemRow({ onNavigate?: (view: 'consultations', itemId?: string) => void showOutcome: boolean }) { - const contentRef = useRef(null) - const [contentHeight, setContentHeight] = useState(undefined) - const prefersReducedMotion = useRef( - window.matchMedia('(prefers-reduced-motion: reduce)').matches - ).current - - useEffect(() => { - if (contentRef.current) { - setContentHeight(contentRef.current.scrollHeight) - } - }, [isExpanded]) - const linkedConsultations = (problem.linkedConsultations ?? []) .map((id) => consultations.find((c) => c.id === id)) .filter((c): c is Consultation => c !== undefined) @@ -69,86 +61,99 @@ function ProblemRow({ return ( <> - - [{problem.code}] + [{problem.code}] - {problem.description} + {problem.description} - + {problem.resolved || problem.since} {showOutcome && ( {problem.outcome && ( - {problem.outcome} + {problem.outcome} )} )} - + + - - - -
+ + {isExpanded && ( + -
-
- {problem.narrative} -
- {linkedConsultations.length > 0 && ( -
- - Linked Consultations: - -
- {linkedConsultations.map((consultation) => ( - - ))} + + +
+
+ {problem.narrative}
+ {linkedConsultations.length > 0 && ( +
+ + Linked Consultations: + +
+ {linkedConsultations.map((consultation) => ( + + ))} +
+
+ )}
- )} -
-
- - + + + + )} + ) } @@ -177,23 +182,23 @@ function MobileProblemCard({ } return ( -
+
- {isExpanded && ( -
-
- {problem.narrative} -
- {linkedConsultations.length > 0 && ( -
- - Linked Consultations: - -
- {linkedConsultations.map((consultation) => ( - - ))} + + {isExpanded && ( + +
+
+ {problem.narrative}
+ {linkedConsultations.length > 0 && ( +
+ + Linked Consultations: + +
+ {linkedConsultations.map((consultation) => ( + + ))} +
+
+ )}
- )} -
- )} + + )} +
) } @@ -248,21 +264,36 @@ function MobileProblemCard({ export function ProblemsView({ onNavigate }: ProblemsViewProps) { const [expandedId, setExpandedId] = useState(null) const { isMobile } = useBreakpoint() + const { setExpandedItem } = useAccessibility() const activeProblems = problems.filter( (p) => p.status === 'Active' || p.status === 'In Progress' ) const resolvedProblems = problems.filter((p) => p.status === 'Resolved') - const handleToggle = (id: string) => { - setExpandedId(expandedId === id ? null : id) - } + const handleToggle = useCallback( + (id: string) => { + const newExpandedId = expandedId === id ? null : id + setExpandedId(newExpandedId) + + // Update breadcrumb context - pass the problem description as the expanded item ID + if (newExpandedId) { + const problem = problems.find((p) => p.id === newExpandedId) + if (problem) { + setExpandedItem(problem.description) + } + } else { + setExpandedItem(null) + } + }, + [expandedId, setExpandedItem] + ) return (
-
+
-

+

Active Problems

@@ -285,31 +316,31 @@ export function ProblemsView({ onNavigate }: ProblemsViewProps) { Status Code Problem Since Expand @@ -330,13 +361,13 @@ export function ProblemsView({ onNavigate }: ProblemsViewProps) { )} {activeProblems.length === 0 && ( -
No active problems
+
No active problems
)}
-
+
-

+

Resolved Problems

@@ -359,37 +390,37 @@ export function ProblemsView({ onNavigate }: ProblemsViewProps) { Status Code Problem Resolved Outcome Expand @@ -410,7 +441,7 @@ export function ProblemsView({ onNavigate }: ProblemsViewProps) { )} {resolvedProblems.length === 0 && ( -
No resolved problems
+
No resolved problems
)}