douyinWEB/frontend/src/lib/useLiveFocusScroll.ts
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

30 lines
901 B
TypeScript

"use client";
import { useEffect, useRef } from "react";
/** Scroll to a DOM id and briefly highlight after data loads. */
export function useLiveFocusScroll(
focusId: string | null | undefined,
elementIdPrefix: string,
ready: boolean,
) {
const doneRef = useRef<string | null>(null);
useEffect(() => {
if (!focusId || !ready) return;
const token = `${elementIdPrefix}${focusId}`;
if (doneRef.current === token) return;
const el = document.getElementById(`${elementIdPrefix}${focusId}`);
if (!el) return;
doneRef.current = token;
const t = window.setTimeout(() => {
el.scrollIntoView({ behavior: "smooth", block: "center" });
el.classList.add("yt-live-focus-highlight");
window.setTimeout(() => el.classList.remove("yt-live-focus-highlight"), 4500);
}, 280);
return () => clearTimeout(t);
}, [focusId, ready, elementIdPrefix]);
}