@@ -118,6 +118,12 @@ const LAP_RANGES = [
118118export default function LapAnalysisPanel ( { laps, drivers, currentLap, onClose } : Props ) {
119119 const [ selectedDrivers , setSelectedDrivers ] = useState < [ string | null , string | null ] > ( [ null , null ] ) ;
120120 const [ lapRange , setLapRange ] = useState < number > ( 0 ) ; // 0 = all
121+ const [ lapOrder , setLapOrder ] = useState < "asc" | "desc" > ( ( ) => {
122+ if ( typeof window !== "undefined" ) {
123+ return ( localStorage . getItem ( "f1replay_lap_order" ) as "asc" | "desc" ) || "asc" ;
124+ }
125+ return "asc" ;
126+ } ) ;
121127
122128 const sortedDrivers = useMemo (
123129 ( ) => [ ...drivers ] . sort ( ( a , b ) => ( a . position ?? 999 ) - ( b . position ?? 999 ) ) ,
@@ -499,7 +505,20 @@ export default function LapAnalysisPanel({ laps, drivers, currentLap, onClose }:
499505 < div className = "px-3 pb-2" >
500506 { /* Header row */ }
501507 < div className = "flex items-center gap-1 py-1 border-b border-f1-border" >
502- < span className = "w-8 text-[9px] font-bold text-f1-muted" > LAP</ span >
508+ < button
509+ onClick = { ( ) => {
510+ const next = lapOrder === "asc" ? "desc" : "asc" ;
511+ setLapOrder ( next ) ;
512+ try { localStorage . setItem ( "f1replay_lap_order" , next ) ; } catch { }
513+ } }
514+ className = "w-8 text-[9px] font-bold text-f1-muted hover:text-white transition-colors flex items-center gap-0.5"
515+ title = { lapOrder === "asc" ? "Show latest first" : "Show earliest first" }
516+ >
517+ LAP
518+ < svg className = { `w-2.5 h-2.5 transition-transform ${ lapOrder === "desc" ? "rotate-180" : "" } ` } fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" strokeWidth = { 2.5 } >
519+ < path strokeLinecap = "round" strokeLinejoin = "round" d = "M19 9l-7 7-7-7" />
520+ </ svg >
521+ </ button >
503522 { activeDrivers . map ( ( abbr ) => (
504523 < div key = { abbr } className = "flex-1 flex items-center gap-1" >
505524 < span
@@ -524,7 +543,10 @@ export default function LapAnalysisPanel({ laps, drivers, currentLap, onClose }:
524543 } ) ,
525544 ) ;
526545 const rows = [ ] ;
527- for ( let lap = 1 ; lap <= maxLap ; lap ++ ) {
546+ const startLap = lapOrder === "desc" ? maxLap : 1 ;
547+ const endLap = lapOrder === "desc" ? 1 : maxLap ;
548+ const step = lapOrder === "desc" ? - 1 : 1 ;
549+ for ( let lap = startLap ; lapOrder === "desc" ? lap >= endLap : lap <= endLap ; lap += step ) {
528550 rows . push (
529551 < div
530552 key = { lap }
0 commit comments