Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Sync from huggingface/lerobot-dataset-visualizer via hub-sync
Browse files- src/components/side-nav.tsx +16 -2
src/components/side-nav.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"use client";
|
| 2 |
|
| 3 |
import Link from "next/link";
|
| 4 |
-
import React, { useMemo, useState } from "react";
|
| 5 |
import { useFlaggedEpisodes } from "@/context/flagged-episodes-context";
|
| 6 |
|
| 7 |
import type { DatasetDisplayInfo } from "@/app/[org]/[dataset]/[episode]/fetch-data";
|
|
@@ -39,9 +39,23 @@ const Sidebar: React.FC<SidebarProps> = ({
|
|
| 39 |
return [...flagged].sort((a, b) => a - b);
|
| 40 |
}, [paginatedEpisodes, showFlaggedOnly, flagged, count]);
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
return (
|
| 43 |
<div className="flex z-10 shrink-0">
|
| 44 |
<nav
|
|
|
|
| 45 |
className={`shrink-0 overflow-y-auto bg-[var(--surface-0)] border-r border-white/5 p-4 break-words w-60 ${
|
| 46 |
mobileVisible ? "block" : "hidden"
|
| 47 |
} md:block`}
|
|
@@ -93,7 +107,7 @@ const Sidebar: React.FC<SidebarProps> = ({
|
|
| 93 |
: "text-slate-300 hover:bg-white/5"
|
| 94 |
}`;
|
| 95 |
return (
|
| 96 |
-
<li key={episode}>
|
| 97 |
{onEpisodeSelect ? (
|
| 98 |
<div className={itemClass}>
|
| 99 |
<button
|
|
|
|
| 1 |
"use client";
|
| 2 |
|
| 3 |
import Link from "next/link";
|
| 4 |
+
import React, { useEffect, useMemo, useRef, useState } from "react";
|
| 5 |
import { useFlaggedEpisodes } from "@/context/flagged-episodes-context";
|
| 6 |
|
| 7 |
import type { DatasetDisplayInfo } from "@/app/[org]/[dataset]/[episode]/fetch-data";
|
|
|
|
| 39 |
return [...flagged].sort((a, b) => a - b);
|
| 40 |
}, [paginatedEpisodes, showFlaggedOnly, flagged, count]);
|
| 41 |
|
| 42 |
+
/// A page holds 100 episodes; without this, opening episode 80 left its highlighted row off screen.
|
| 43 |
+
/// Only scrolls when the row is out of view, so clicking a visible row doesn't make the list jump.
|
| 44 |
+
const navRef = useRef<HTMLElement>(null);
|
| 45 |
+
const activeItemRef = useRef<HTMLLIElement>(null);
|
| 46 |
+
useEffect(() => {
|
| 47 |
+
const item = activeItemRef.current?.getBoundingClientRect();
|
| 48 |
+
const nav = navRef.current?.getBoundingClientRect();
|
| 49 |
+
if (!item || !nav) return;
|
| 50 |
+
if (item.top < nav.top || item.bottom > nav.bottom) {
|
| 51 |
+
activeItemRef.current?.scrollIntoView({ block: "center" });
|
| 52 |
+
}
|
| 53 |
+
}, [episodeId, displayEpisodes]);
|
| 54 |
+
|
| 55 |
return (
|
| 56 |
<div className="flex z-10 shrink-0">
|
| 57 |
<nav
|
| 58 |
+
ref={navRef}
|
| 59 |
className={`shrink-0 overflow-y-auto bg-[var(--surface-0)] border-r border-white/5 p-4 break-words w-60 ${
|
| 60 |
mobileVisible ? "block" : "hidden"
|
| 61 |
} md:block`}
|
|
|
|
| 107 |
: "text-slate-300 hover:bg-white/5"
|
| 108 |
}`;
|
| 109 |
return (
|
| 110 |
+
<li key={episode} ref={active ? activeItemRef : undefined}>
|
| 111 |
{onEpisodeSelect ? (
|
| 112 |
<div className={itemClass}>
|
| 113 |
<button
|