`req` opens its blocking dialog for 400/409/422/5xx only. A 403/404/429 was left to the caller and a 502-504 or lost connection got just the self-clearing connection notice, so 34 mutations without a reporting onError and 15 direct api writes with a bare or missing catch failed in silence: a hidden channel that snapped back, a share link that never revoked, a confirmed account delete that ended with nothing said. - lib/queryClient: one MutationCache reporter. react-query awaits it BEFORE the mutation's own onError, so it waits a task and skips a failure the site already reported; the toast title comes from `meta.failTitle`, `meta.errorShownInline` opts out. - notifyActionError: title names WHAT failed, the line under it says WHY (`failureReason`: a structured localized detail, else the status). It marks the error reported (`markReported`), so nothing reports one failure twice; `notifyKnownFailure` for a site's own specific sentence. - Every silent site named (45 new HU/EN titles, 4 reasons). Stale "the global dialog shows it" comments corrected on the job actions, channel block, Plex sync, cookies, download enqueue, account delete and usePref. - Channels passed the tag hook's channel id to the reporter as the error; the tag and priority hooks now report themselves, with the real error. - A contract test keeps every useMutation naming its failure; CLAUDE.md gains the pattern row. - history.dom.test: the "navigates only once the entries are back" assertion raced an async act's macrotask flush (1 in 5 runs); it now asserts from a later popstate listener.
118 lines
3.8 KiB
TypeScript
118 lines
3.8 KiB
TypeScript
import { lazy, Suspense, useState } from "react";
|
|
import { qk } from "../lib/queryKeys";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import Modal from "./ui/Modal";
|
|
import { Button } from "./ui/Button";
|
|
import { api } from "../lib/api";
|
|
import { invalidateDownloads } from "../lib/downloads";
|
|
|
|
// Lazy: the full profile editor only opens from the dialog's "manage presets" affordance.
|
|
const ProfileEditor = lazy(() => import("./ProfileEditor"));
|
|
import { notify } from "../lib/notifications";
|
|
import { notifyActionError } from "../lib/actionErrors";
|
|
import { navigateTo } from "../lib/nav";
|
|
import { inputCls } from "./ui/form";
|
|
|
|
// Preset picker shown when the user hits Download on a card / in the player, or adds a URL from
|
|
// the Download Center. Enqueues via the API and points the user at the Download Center.
|
|
export default function DownloadDialog({
|
|
source,
|
|
title,
|
|
onClose,
|
|
}: {
|
|
source: string;
|
|
title?: string | null;
|
|
onClose: () => void;
|
|
}) {
|
|
const { t } = useTranslation();
|
|
const qc = useQueryClient();
|
|
const profilesQ = useQuery({ queryKey: qk.downloadProfiles(), queryFn: api.downloadProfiles });
|
|
const [profileId, setProfileId] = useState<number | null>(null);
|
|
const [name, setName] = useState("");
|
|
const [busy, setBusy] = useState(false);
|
|
const [manage, setManage] = useState(false);
|
|
|
|
const profiles = profilesQ.data ?? [];
|
|
const chosen = profileId ?? profiles[0]?.id ?? null;
|
|
|
|
const submit = async () => {
|
|
if (!chosen || busy) return;
|
|
setBusy(true);
|
|
try {
|
|
await api.enqueueDownload({
|
|
source,
|
|
profile_id: chosen,
|
|
display_name: name.trim() || undefined,
|
|
});
|
|
invalidateDownloads(qc);
|
|
notify({
|
|
level: "success",
|
|
message: t("downloads.dialog.added"),
|
|
action: { label: t("downloads.dialog.view"), onClick: () => navigateTo("downloads") },
|
|
});
|
|
onClose();
|
|
} catch (e) {
|
|
// A quota or validation refusal (422/409) is already in the global error dialog, which the
|
|
// reporter skips; a 403/404/429 or a lost connection is not, and used to leave the dialog
|
|
// open with nothing said (E11 S2b).
|
|
notifyActionError(e, t("errors.writeFailed.enqueueDownload"));
|
|
setBusy(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Modal title={t("downloads.dialog.title")} onClose={onClose}>
|
|
{title && <p className="text-sm text-muted mb-4 line-clamp-2">{title}</p>}
|
|
|
|
<label className="block text-sm font-medium mb-1">{t("downloads.dialog.profile")}</label>
|
|
<select
|
|
value={chosen ?? ""}
|
|
onChange={(e) => setProfileId(Number(e.target.value))}
|
|
className={inputCls}
|
|
>
|
|
{profiles.map((p) => (
|
|
<option key={p.id} value={p.id}>
|
|
{p.name}
|
|
</option>
|
|
))}
|
|
</select>
|
|
<button
|
|
type="button"
|
|
onClick={() => setManage(true)}
|
|
className="text-xs text-accent hover:underline mt-1 mb-4"
|
|
>
|
|
{t("downloads.dialog.manage")}
|
|
</button>
|
|
|
|
<label className="block text-sm font-medium mb-1">{t("downloads.dialog.nameLabel")}</label>
|
|
<input
|
|
value={name}
|
|
onChange={(e) => setName(e.target.value)}
|
|
placeholder={t("downloads.dialog.namePlaceholder")}
|
|
className={`${inputCls} mb-5`}
|
|
/>
|
|
|
|
<div className="flex justify-end gap-2">
|
|
<Button variant="ghost" size="sm" onClick={onClose}>
|
|
{t("downloads.actions.cancel")}
|
|
</Button>
|
|
<Button variant="primary" size="sm" onClick={submit} disabled={busy || !chosen}>
|
|
{t("downloads.dialog.submit")}
|
|
</Button>
|
|
</div>
|
|
|
|
{manage && (
|
|
<Suspense fallback={null}>
|
|
<ProfileEditor
|
|
onClose={() => {
|
|
setManage(false);
|
|
profilesQ.refetch();
|
|
}}
|
|
/>
|
|
</Suspense>
|
|
)}
|
|
</Modal>
|
|
);
|
|
}
|