Spaces:
Running
Running
fix type check
Browse files
src/app/[org]/[dataset]/[episode]/episode-viewer.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
"use client";
|
| 2 |
|
| 3 |
-
import { useState, useEffect, useRef, lazy, Suspense } from "react";
|
| 4 |
import { useRouter, useSearchParams } from "next/navigation";
|
| 5 |
import { postParentMessageWithParams } from "@/utils/postParentMessage";
|
| 6 |
import { SimpleVideosPlayer } from "@/components/simple-videos-player";
|
|
@@ -140,7 +140,7 @@ function EpisodeViewerInner({
|
|
| 140 |
`[perf] Loading complete in ${(performance.now() - loadStartRef.current).toFixed(0)}ms (videos: ${videosReady ? "✓" : "…"}, charts: ${chartsReady ? "✓" : "…"})`,
|
| 141 |
);
|
| 142 |
}
|
| 143 |
-
}, [isLoading]);
|
| 144 |
|
| 145 |
const router = useRouter();
|
| 146 |
const searchParams = useSearchParams();
|
|
@@ -357,7 +357,7 @@ function EpisodeViewerInner({
|
|
| 357 |
setCurrentTime(timeValue);
|
| 358 |
}
|
| 359 |
}
|
| 360 |
-
}, []);
|
| 361 |
|
| 362 |
// sync with parent window hf.co/spaces
|
| 363 |
useEffect(() => {
|
|
@@ -366,6 +366,31 @@ function EpisodeViewerInner({
|
|
| 366 |
});
|
| 367 |
}, []);
|
| 368 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
// Initialize based on URL time parameter
|
| 370 |
useEffect(() => {
|
| 371 |
// Initialize page based on current episode
|
|
@@ -379,7 +404,7 @@ function EpisodeViewerInner({
|
|
| 379 |
return () => {
|
| 380 |
window.removeEventListener("keydown", handleKeyDown);
|
| 381 |
};
|
| 382 |
-
}, [episodes, episodeId, pageSize,
|
| 383 |
|
| 384 |
// Only update URL ?t= param when the integer second changes
|
| 385 |
const lastUrlSecondRef = useRef<number>(-1);
|
|
@@ -402,28 +427,6 @@ function EpisodeViewerInner({
|
|
| 402 |
}
|
| 403 |
}, [isPlaying, currentTime, searchParams]);
|
| 404 |
|
| 405 |
-
// Handle keyboard shortcuts
|
| 406 |
-
const handleKeyDown = (e: KeyboardEvent) => {
|
| 407 |
-
const { key } = e;
|
| 408 |
-
|
| 409 |
-
if (key === " ") {
|
| 410 |
-
e.preventDefault();
|
| 411 |
-
setIsPlaying((prev: boolean) => !prev);
|
| 412 |
-
} else if (key === "ArrowDown" || key === "ArrowUp") {
|
| 413 |
-
e.preventDefault();
|
| 414 |
-
const nextEpisodeId = key === "ArrowDown" ? episodeId + 1 : episodeId - 1;
|
| 415 |
-
const lowestEpisodeId = episodes[0];
|
| 416 |
-
const highestEpisodeId = episodes[episodes.length - 1];
|
| 417 |
-
|
| 418 |
-
if (
|
| 419 |
-
nextEpisodeId >= lowestEpisodeId &&
|
| 420 |
-
nextEpisodeId <= highestEpisodeId
|
| 421 |
-
) {
|
| 422 |
-
router.push(`./episode_${nextEpisodeId}`);
|
| 423 |
-
}
|
| 424 |
-
}
|
| 425 |
-
};
|
| 426 |
-
|
| 427 |
// Pagination functions
|
| 428 |
const nextPage = () => {
|
| 429 |
if (currentPage < totalPages) {
|
|
@@ -555,6 +558,7 @@ function EpisodeViewerInner({
|
|
| 555 |
target="_blank"
|
| 556 |
className="block"
|
| 557 |
>
|
|
|
|
| 558 |
<img
|
| 559 |
src="https://github.com/huggingface/lerobot/raw/main/media/readme/lerobot-logo-thumbnail.png"
|
| 560 |
alt="LeRobot Logo"
|
|
|
|
| 1 |
"use client";
|
| 2 |
|
| 3 |
+
import { useState, useEffect, useRef, lazy, Suspense, useCallback } from "react";
|
| 4 |
import { useRouter, useSearchParams } from "next/navigation";
|
| 5 |
import { postParentMessageWithParams } from "@/utils/postParentMessage";
|
| 6 |
import { SimpleVideosPlayer } from "@/components/simple-videos-player";
|
|
|
|
| 140 |
`[perf] Loading complete in ${(performance.now() - loadStartRef.current).toFixed(0)}ms (videos: ${videosReady ? "✓" : "…"}, charts: ${chartsReady ? "✓" : "…"})`,
|
| 141 |
);
|
| 142 |
}
|
| 143 |
+
}, [isLoading, videosReady, chartsReady]);
|
| 144 |
|
| 145 |
const router = useRouter();
|
| 146 |
const searchParams = useSearchParams();
|
|
|
|
| 357 |
setCurrentTime(timeValue);
|
| 358 |
}
|
| 359 |
}
|
| 360 |
+
}, [searchParams, setCurrentTime]);
|
| 361 |
|
| 362 |
// sync with parent window hf.co/spaces
|
| 363 |
useEffect(() => {
|
|
|
|
| 366 |
});
|
| 367 |
}, []);
|
| 368 |
|
| 369 |
+
const handleKeyDown = useCallback(
|
| 370 |
+
(e: KeyboardEvent) => {
|
| 371 |
+
const { key } = e;
|
| 372 |
+
|
| 373 |
+
if (key === " ") {
|
| 374 |
+
e.preventDefault();
|
| 375 |
+
setIsPlaying((prev: boolean) => !prev);
|
| 376 |
+
} else if (key === "ArrowDown" || key === "ArrowUp") {
|
| 377 |
+
e.preventDefault();
|
| 378 |
+
const nextEpisodeId =
|
| 379 |
+
key === "ArrowDown" ? episodeId + 1 : episodeId - 1;
|
| 380 |
+
const lowestEpisodeId = episodes[0];
|
| 381 |
+
const highestEpisodeId = episodes[episodes.length - 1];
|
| 382 |
+
|
| 383 |
+
if (
|
| 384 |
+
nextEpisodeId >= lowestEpisodeId &&
|
| 385 |
+
nextEpisodeId <= highestEpisodeId
|
| 386 |
+
) {
|
| 387 |
+
router.push(`./episode_${nextEpisodeId}`);
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
},
|
| 391 |
+
[episodeId, episodes, router, setIsPlaying],
|
| 392 |
+
);
|
| 393 |
+
|
| 394 |
// Initialize based on URL time parameter
|
| 395 |
useEffect(() => {
|
| 396 |
// Initialize page based on current episode
|
|
|
|
| 404 |
return () => {
|
| 405 |
window.removeEventListener("keydown", handleKeyDown);
|
| 406 |
};
|
| 407 |
+
}, [episodes, episodeId, pageSize, handleKeyDown]);
|
| 408 |
|
| 409 |
// Only update URL ?t= param when the integer second changes
|
| 410 |
const lastUrlSecondRef = useRef<number>(-1);
|
|
|
|
| 427 |
}
|
| 428 |
}, [isPlaying, currentTime, searchParams]);
|
| 429 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
// Pagination functions
|
| 431 |
const nextPage = () => {
|
| 432 |
if (currentPage < totalPages) {
|
|
|
|
| 558 |
target="_blank"
|
| 559 |
className="block"
|
| 560 |
>
|
| 561 |
+
{/* eslint-disable-next-line @next/next/no-img-element */}
|
| 562 |
<img
|
| 563 |
src="https://github.com/huggingface/lerobot/raw/main/media/readme/lerobot-logo-thumbnail.png"
|
| 564 |
alt="LeRobot Logo"
|