✨ Add refresh button

This commit is contained in:
刘嘉伟 committed 2026-03-11 17:56:12 +08:00
1 parent 1569ff2bd1
commit d07531c8d0
2 files changed
+21 -7

No files matched your search

@@ -25,7 +25,7 @@ export function ServerDetailPage() {
const [mounted, setMounted] = useState(false);
const [deleteProxyId, setDeleteProxyId] = useState<string | null>(null);
const [copiedId, setCopiedId] = useState<string | null>(null);
const { proxies, togglingId, toggleStatus, deleteProxy } = useServerProxies(id);
const { proxies, togglingId, toggleStatus, deleteProxy, refreshing, refresh } = useServerProxies(id);
const handleCopy = (text: string, key: string) => {
navigator.clipboard.writeText(text).then(() => {
@@ -310,10 +310,21 @@ export function ServerDetailPage() {
<Card size="3">
<Flex justify="between" align="center" mb="4">
<Heading size="4">{t("proxy.title")}</Heading>
<Button size="1" onClick={() => navigate(`/proxies/new?serverId=${id}`)}>
<Icon icon="lucide:plus" width="14" height="14" />
{t("proxy.addProxy")}
</Button>
<Flex gap="2">
<Button size="1" variant="soft" onClick={refresh} disabled={refreshing}>
<Icon
icon="lucide:refresh-cw"
width="14"
height="14"
className={refreshing ? "animate-spin" : ""}
/>
{t("proxy.refresh")}
</Button>
<Button size="1" onClick={() => navigate(`/proxies/new?serverId=${id}`)}>
<Icon icon="lucide:plus" width="14" height="14" />
{t("proxy.addProxy")}
</Button>
</Flex>
</Flex>
{proxies.length === 0 ? (
@@ -7,10 +7,12 @@ import type { Proxy } from "../Proxies/useProxies";
export function useServerProxies(serverId: string | undefined) {
const [proxies, setProxies] = useState<Proxy[]>([]);
const [loading, setLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false);
const [togglingId, setTogglingId] = useState<string | null>(null);
const fetchProxies = useCallback(async () => {
const fetchProxies = useCallback(async (isManual = false) => {
if (!serverId) return;
if (isManual) setRefreshing(true);
try {
const result = await pb.collection("fh_proxies").getFullList<Proxy>({
filter: `serverId = "${serverId}"`,
@@ -22,6 +24,7 @@ export function useServerProxies(serverId: string | undefined) {
toast.error(err instanceof Error ? err.message : "Failed to fetch proxies");
} finally {
setLoading(false);
if (isManual) setRefreshing(false);
}
}, [serverId]);
@@ -66,5 +69,5 @@ export function useServerProxies(serverId: string | undefined) {
}
};
return { proxies, loading, togglingId, toggleStatus, deleteProxy, refresh: fetchProxies };
return { proxies, loading, refreshing, togglingId, toggleStatus, deleteProxy, refresh: () => fetchProxies(true) };
}