E32 S3. The compiler skipped 93 functions; it now skips 29 (try/finally shapes, two suppressions,
VirtualGrid). react-hooks/refs hits 245 -> 31.
- Popover engine: `ref={pop.refs.setReference}` made the compiler treat the whole popover handle as
a ref, so every component holding one was skipped (21 call sites, the engine and its surface
among them). The setter is destructured now; the same for useScrollFade and useReturnFocus.
- Render-phase `ref.current = x` writes moved to `useEffectEvent` where only effects read them,
else to the new `useLatest` (written in a layout effect) / `useStableCallback`.
- FocusSafeButton (under every Button) read the focused element during render; it reads it through
useSyncExternalStore, which React asks on every render instead of a cached memo.
Bugs this surfaced, fixed:
- Combobox: a chip could keep showing its raw id. The label cache was a ref an effect filled after
the render that needed it; it is state merged during render now (test seen RED).
- useUndoable rendered from a ref plus a forced re-render; compiled, that memoizes a stale value.
The history is state now, mirrored in a ref for the stable callbacks.
- ConfigPanel and the saved-views editor re-seeded their drafts in an effect, painting the stale
draft for a frame; both adjust during render against the remembered key.
- Toaster's handover is written after commit instead of during render; a new test pins that the
inherited set is taken once, at the takeover (seen RED on a per-render re-read).
- IssueComposer mutated a ref prop as a one-shot focus token; it is plain state.
- PlexBrowse wrote its info-scroll memory from an effect declared before the ref, past its own
"one writer" rule; the writer comes first now and the effect goes through it.
The compiler ratchet drops to the measured 29 and now also requires FocusSafeButton and the popover
engine to compile.
113 lines
3.6 KiB
TypeScript
113 lines
3.6 KiB
TypeScript
import { useState } from "react";
|
|
import {
|
|
BarChart3,
|
|
Clock,
|
|
Film,
|
|
History,
|
|
RefreshCw,
|
|
Users,
|
|
Zap,
|
|
type LucideIcon,
|
|
} from "lucide-react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { type MyStatus } from "../lib/api";
|
|
import { formatEta, formatNumber } from "../lib/format";
|
|
import { PopoverSurface } from "./ui/AnchoredPopover";
|
|
import { useAnchoredPopover } from "./ui/anchoredPopoverHooks";
|
|
import { Button } from "./ui/Button";
|
|
import { SURFACE } from "./ui/surfaces";
|
|
|
|
// The channel-manager catalog stats, collapsed from a crowded inline row into a compact "Stats" chip
|
|
// that reveals the numbers on hover (reuses the AnchoredPopover hover mode). One row per stat, each
|
|
// with a leading icon. Kept in the manager's own toolbar (the header's SyncStatus is global; these
|
|
// are channel-catalog figures).
|
|
export default function ChannelStatsPopover({ status }: { status: MyStatus }) {
|
|
const { t, i18n } = useTranslation();
|
|
const lang = i18n.language;
|
|
const [open, setOpen] = useState(false);
|
|
const pop = useAnchoredPopover({
|
|
open,
|
|
onOpenChange: setOpen,
|
|
mode: "hover",
|
|
placement: "bottom-end",
|
|
offset: 8,
|
|
});
|
|
const { setReference } = pop.refs;
|
|
|
|
// Each row keeps the per-stat explanation the old inline stats carried (as a native `title` on the
|
|
// row), so hovering a figure still tells the user what it counts — the guidance is not lost.
|
|
const rows: { icon: LucideIcon; label: string; value: string | number; hint: string }[] = [
|
|
{
|
|
icon: Users,
|
|
label: t("channels.stats.channels"),
|
|
value: status.channels_total,
|
|
hint: t("channels.stats.channelsHint"),
|
|
},
|
|
{
|
|
icon: RefreshCw,
|
|
label: t("channels.stats.recentSynced"),
|
|
value: `${status.channels_recent_synced}/${status.channels_total}`,
|
|
hint: t("channels.stats.recentSyncedHint"),
|
|
},
|
|
{
|
|
icon: History,
|
|
label: t("channels.stats.fullHistory"),
|
|
value: `${status.channels_deep_done}/${status.channels_deep_requested}`,
|
|
hint: t("channels.stats.fullHistoryHint"),
|
|
},
|
|
...(status.deep_pending_count > 0
|
|
? [
|
|
{
|
|
icon: Clock,
|
|
label: t("channels.stats.left"),
|
|
value: formatEta(t, status.deep_eta_seconds),
|
|
hint: t("channels.stats.leftHint", { count: status.deep_pending_count }),
|
|
},
|
|
]
|
|
: []),
|
|
{
|
|
icon: Film,
|
|
label: t("channels.stats.myVideos"),
|
|
value: formatNumber(status.my_videos, lang),
|
|
hint: t("channels.stats.myVideosHint"),
|
|
},
|
|
{
|
|
icon: Zap,
|
|
label: t("channels.stats.quotaLeft"),
|
|
value: formatNumber(status.quota_remaining_today, lang),
|
|
hint: t("channels.stats.quotaLeftHint"),
|
|
},
|
|
];
|
|
|
|
return (
|
|
<>
|
|
<Button
|
|
variant="glass"
|
|
size="sm"
|
|
icon={<BarChart3 aria-hidden="true" />}
|
|
ref={setReference}
|
|
{...pop.getReferenceProps()}
|
|
>
|
|
{t("channels.stats.label")}
|
|
</Button>
|
|
<PopoverSurface
|
|
popover={pop}
|
|
ariaLabel={t("channels.stats.label")}
|
|
className={`${SURFACE.popover} w-60 p-2 text-xs animate-[popIn_0.16s_ease]`}
|
|
>
|
|
{rows.map((r) => (
|
|
<div
|
|
key={r.label}
|
|
title={r.hint}
|
|
className="flex cursor-help items-center gap-2.5 px-1.5 py-1.5"
|
|
>
|
|
<r.icon className="h-4 w-4 shrink-0 text-muted" aria-hidden="true" />
|
|
<span className="flex-1 text-muted">{r.label}</span>
|
|
<span className="tabular-nums font-medium text-fg">{r.value}</span>
|
|
</div>
|
|
))}
|
|
</PopoverSurface>
|
|
</>
|
|
);
|
|
}
|