Files
clash-verge-rev/src/pages/proxy.tsx
T

50 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-01-10 21:25:41 +08:00
import useSWR, { useSWRConfig } from "swr";
import { useEffect } from "react";
2022-01-16 03:11:07 +08:00
import { List, Paper } from "@mui/material";
2021-12-25 22:33:29 +08:00
import { getProxies } from "../services/api";
2022-01-16 03:11:07 +08:00
import BasePage from "../components/base-page";
2022-01-13 02:51:30 +08:00
import ProxyItem from "../components/proxy-item";
2022-01-16 03:11:07 +08:00
import ProxyGroup from "../components/proxy-group";
2021-12-08 23:36:34 +08:00
const ProxyPage = () => {
2022-01-10 21:25:41 +08:00
const { mutate } = useSWRConfig();
2021-12-28 01:47:43 +08:00
const { data: proxiesData } = useSWR("getProxies", getProxies);
2022-01-13 02:51:30 +08:00
const { groups = [], proxies = [] } = proxiesData ?? {};
2022-01-10 21:25:41 +08:00
useEffect(() => {
// fix the empty proxies on the first sight
// this bud only show on the build version
// call twice to avoid something unknown or the delay of the clash startup
setTimeout(() => mutate("getProxies"), 250);
setTimeout(() => mutate("getProxies"), 1000);
}, []);
return (
2022-01-16 03:11:07 +08:00
<BasePage title={groups.length ? "Proxy Groups" : "Proxies"}>
<Paper sx={{ borderRadius: 1, boxShadow: 2, mb: 1 }}>
2022-01-13 02:51:30 +08:00
{groups.length > 0 && (
2021-12-22 02:11:31 +08:00
<List>
{groups.map((group) => (
<ProxyGroup key={group.name} group={group} />
))}
</List>
2022-01-13 02:51:30 +08:00
)}
{!groups.length && (
<List>
{Object.values(proxies).map((proxy) => (
<ProxyItem
key={proxy.name}
proxy={proxy}
selected={false}
sx={{ py: 0, px: 2 }}
/>
))}
</List>
)}
</Paper>
2022-01-16 03:11:07 +08:00
</BasePage>
);
2021-12-08 23:36:34 +08:00
};
export default ProxyPage;