docs(plan): on-demand site detail page parsing (HHClub details.php)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
94fd48bff2
commit
ac478673bc
39 files changed
+2446
-339
No files matched your search
@@ -0,0 +1,110 @@
|
||||
import type { SearchSiteMode, SiteListItem } from "@umt/contracts";
|
||||
import { LoaderCircle } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { useSettings, useUpdateSettings } from "~/api/settings.ts";
|
||||
import { ChipToggleGroup } from "~/components/library/parts.tsx";
|
||||
import { Button } from "~/components/ui/button.tsx";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "~/components/ui/dialog.tsx";
|
||||
import { errorMessage } from "~/lib/api.ts";
|
||||
import { cn } from "~/lib/utils.ts";
|
||||
|
||||
// 站点页「搜索站点」:settings.search.defaultSiteMode —— 搜资源时站点选择的初始值,也是 API 不带 sites 时的站点范围。
|
||||
|
||||
const MODES: { value: SearchSiteMode; label: string; hint: string }[] = [
|
||||
{ value: "default", label: "默认站点", hint: "站点卡上打开了「默认参与搜索」的站点" },
|
||||
{ value: "all", label: "全部站点", hint: "全部已启用站点" },
|
||||
{ value: "custom", label: "指定站点", hint: "只查下面选中的站点" },
|
||||
];
|
||||
|
||||
export function SearchDefaultDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
sites,
|
||||
}: {
|
||||
open: boolean;
|
||||
onOpenChange: (o: boolean) => void;
|
||||
sites: SiteListItem[];
|
||||
}) {
|
||||
const settings = useSettings();
|
||||
const update = useUpdateSettings();
|
||||
const [mode, setMode] = useState<SearchSiteMode>("default");
|
||||
const [ids, setIds] = useState<string[]>([]);
|
||||
useEffect(() => {
|
||||
if (!open || !settings.data) return;
|
||||
setMode(settings.data.search?.defaultSiteMode ?? "default");
|
||||
setIds(settings.data.search?.siteIds ?? []);
|
||||
}, [open, settings.data]);
|
||||
const enabled = sites.filter((s) => s.enabled);
|
||||
|
||||
const save = () =>
|
||||
update.mutate(
|
||||
{ search: { defaultSiteMode: mode, siteIds: mode === "custom" ? ids : [] } },
|
||||
{
|
||||
onSuccess: () => {
|
||||
toast.success("搜索站点已保存");
|
||||
onOpenChange(false);
|
||||
},
|
||||
onError: (e) => toast.error(errorMessage(e, "保存失败")),
|
||||
},
|
||||
);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>搜索站点</DialogTitle>
|
||||
<DialogDescription>搜资源时默认查哪些站点。每次搜索前仍可改选,本机会记住上次的选择。</DialogDescription>
|
||||
</DialogHeader>
|
||||
<fieldset aria-label="默认范围" className="m-0 space-y-1.5 border-0 p-0">
|
||||
{MODES.map((m) => (
|
||||
<button
|
||||
key={m.value}
|
||||
type="button"
|
||||
aria-pressed={mode === m.value}
|
||||
onClick={() => setMode(m.value)}
|
||||
className={cn(
|
||||
"block w-full cursor-pointer rounded-lg border px-3 py-2 text-left transition-colors duration-micro",
|
||||
mode === m.value ? "pill-selected" : "border-border hover:bg-foreground/[0.04]",
|
||||
)}
|
||||
>
|
||||
<span className="block text-sm font-medium text-foreground">{m.label}</span>
|
||||
<span className="block text-meta text-muted-foreground">
|
||||
{m.hint}
|
||||
{m.value === "default"
|
||||
? `(${enabled.filter((s) => s.searchDefault !== false).length} 个)`
|
||||
: m.value === "all"
|
||||
? `(${enabled.length} 个)`
|
||||
: ""}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</fieldset>
|
||||
{mode === "custom" ? (
|
||||
<ChipToggleGroup
|
||||
label="站点"
|
||||
options={enabled.map((s) => ({ value: s.id, label: s.name }))}
|
||||
value={ids.filter((id) => enabled.some((s) => s.id === id))}
|
||||
onChange={setIds}
|
||||
/>
|
||||
) : null}
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)} disabled={update.isPending}>
|
||||
取消
|
||||
</Button>
|
||||
<Button onClick={save} disabled={update.isPending || (mode === "custom" && ids.length === 0)}>
|
||||
{update.isPending ? <LoaderCircle className="animate-spin" /> : null}
|
||||
保存
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { Link } from "react-router";
|
||||
import { toast } from "sonner";
|
||||
import { snapshotStale, useSnapshotSite, useToggleSite } from "~/api/sites.ts";
|
||||
import { snapshotStale, useSnapshotSite, useToggleSite, useUpdateSite } from "~/api/sites.ts";
|
||||
import { DataTable } from "~/components/console/data-table.tsx";
|
||||
import { consolePath } from "~/components/console/nav.ts";
|
||||
import { StatusBadge } from "~/components/console/status-badge.tsx";
|
||||
@@ -76,6 +76,31 @@ function EnableSwitch({ site, withLabel }: { site: SiteListItem; withLabel?: boo
|
||||
);
|
||||
}
|
||||
|
||||
/** 默认参与搜索:搜资源时「默认站点」集合 */
|
||||
function SearchDefaultSwitch({ site }: { site: SiteListItem }) {
|
||||
const update = useUpdateSite();
|
||||
const on = site.searchDefault !== false;
|
||||
return (
|
||||
<span className="mr-auto flex items-center gap-2 text-meta text-muted-foreground">
|
||||
<Switch
|
||||
id={`site-sd-${site.id}`}
|
||||
checked={on}
|
||||
disabled={update.isPending}
|
||||
onCheckedChange={(v) =>
|
||||
update.mutate(
|
||||
{ id: site.id, body: { searchDefault: v } },
|
||||
{
|
||||
onSuccess: () => toast.success(v ? `${site.name} 默认参与搜索` : `${site.name} 不再默认参与搜索`),
|
||||
onError: (e) => toast.error(errorMessage(e)),
|
||||
},
|
||||
)
|
||||
}
|
||||
/>
|
||||
<label htmlFor={`site-sd-${site.id}`}>默认参与搜索</label>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** "更多"菜单:更新凭证、编辑、快照、启停、删除 */
|
||||
export function SiteMoreMenu({ site, onDialog }: { site: SiteListItem; onDialog: (d: SiteDialog) => void }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -305,6 +330,7 @@ export function SiteCard({ site, checks, onDialog }: Props) {
|
||||
</dl>
|
||||
|
||||
<footer className="mt-4 flex flex-wrap items-center justify-end gap-2 border-t border-border/60 pt-3">
|
||||
<SearchDefaultSwitch site={site} />
|
||||
{acc ? (
|
||||
<CheckButtons site={site} checks={checks} />
|
||||
) : (
|
||||
|
||||
@@ -323,6 +323,7 @@ export function SiteEditSheet({ site, onClose }: { site: SiteListItem; onClose:
|
||||
snapshotEnabled: site.snapshotEnabled,
|
||||
intervalMin: site.snapshotIntervalSec ? String(Math.round(site.snapshotIntervalSec / 60)) : "",
|
||||
proxy: site.proxy,
|
||||
searchDefault: site.searchDefault !== false,
|
||||
});
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
const set = <K extends keyof typeof v>(k: K, val: (typeof v)[K]) => setV((s) => ({ ...s, [k]: val }));
|
||||
@@ -364,6 +365,7 @@ export function SiteEditSheet({ site, onClose }: { site: SiteListItem; onClose:
|
||||
snapshotEnabled: v.snapshotEnabled,
|
||||
snapshotIntervalSec: interval ? interval * 60 : null,
|
||||
proxy: v.proxy,
|
||||
searchDefault: v.searchDefault,
|
||||
},
|
||||
});
|
||||
toast.success(`${v.name.trim()} 已保存`);
|
||||
@@ -453,6 +455,20 @@ export function SiteEditSheet({ site, onClose }: { site: SiteListItem; onClose:
|
||||
<span className="block text-muted-foreground">走「站点默认」里的代理地址;没填代理地址时不生效</span>
|
||||
</label>
|
||||
</div>
|
||||
<div className="mb-2 flex items-start gap-3">
|
||||
<Switch
|
||||
id="se-search"
|
||||
checked={v.searchDefault}
|
||||
onCheckedChange={(x) => set("searchDefault", x)}
|
||||
disabled={busy}
|
||||
/>
|
||||
<label htmlFor="se-search" className="text-caption">
|
||||
<span className="block font-medium text-foreground">默认参与搜索</span>
|
||||
<span className="block text-muted-foreground">
|
||||
搜资源选「默认站点」时查这个站点;全部站点或指定站点时另选
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<p className="text-meta text-muted-foreground">User-Agent 随凭证保存,在"更新凭证"里填写。</p>
|
||||
</div>
|
||||
</DetailSheet>
|
||||
|
||||
Reference in new issue
Block a user