A pure move (git mv, history kept): 333 files leave components/, which now holds only the platform layer (ui/) and the legal pages. The shell is the frame (App, header, nav rail, palette, boot); each page lives in modules/<page>/ with its rail, store and tests; what several pages share sits in features/<name>/; the shared-link page is watch/. Domain-free helpers went straight to ui/ (ViewSwitcher, FilterRail, the confirm dialog, the language switcher, the copy rows). Every relative specifier was rewritten (imports, dynamic imports, vi.mock, new URL), and the contract tests that scan sources now scan the whole app source, not only components/ — each glob was counted before and after so none went green over fewer files. The locale-format rule matched `/src/components/` only, so the move would have taken ~300 files out from under its i18n-singleton check; it now covers every folder that holds components, with a test per folder.
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import { lazy, Suspense, useState } from "react";
|
|
import { qk } from "../../lib/queryKeys";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { Download } from "lucide-react";
|
|
import clsx from "clsx";
|
|
// Lazy: the download dialog (+ its profile editor) loads only when a card's download button is
|
|
// clicked, so it never ships in the feed chunk for the majority who just browse.
|
|
const DownloadDialog = lazy(() => import("./DownloadDialog"));
|
|
import { api } from "../../lib/api";
|
|
import { IconButton } from "../../components/ui/IconButton";
|
|
|
|
// Self-contained download affordance for a video card / the player. Reflects the video's current state from
|
|
// the shared per-user download index (one polled query shared across every card).
|
|
export default function DownloadButton({
|
|
videoId,
|
|
title,
|
|
variant = "ghost",
|
|
size = "sm",
|
|
}: {
|
|
videoId: string;
|
|
title?: string | null;
|
|
variant?: "ghost" | "outline" | "overlay";
|
|
size?: "sm" | "md";
|
|
}) {
|
|
const { t } = useTranslation();
|
|
const indexQ = useQuery({
|
|
queryKey: qk.downloadIndex(),
|
|
queryFn: api.downloadIndex,
|
|
staleTime: 10000,
|
|
});
|
|
const [open, setOpen] = useState(false);
|
|
|
|
const status = indexQ.data?.[videoId];
|
|
const downloaded = status === "done";
|
|
const inQueue = status === "queued" || status === "running" || status === "paused";
|
|
const label = downloaded
|
|
? t("downloads.button.downloaded")
|
|
: inQueue
|
|
? t("downloads.button.queued")
|
|
: t("downloads.button.label");
|
|
|
|
return (
|
|
<>
|
|
<IconButton
|
|
variant={variant}
|
|
size={size}
|
|
onClick={(e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
setOpen(true);
|
|
}}
|
|
label={label}
|
|
>
|
|
{/* The state is in the glyph: downloaded or queued is the accent, a running one pulses. */}
|
|
<Download
|
|
className={clsx(
|
|
(downloaded || inQueue) && "text-accent",
|
|
inQueue && "motion-safe:animate-pulse",
|
|
)}
|
|
/>
|
|
</IconButton>
|
|
{open && (
|
|
<Suspense fallback={null}>
|
|
<DownloadDialog source={videoId} title={title} onClose={() => setOpen(false)} />
|
|
</Suspense>
|
|
)}
|
|
</>
|
|
);
|
|
}
|