Spaces:
Runtime error
Runtime error
Commit ·
484a0e5
1
Parent(s): 0591976
auto scroll
Browse files- src/components/runs-list.tsx +24 -2
src/components/runs-list.tsx
CHANGED
|
@@ -30,6 +30,8 @@ export default function RunsList({
|
|
| 30 |
const [startFilter, setStartFilter] = useState("");
|
| 31 |
const [endFilter, setEndFilter] = useState("");
|
| 32 |
const timerRef = useRef<NodeJS.Timeout | null>(null);
|
|
|
|
|
|
|
| 33 |
|
| 34 |
// Filter runs based on start and end filters
|
| 35 |
const filteredRuns = runs.filter((run) => {
|
|
@@ -55,7 +57,7 @@ export default function RunsList({
|
|
| 55 |
);
|
| 56 |
|
| 57 |
onSelectRun(originalIndex);
|
| 58 |
-
},
|
| 59 |
} else if (timerRef.current) {
|
| 60 |
clearInterval(timerRef.current);
|
| 61 |
timerRef.current = null;
|
|
@@ -68,6 +70,19 @@ export default function RunsList({
|
|
| 68 |
};
|
| 69 |
}, [isPlaying, selectedRunId, filteredRuns, runs, onSelectRun]);
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
const togglePlayPause = () => {
|
| 72 |
setIsPlaying(prev => !prev);
|
| 73 |
};
|
|
@@ -114,12 +129,19 @@ export default function RunsList({
|
|
| 114 |
</div>
|
| 115 |
</div>
|
| 116 |
|
| 117 |
-
<div className="flex-1 overflow-y-auto overflow-x-hidden space-y-3 pr-1">
|
| 118 |
{filteredRuns.map((run) => {
|
| 119 |
const originalIndex = runs.indexOf(run);
|
| 120 |
return (
|
| 121 |
<Card
|
| 122 |
key={originalIndex}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
className={cn(
|
| 124 |
"p-0 cursor-pointer transition-all border overflow-hidden",
|
| 125 |
selectedRunId === originalIndex
|
|
|
|
| 30 |
const [startFilter, setStartFilter] = useState("");
|
| 31 |
const [endFilter, setEndFilter] = useState("");
|
| 32 |
const timerRef = useRef<NodeJS.Timeout | null>(null);
|
| 33 |
+
const listContainerRef = useRef<HTMLDivElement>(null);
|
| 34 |
+
const runItemsRef = useRef<Map<number, HTMLDivElement>>(new Map());
|
| 35 |
|
| 36 |
// Filter runs based on start and end filters
|
| 37 |
const filteredRuns = runs.filter((run) => {
|
|
|
|
| 57 |
);
|
| 58 |
|
| 59 |
onSelectRun(originalIndex);
|
| 60 |
+
}, 1500);
|
| 61 |
} else if (timerRef.current) {
|
| 62 |
clearInterval(timerRef.current);
|
| 63 |
timerRef.current = null;
|
|
|
|
| 70 |
};
|
| 71 |
}, [isPlaying, selectedRunId, filteredRuns, runs, onSelectRun]);
|
| 72 |
|
| 73 |
+
// Scroll selected run into view when it changes
|
| 74 |
+
useEffect(() => {
|
| 75 |
+
if (selectedRunId !== null && isPlaying) {
|
| 76 |
+
const selectedElement = runItemsRef.current.get(selectedRunId);
|
| 77 |
+
if (selectedElement && listContainerRef.current) {
|
| 78 |
+
selectedElement.scrollIntoView({
|
| 79 |
+
behavior: 'smooth',
|
| 80 |
+
block: 'nearest'
|
| 81 |
+
});
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}, [selectedRunId, isPlaying]);
|
| 85 |
+
|
| 86 |
const togglePlayPause = () => {
|
| 87 |
setIsPlaying(prev => !prev);
|
| 88 |
};
|
|
|
|
| 129 |
</div>
|
| 130 |
</div>
|
| 131 |
|
| 132 |
+
<div ref={listContainerRef} className="flex-1 overflow-y-auto overflow-x-hidden space-y-3 pr-1">
|
| 133 |
{filteredRuns.map((run) => {
|
| 134 |
const originalIndex = runs.indexOf(run);
|
| 135 |
return (
|
| 136 |
<Card
|
| 137 |
key={originalIndex}
|
| 138 |
+
ref={(el) => {
|
| 139 |
+
if (el) {
|
| 140 |
+
runItemsRef.current.set(originalIndex, el);
|
| 141 |
+
} else {
|
| 142 |
+
runItemsRef.current.delete(originalIndex);
|
| 143 |
+
}
|
| 144 |
+
}}
|
| 145 |
className={cn(
|
| 146 |
"p-0 cursor-pointer transition-all border overflow-hidden",
|
| 147 |
selectedRunId === originalIndex
|