Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download web/src/shell/FreezeNotice.tsx from fsanyoto/runloopable: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/spaces/fsanyoto/runloopable/resolve/main/web/src/shell/FreezeNotice.tsx
- Command line
-
hf download hf://spaces/fsanyoto/runloopable/web/src/shell/FreezeNotice.tsx
-
curl -L -o FreezeNotice.tsx https://huggingface.co/spaces/fsanyoto/runloopable/resolve/main/web/src/shell/FreezeNotice.tsx
1.78 kB
| import { useEffect, useState } from "react"; | |
| import { getFreezeNotice } from "../settings/settingsApi"; | |
| import type { FreezeNoticeState } from "../settings/settingsApi"; | |
| export function useFreezeNotice(): FreezeNoticeState { | |
| const [notice, setNotice] = useState<FreezeNoticeState>({ enabled: false, text: "" }); | |
| useEffect(() => { | |
| let live = true; | |
| let request: AbortController | null = null; | |
| const refresh = () => { | |
| if (document.hidden) return; | |
| request?.abort(); | |
| const controller = new AbortController(); | |
| request = controller; | |
| void getFreezeNotice(controller.signal).then((result) => { | |
| if (!live || controller.signal.aborted || !result.ok) return; | |
| const next = result.data; | |
| if (typeof next?.enabled === "boolean" && typeof next.text === "string") { | |
| setNotice((current) => current.enabled === next.enabled && current.text === next.text | |
| ? current : { enabled: next.enabled, text: next.text }); | |
| } | |
| }); | |
| }; | |
| refresh(); | |
| const timer = window.setInterval(refresh, 30_000); | |
| window.addEventListener("focus", refresh); | |
| document.addEventListener("visibilitychange", refresh); | |
| return () => { | |
| live = false; | |
| request?.abort(); | |
| window.clearInterval(timer); | |
| window.removeEventListener("focus", refresh); | |
| document.removeEventListener("visibilitychange", refresh); | |
| }; | |
| }, []); | |
| return notice; | |
| } | |
| export default function FreezeNotice({ notice, standalone = false }: { | |
| notice?: FreezeNoticeState; | |
| standalone?: boolean; | |
| }) { | |
| if (!notice?.enabled) return null; | |
| const message = <span className="freeze-notice" role="status">{notice.text}</span>; | |
| return standalone ? <div className="freeze-notice-band">{message}</div> : message; | |
| } | |