diff --git a/src/pages/proxy.tsx b/src/pages/proxy.tsx index 1c36ca70d3c11f693760fdc4f9edd73f9f144b14..c0d8e58f3484f708695662a5b6b8d92b1bd64538 100644 --- a/src/pages/proxy.tsx +++ b/src/pages/proxy.tsx @@ -1,19 +1,11 @@ -import { useEffect, useState } from "react"; +import useSWR from "swr"; import { Box, List, Typography } from "@mui/material"; import services from "../services"; import ProxyGroup from "../components/proxy-group"; -import type { ProxyGroupItem } from "../services/proxy"; const ProxyPage = () => { - const [groups, setGroups] = useState<ProxyGroupItem[]>([]); - - useEffect(() => { - // Todo - // result cache - services.getProxyInfo().then((res) => { - setGroups(res.groups); - }); - }, []); + const { data } = useSWR("getProxies", services.getProxies); + const { groups = [] } = data ?? {}; return ( <Box sx={{ width: 0.9, maxWidth: "850px", mx: "auto", mb: 2 }}> diff --git a/src/pages/rules.tsx b/src/pages/rules.tsx index be63f42393c3cd5eea4eac8aca14f531cb9f31e0..7e4f250ded8706d5c9ce384cbf0600d13023259b 100644 --- a/src/pages/rules.tsx +++ b/src/pages/rules.tsx @@ -1,6 +1,7 @@ import { useRef, useState } from "react"; import useSWR, { useSWRConfig } from "swr"; import { Box, Button, Grid, TextField, Typography } from "@mui/material"; +import services from "../services"; import { getProfiles, importProfile, @@ -35,6 +36,7 @@ const RulesPage = () => { putProfiles(index) .then(() => { mutate("getProfiles", { ...profiles, current: index }, true); + mutate("getProxies", services.getProxies()); }) .catch((err) => { console.error(err); diff --git a/src/services/proxy.ts b/src/services/proxy.ts index 3dbdae8780a7704872edb7fd74442be6e365bc5a..1f29ac9c2e07dfdb3552727e89979c0d5f95404b 100644 --- a/src/services/proxy.ts +++ b/src/services/proxy.ts @@ -17,7 +17,7 @@ export type ProxyGroupItem = Omit<ProxyItem, "all"> & { }; /// Get the Proxy infomation -export async function getProxyInfo() { +export async function getProxies() { const axiosIns = await getAxios(); const response = await axiosIns.get<any, any>("/proxies"); const proxies = (response?.proxies ?? {}) as Record<string, ProxyItem>;