fix: replace channel enable buttons with real Switch toggles
Add shared EnableSwitch, confirm before disable, busy state, and card dimming on shorts/yt-long/tiktok/x. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
f2b3242e7d
commit
d60d3e5ac0
@ -17,6 +17,7 @@ import {
|
|||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
|
||||||
import { DouyinLiveBadge } from "@/components/DouyinLiveBadge";
|
import { DouyinLiveBadge } from "@/components/DouyinLiveBadge";
|
||||||
|
import { EnableSwitch } from "@/components/EnableSwitch";
|
||||||
import { Shell } from "@/components/Shell";
|
import { Shell } from "@/components/Shell";
|
||||||
import { useConfirm } from "@/components/ConfirmDialog";
|
import { useConfirm } from "@/components/ConfirmDialog";
|
||||||
import { useToast } from "@/components/Toast";
|
import { useToast } from "@/components/Toast";
|
||||||
@ -150,6 +151,7 @@ export default function ShortsPage() {
|
|||||||
const [form, setForm] = useState({ ...emptyForm });
|
const [form, setForm] = useState({ ...emptyForm });
|
||||||
const [editId, setEditId] = useState("");
|
const [editId, setEditId] = useState("");
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
|
const [togglingId, setTogglingId] = useState("");
|
||||||
const [msg, setMsg] = useState("");
|
const [msg, setMsg] = useState("");
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [jobFilter, setJobFilter] = useState("");
|
const [jobFilter, setJobFilter] = useState("");
|
||||||
@ -549,6 +551,16 @@ export default function ShortsPage() {
|
|||||||
|
|
||||||
async function toggleChannelEnabled(ch: Channel) {
|
async function toggleChannelEnabled(ch: Channel) {
|
||||||
const turningOn = ch.enabled === false;
|
const turningOn = ch.enabled === false;
|
||||||
|
if (!turningOn) {
|
||||||
|
const ok = await confirm({
|
||||||
|
title: `停用「${ch.name}」?`,
|
||||||
|
message: "关闭后将立即清除该频道全部任务与成片,并停止取样/录制/上传。可随时再开。",
|
||||||
|
confirmLabel: "停用并清任务",
|
||||||
|
destructive: true,
|
||||||
|
});
|
||||||
|
if (!ok) return;
|
||||||
|
}
|
||||||
|
setTogglingId(ch.id);
|
||||||
try {
|
try {
|
||||||
const r = await fetchJson(`/api/shorts/channels/${ch.id}`, {
|
const r = await fetchJson(`/api/shorts/channels/${ch.id}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
@ -557,7 +569,7 @@ export default function ShortsPage() {
|
|||||||
const cleared = r.cleared as { jobs?: number; clips?: number } | undefined;
|
const cleared = r.cleared as { jobs?: number; clips?: number } | undefined;
|
||||||
if (!turningOn && cleared) {
|
if (!turningOn && cleared) {
|
||||||
toast.push(
|
toast.push(
|
||||||
`已停用「${ch.name}」· 清除任务 ${cleared.jobs ?? 0} · 成片 ${cleared.clips ?? 0}`,
|
`已停用 · 清除任务 ${cleared.jobs ?? 0} · 成片 ${cleared.clips ?? 0}`,
|
||||||
"ok",
|
"ok",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -566,6 +578,8 @@ export default function ShortsPage() {
|
|||||||
await load();
|
await load();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.push((e as Error).message, "err");
|
toast.push((e as Error).message, "err");
|
||||||
|
} finally {
|
||||||
|
setTogglingId("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1203,8 +1217,14 @@ export default function ShortsPage() {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={ch.id}
|
key={ch.id}
|
||||||
className={`rounded-xl border bg-gradient-to-br from-white/[0.04] to-transparent p-3 ${
|
className={`rounded-xl border bg-gradient-to-br from-white/[0.04] to-transparent p-3 transition ${
|
||||||
warn ? "border-amber-500/35" : ch.max_met ? "border-teal-500/30" : "border-white/10"
|
full?.enabled === false
|
||||||
|
? "border-white/10 opacity-55"
|
||||||
|
: warn
|
||||||
|
? "border-amber-500/35"
|
||||||
|
: ch.max_met
|
||||||
|
? "border-teal-500/30"
|
||||||
|
: "border-white/10"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<div className="flex items-start justify-between gap-2">
|
<div className="flex items-start justify-between gap-2">
|
||||||
@ -1218,18 +1238,13 @@ export default function ShortsPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{full ? (
|
{full ? (
|
||||||
<button
|
<EnableSwitch
|
||||||
type="button"
|
checked={full.enabled !== false}
|
||||||
title={full.enabled === false ? "启用此频道" : "停用并清除任务"}
|
busy={togglingId === full.id}
|
||||||
onClick={() => void toggleChannelEnabled(full)}
|
accent="teal"
|
||||||
className={`shrink-0 rounded-lg px-2 py-1 text-[10px] ${
|
label={full.enabled === false ? "关" : "开"}
|
||||||
full.enabled === false
|
onChange={() => void toggleChannelEnabled(full)}
|
||||||
? "bg-white/5 text-slate-400"
|
/>
|
||||||
: "bg-teal-500/15 text-teal-200"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{full.enabled === false ? "已停" : "启用中"}
|
|
||||||
</button>
|
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
<div className="relative mt-3 h-1.5 overflow-hidden rounded-full bg-white/10">
|
<div className="relative mt-3 h-1.5 overflow-hidden rounded-full bg-white/10">
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import {
|
|||||||
import { Shell } from "@/components/Shell";
|
import { Shell } from "@/components/Shell";
|
||||||
import { useConfirm } from "@/components/ConfirmDialog";
|
import { useConfirm } from "@/components/ConfirmDialog";
|
||||||
import { useToast } from "@/components/Toast";
|
import { useToast } from "@/components/Toast";
|
||||||
|
import { EnableSwitch } from "@/components/EnableSwitch";
|
||||||
import { PageLoader } from "@/components/ui";
|
import { PageLoader } from "@/components/ui";
|
||||||
import {
|
import {
|
||||||
TikTokUpcomingUploadRow,
|
TikTokUpcomingUploadRow,
|
||||||
@ -130,6 +131,7 @@ export default function TikTokPage() {
|
|||||||
const rightPanelRef = useRef<HTMLElement>(null);
|
const rightPanelRef = useRef<HTMLElement>(null);
|
||||||
|
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [togglingId, setTogglingId] = useState("");
|
||||||
const [status, setStatus] = useState<any>(null);
|
const [status, setStatus] = useState<any>(null);
|
||||||
const [channels, setChannels] = useState<Channel[]>([]);
|
const [channels, setChannels] = useState<Channel[]>([]);
|
||||||
const [socksProfiles, setSocksProfiles] = useState<SocksProfile[]>([]);
|
const [socksProfiles, setSocksProfiles] = useState<SocksProfile[]>([]);
|
||||||
@ -421,6 +423,16 @@ export default function TikTokPage() {
|
|||||||
|
|
||||||
const toggleChannelEnabled = async (ch: Channel) => {
|
const toggleChannelEnabled = async (ch: Channel) => {
|
||||||
const turningOn = ch.enabled === false;
|
const turningOn = ch.enabled === false;
|
||||||
|
if (!turningOn) {
|
||||||
|
const ok = await confirm({
|
||||||
|
title: `停用「${ch.name}」?`,
|
||||||
|
message: "关闭后将立即清除该账号全部任务与成片,并停止取样/录制/上传。可随时再开。",
|
||||||
|
confirmLabel: "停用并清任务",
|
||||||
|
destructive: true,
|
||||||
|
});
|
||||||
|
if (!ok) return;
|
||||||
|
}
|
||||||
|
setTogglingId(ch.id);
|
||||||
try {
|
try {
|
||||||
const r = await fetchJson(`/api/tiktok/channels/${ch.id}`, {
|
const r = await fetchJson(`/api/tiktok/channels/${ch.id}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
@ -429,7 +441,7 @@ export default function TikTokPage() {
|
|||||||
const cleared = r.cleared as { jobs?: number; clips?: number } | undefined;
|
const cleared = r.cleared as { jobs?: number; clips?: number } | undefined;
|
||||||
if (!turningOn && cleared) {
|
if (!turningOn && cleared) {
|
||||||
toast.push(
|
toast.push(
|
||||||
`已停用「${ch.name}」· 清除任务 ${cleared.jobs ?? 0} · 成片 ${cleared.clips ?? 0}`,
|
`已停用 · 清除任务 ${cleared.jobs ?? 0} · 成片 ${cleared.clips ?? 0}`,
|
||||||
"ok",
|
"ok",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -438,6 +450,8 @@ export default function TikTokPage() {
|
|||||||
void load();
|
void load();
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
toast.push(e?.message || "切换失败", "err");
|
toast.push(e?.message || "切换失败", "err");
|
||||||
|
} finally {
|
||||||
|
setTogglingId("");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1156,10 +1170,21 @@ export default function TikTokPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span className={`shrink-0 text-[10px] ${cookieAgeClass(full)}`}>
|
<div className="flex shrink-0 flex-col items-end gap-1.5">
|
||||||
|
{full ? (
|
||||||
|
<EnableSwitch
|
||||||
|
checked={full.enabled !== false}
|
||||||
|
busy={togglingId === full.id}
|
||||||
|
accent="pink"
|
||||||
|
label={full.enabled === false ? "关" : "开"}
|
||||||
|
onChange={() => void toggleChannelEnabled(full)}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
<span className={`text-[10px] ${cookieAgeClass(full)}`}>
|
||||||
{full?.authorized ? "Cookie 就绪" : "未配置"}
|
{full?.authorized ? "Cookie 就绪" : "未配置"}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
{(full?.follower_count || full?.video_count || full?.heart_count) ? (
|
{(full?.follower_count || full?.video_count || full?.heart_count) ? (
|
||||||
<div className="mt-2 flex flex-wrap gap-2 text-[10px] text-slate-400">
|
<div className="mt-2 flex flex-wrap gap-2 text-[10px] text-slate-400">
|
||||||
<span>粉丝 {fmtCount(full?.follower_count)}</span>
|
<span>粉丝 {fmtCount(full?.follower_count)}</span>
|
||||||
@ -1220,15 +1245,6 @@ export default function TikTokPage() {
|
|||||||
刷新资料
|
刷新资料
|
||||||
</button>
|
</button>
|
||||||
) : null}
|
) : null}
|
||||||
{full && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => void toggleChannelEnabled(full)}
|
|
||||||
className="rounded-lg bg-white/5 px-2 py-1 text-[11px]"
|
|
||||||
>
|
|
||||||
{full.enabled === false ? "启用" : "停用"}
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
{full && (
|
{full && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
@ -9,7 +9,9 @@ import {
|
|||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
|
||||||
import { Shell } from "@/components/Shell";
|
import { Shell } from "@/components/Shell";
|
||||||
|
import { useConfirm } from "@/components/ConfirmDialog";
|
||||||
import { useToast } from "@/components/Toast";
|
import { useToast } from "@/components/Toast";
|
||||||
|
import { EnableSwitch } from "@/components/EnableSwitch";
|
||||||
import { fetchJson, fmtTs } from "@/lib/api";
|
import { fetchJson, fmtTs } from "@/lib/api";
|
||||||
import {
|
import {
|
||||||
kindLabel,
|
kindLabel,
|
||||||
@ -62,8 +64,10 @@ const NAV: { id: TabId; emoji: string; label: string }[] = [
|
|||||||
|
|
||||||
export default function XPage() {
|
export default function XPage() {
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
const confirm = useConfirm();
|
||||||
const [tab, setTab] = useState<TabId>("workbench");
|
const [tab, setTab] = useState<TabId>("workbench");
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [togglingId, setTogglingId] = useState("");
|
||||||
const [agents, setAgents] = useState<X2Agent[]>([]);
|
const [agents, setAgents] = useState<X2Agent[]>([]);
|
||||||
const [accounts, setAccounts] = useState<X2Account[]>([]);
|
const [accounts, setAccounts] = useState<X2Account[]>([]);
|
||||||
const [jobs, setJobs] = useState<XJob[]>([]);
|
const [jobs, setJobs] = useState<XJob[]>([]);
|
||||||
@ -133,6 +137,16 @@ export default function XPage() {
|
|||||||
const toggleAccountEnabled = useCallback(
|
const toggleAccountEnabled = useCallback(
|
||||||
async (acc: X2Account) => {
|
async (acc: X2Account) => {
|
||||||
const turningOn = acc.enabled === false;
|
const turningOn = acc.enabled === false;
|
||||||
|
if (!turningOn) {
|
||||||
|
const ok = await confirm({
|
||||||
|
title: `停用 @${acc.username || "—"}?`,
|
||||||
|
message: "关闭后将立即清除该账号切片任务并取消插件队列,禁止继续发帖/切片。可随时再开。",
|
||||||
|
confirmLabel: "停用并清任务",
|
||||||
|
destructive: true,
|
||||||
|
});
|
||||||
|
if (!ok) return;
|
||||||
|
}
|
||||||
|
setTogglingId(acc.id);
|
||||||
try {
|
try {
|
||||||
const r = await fetchJson(`/api/x2/accounts/${encodeURIComponent(acc.id)}`, {
|
const r = await fetchJson(`/api/x2/accounts/${encodeURIComponent(acc.id)}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
@ -142,7 +156,7 @@ export default function XPage() {
|
|||||||
if (!turningOn && cleared) {
|
if (!turningOn && cleared) {
|
||||||
const x2n = cleared.x2_cancelled?.count ?? 0;
|
const x2n = cleared.x2_cancelled?.count ?? 0;
|
||||||
toast.push(
|
toast.push(
|
||||||
`已停用 @${acc.username || "—"} · 切片 ${cleared.jobs ?? 0} · 插件任务 ${x2n}`,
|
`已停用 · 切片 ${cleared.jobs ?? 0} · 插件任务 ${x2n}`,
|
||||||
"ok",
|
"ok",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -151,9 +165,11 @@ export default function XPage() {
|
|||||||
await load();
|
await load();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
toast.push((e as Error)?.message || "切换失败", "err");
|
toast.push((e as Error)?.message || "切换失败", "err");
|
||||||
|
} finally {
|
||||||
|
setTogglingId("");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[load, toast],
|
[confirm, load, toast],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -421,13 +437,18 @@ export default function XPage() {
|
|||||||
|
|
||||||
{accounts.length > 0 ? (
|
{accounts.length > 0 ? (
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<div className="mb-2 text-[11px] uppercase tracking-[0.14em] text-slate-500">账号开关</div>
|
<div className="mb-2 flex items-center justify-between gap-2">
|
||||||
|
<div className="text-[11px] uppercase tracking-[0.14em] text-slate-500">账号开关</div>
|
||||||
|
<div className="text-[10px] text-slate-500">关闭会清切片任务</div>
|
||||||
|
</div>
|
||||||
<div className="grid gap-2 sm:grid-cols-2 xl:grid-cols-3">
|
<div className="grid gap-2 sm:grid-cols-2 xl:grid-cols-3">
|
||||||
{accounts.map((a) => (
|
{accounts.map((a) => (
|
||||||
<div
|
<div
|
||||||
key={a.id}
|
key={a.id}
|
||||||
className={`flex items-center justify-between gap-2 rounded-xl border px-3 py-2.5 ${
|
className={`flex items-center justify-between gap-3 rounded-xl border px-3 py-2.5 transition ${
|
||||||
a.enabled === false ? "border-white/10 bg-white/[0.02]" : "border-orange-400/25 bg-orange-500/5"
|
a.enabled === false
|
||||||
|
? "border-white/10 bg-white/[0.02] opacity-60"
|
||||||
|
: "border-orange-400/25 bg-orange-500/5"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<div className="min-w-0">
|
<div className="min-w-0">
|
||||||
@ -436,18 +457,14 @@ export default function XPage() {
|
|||||||
<div className="truncate text-[11px] text-slate-500">{a.display_name}</div>
|
<div className="truncate text-[11px] text-slate-500">{a.display_name}</div>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
<button
|
<EnableSwitch
|
||||||
type="button"
|
checked={a.enabled !== false}
|
||||||
title={a.enabled === false ? "启用此账号" : "停用并清除切片任务"}
|
busy={togglingId === a.id}
|
||||||
onClick={() => void toggleAccountEnabled(a)}
|
accent="orange"
|
||||||
className={`shrink-0 rounded-lg px-2.5 py-1 text-[11px] ${
|
size="md"
|
||||||
a.enabled === false
|
label={a.enabled === false ? "关" : "开"}
|
||||||
? "bg-white/5 text-slate-400"
|
onChange={() => void toggleAccountEnabled(a)}
|
||||||
: "bg-orange-500/20 text-orange-100"
|
/>
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{a.enabled === false ? "已停" : "启用中"}
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import {
|
|||||||
import { Shell } from "@/components/Shell";
|
import { Shell } from "@/components/Shell";
|
||||||
import { useConfirm } from "@/components/ConfirmDialog";
|
import { useConfirm } from "@/components/ConfirmDialog";
|
||||||
import { useToast } from "@/components/Toast";
|
import { useToast } from "@/components/Toast";
|
||||||
|
import { EnableSwitch } from "@/components/EnableSwitch";
|
||||||
import { OauthClientBadge, normalizeOauthProfileId } from "@/components/OauthClientBadge";
|
import { OauthClientBadge, normalizeOauthProfileId } from "@/components/OauthClientBadge";
|
||||||
import { YtChannelProfileSnippet, type YtProfileSnippet } from "@/components/YtChannelProfileSnippet";
|
import { YtChannelProfileSnippet, type YtProfileSnippet } from "@/components/YtChannelProfileSnippet";
|
||||||
import { buildChannelMeta } from "@/lib/ytChannelMeta";
|
import { buildChannelMeta } from "@/lib/ytChannelMeta";
|
||||||
@ -190,6 +191,7 @@ export default function YtLongPage() {
|
|||||||
const [form, setForm] = useState({ ...emptyForm });
|
const [form, setForm] = useState({ ...emptyForm });
|
||||||
const [editId, setEditId] = useState("");
|
const [editId, setEditId] = useState("");
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
|
const [togglingId, setTogglingId] = useState("");
|
||||||
const [msg, setMsg] = useState("");
|
const [msg, setMsg] = useState("");
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [jobFilter, setJobFilter] = useState("");
|
const [jobFilter, setJobFilter] = useState("");
|
||||||
@ -455,6 +457,16 @@ export default function YtLongPage() {
|
|||||||
|
|
||||||
async function toggleChannelEnabled(ch: Channel) {
|
async function toggleChannelEnabled(ch: Channel) {
|
||||||
const turningOn = ch.enabled === false;
|
const turningOn = ch.enabled === false;
|
||||||
|
if (!turningOn) {
|
||||||
|
const ok = await confirm({
|
||||||
|
title: `停用「${ch.name}」?`,
|
||||||
|
message: "关闭后将立即清除该频道全部长视频任务,并停止取样/录制/上传。可随时再开。",
|
||||||
|
confirmLabel: "停用并清任务",
|
||||||
|
destructive: true,
|
||||||
|
});
|
||||||
|
if (!ok) return;
|
||||||
|
}
|
||||||
|
setTogglingId(ch.id);
|
||||||
try {
|
try {
|
||||||
const r = await fetchJson(`/api/yt-long/channels/${ch.id}`, {
|
const r = await fetchJson(`/api/yt-long/channels/${ch.id}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
@ -462,13 +474,15 @@ export default function YtLongPage() {
|
|||||||
});
|
});
|
||||||
const cleared = r.cleared as { jobs?: number } | undefined;
|
const cleared = r.cleared as { jobs?: number } | undefined;
|
||||||
if (!turningOn && cleared) {
|
if (!turningOn && cleared) {
|
||||||
toast.push(`已停用「${ch.name}」· 清除任务 ${cleared.jobs ?? 0}`, "ok");
|
toast.push(`已停用 · 清除任务 ${cleared.jobs ?? 0}`, "ok");
|
||||||
} else {
|
} else {
|
||||||
toast.push(turningOn ? `已启用「${ch.name}」` : `已停用「${ch.name}」`, "ok");
|
toast.push(turningOn ? `已启用「${ch.name}」` : `已停用「${ch.name}」`, "ok");
|
||||||
}
|
}
|
||||||
await load();
|
await load();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.push((e as Error).message, "err");
|
toast.push((e as Error).message, "err");
|
||||||
|
} finally {
|
||||||
|
setTogglingId("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -675,8 +689,10 @@ export default function YtLongPage() {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={ch.id}
|
key={ch.id}
|
||||||
className={`rounded-xl border bg-gradient-to-br from-white/[0.04] to-transparent p-3 ${
|
className={`rounded-xl border bg-gradient-to-br from-white/[0.04] to-transparent p-3 transition ${
|
||||||
gap <= 0 && ch.enabled !== false
|
full?.enabled === false
|
||||||
|
? "border-white/10 opacity-55"
|
||||||
|
: gap <= 0 && ch.enabled !== false
|
||||||
? "border-teal-500/30"
|
? "border-teal-500/30"
|
||||||
: "border-white/10"
|
: "border-white/10"
|
||||||
}`}
|
}`}
|
||||||
@ -692,18 +708,13 @@ export default function YtLongPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{full ? (
|
{full ? (
|
||||||
<button
|
<EnableSwitch
|
||||||
type="button"
|
checked={full.enabled !== false}
|
||||||
title={full.enabled === false ? "启用此频道" : "停用并清除任务"}
|
busy={togglingId === full.id}
|
||||||
onClick={() => void toggleChannelEnabled(full)}
|
accent="amber"
|
||||||
className={`shrink-0 rounded-lg px-2 py-1 text-[10px] ${
|
label={full.enabled === false ? "关" : "开"}
|
||||||
full.enabled === false
|
onChange={() => void toggleChannelEnabled(full)}
|
||||||
? "bg-white/5 text-slate-400"
|
/>
|
||||||
: "bg-teal-500/15 text-teal-200"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{full.enabled === false ? "已停" : "启用中"}
|
|
||||||
</button>
|
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
<div className="relative mt-3 h-1.5 overflow-hidden rounded-full bg-white/10">
|
<div className="relative mt-3 h-1.5 overflow-hidden rounded-full bg-white/10">
|
||||||
|
|||||||
90
frontend/src/components/EnableSwitch.tsx
Normal file
90
frontend/src/components/EnableSwitch.tsx
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
type Accent = "teal" | "pink" | "orange" | "amber";
|
||||||
|
|
||||||
|
const TRACK_ON: Record<Accent, string> = {
|
||||||
|
teal: "bg-teal-400 shadow-[0_0_12px_rgba(45,212,191,0.35)]",
|
||||||
|
pink: "bg-pink-400 shadow-[0_0_12px_rgba(244,114,182,0.35)]",
|
||||||
|
orange: "bg-orange-400 shadow-[0_0_12px_rgba(251,146,60,0.35)]",
|
||||||
|
amber: "bg-amber-400 shadow-[0_0_12px_rgba(251,191,36,0.35)]",
|
||||||
|
};
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
checked: boolean;
|
||||||
|
onChange: (next: boolean) => void;
|
||||||
|
disabled?: boolean;
|
||||||
|
busy?: boolean;
|
||||||
|
label?: string;
|
||||||
|
accent?: Accent;
|
||||||
|
size?: "sm" | "md";
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Compact iOS-style enable switch for channel / account cards. */
|
||||||
|
export function EnableSwitch({
|
||||||
|
checked,
|
||||||
|
onChange,
|
||||||
|
disabled = false,
|
||||||
|
busy = false,
|
||||||
|
label,
|
||||||
|
accent = "teal",
|
||||||
|
size = "sm",
|
||||||
|
className = "",
|
||||||
|
}: Props) {
|
||||||
|
const locked = disabled || busy;
|
||||||
|
const trackW = size === "md" ? "h-6 w-11" : "h-5 w-9";
|
||||||
|
const knob = size === "md" ? "h-5 w-5" : "h-4 w-4";
|
||||||
|
const travel = size === "md" ? "translate-x-5" : "translate-x-4";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`inline-flex shrink-0 select-none items-center gap-2 ${className}`}
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
{label ? (
|
||||||
|
<span
|
||||||
|
className={`text-[10px] font-medium tracking-wide ${
|
||||||
|
checked ? "text-slate-200" : "text-slate-500"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
role="switch"
|
||||||
|
aria-checked={checked}
|
||||||
|
aria-busy={busy || undefined}
|
||||||
|
aria-label={checked ? "关闭" : "开启"}
|
||||||
|
title={checked ? "关闭将清除任务并停止取样/上传" : "开启后恢复自动取样与上传"}
|
||||||
|
disabled={locked}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
if (locked) return;
|
||||||
|
onChange(!checked);
|
||||||
|
}}
|
||||||
|
className={[
|
||||||
|
"relative inline-flex shrink-0 items-center rounded-full transition-colors duration-200 ease-out",
|
||||||
|
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/30 focus-visible:ring-offset-2 focus-visible:ring-offset-[#0b1220]",
|
||||||
|
trackW,
|
||||||
|
checked ? TRACK_ON[accent] : "bg-white/15",
|
||||||
|
locked ? "cursor-wait opacity-70" : "cursor-pointer",
|
||||||
|
].join(" ")}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={[
|
||||||
|
"pointer-events-none inline-block transform rounded-full bg-white shadow-md transition duration-200 ease-out",
|
||||||
|
knob,
|
||||||
|
checked ? travel : "translate-x-0.5",
|
||||||
|
].join(" ")}
|
||||||
|
/>
|
||||||
|
{busy ? (
|
||||||
|
<span className="pointer-events-none absolute inset-0 flex items-center justify-center">
|
||||||
|
<span className="h-2.5 w-2.5 animate-spin rounded-full border border-white/40 border-t-white" />
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user