proxies.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import useSWR from "swr";
  2. import { useLockFn } from "ahooks";
  3. import { useTranslation } from "react-i18next";
  4. import { Button, ButtonGroup, Paper } from "@mui/material";
  5. import { getClashConfig, updateConfigs } from "@/services/api";
  6. import { patchClashConfig } from "@/services/cmds";
  7. import { ProxyGroups } from "@/components/proxy/proxy-groups";
  8. import { BasePage } from "@/components/base";
  9. const ProxyPage = () => {
  10. const { t } = useTranslation();
  11. const { data: clashConfig, mutate: mutateClash } = useSWR(
  12. "getClashConfig",
  13. getClashConfig
  14. );
  15. const modeList = ["rule", "global", "direct", "script"];
  16. const curMode = clashConfig?.mode.toLowerCase();
  17. const onChangeMode = useLockFn(async (mode: string) => {
  18. await updateConfigs({ mode });
  19. await patchClashConfig({ mode });
  20. mutateClash();
  21. });
  22. return (
  23. <BasePage
  24. contentStyle={{ height: "100%" }}
  25. title={t("Proxy Groups")}
  26. header={
  27. <ButtonGroup size="small">
  28. {modeList.map((mode) => (
  29. <Button
  30. key={mode}
  31. variant={mode === curMode ? "contained" : "outlined"}
  32. onClick={() => onChangeMode(mode)}
  33. sx={{ textTransform: "capitalize" }}
  34. >
  35. {t(mode)}
  36. </Button>
  37. ))}
  38. </ButtonGroup>
  39. }
  40. >
  41. <Paper
  42. sx={{
  43. borderRadius: 1,
  44. boxShadow: 2,
  45. height: "100%",
  46. boxSizing: "border-box",
  47. py: 1,
  48. }}
  49. >
  50. <ProxyGroups mode={curMode!} />
  51. </Paper>
  52. </BasePage>
  53. );
  54. };
  55. export default ProxyPage;