|
@@ -1,22 +1,14 @@
|
|
import useSWR, { useSWRConfig } from "swr";
|
|
import useSWR, { useSWRConfig } from "swr";
|
|
-import { useEffect, useRef, useState } from "react";
|
|
|
|
|
|
+import { useEffect, useMemo, useRef, useState } from "react";
|
|
import { useLockFn } from "ahooks";
|
|
import { useLockFn } from "ahooks";
|
|
import { Virtuoso } from "react-virtuoso";
|
|
import { Virtuoso } from "react-virtuoso";
|
|
-import { Box, IconButton, TextField } from "@mui/material";
|
|
|
|
-import {
|
|
|
|
- MyLocationRounded,
|
|
|
|
- NetworkCheckRounded,
|
|
|
|
- FilterAltRounded,
|
|
|
|
- FilterAltOffRounded,
|
|
|
|
- VisibilityRounded,
|
|
|
|
- VisibilityOffRounded,
|
|
|
|
-} from "@mui/icons-material";
|
|
|
|
import { ApiType } from "../../services/types";
|
|
import { ApiType } from "../../services/types";
|
|
import { updateProxy } from "../../services/api";
|
|
import { updateProxy } from "../../services/api";
|
|
import { getProfiles, patchProfile } from "../../services/cmds";
|
|
import { getProfiles, patchProfile } from "../../services/cmds";
|
|
|
|
+import useFilterProxy, { ProxySortType } from "./use-filter-proxy";
|
|
import delayManager from "../../services/delay";
|
|
import delayManager from "../../services/delay";
|
|
-import useFilterProxy from "./use-filter-proxy";
|
|
|
|
import ProxyItem from "./proxy-item";
|
|
import ProxyItem from "./proxy-item";
|
|
|
|
+import ProxyHead from "./proxy-head";
|
|
|
|
|
|
interface Props {
|
|
interface Props {
|
|
groupName: string;
|
|
groupName: string;
|
|
@@ -30,13 +22,38 @@ const ProxyGlobal = (props: Props) => {
|
|
|
|
|
|
const { mutate } = useSWRConfig();
|
|
const { mutate } = useSWRConfig();
|
|
const [now, setNow] = useState(curProxy || "DIRECT");
|
|
const [now, setNow] = useState(curProxy || "DIRECT");
|
|
|
|
+
|
|
const [showType, setShowType] = useState(true);
|
|
const [showType, setShowType] = useState(true);
|
|
- const [showFilter, setShowFilter] = useState(false);
|
|
|
|
|
|
+ const [sortType, setSortType] = useState<ProxySortType>(0);
|
|
|
|
+
|
|
|
|
+ const [urlText, setUrlText] = useState("");
|
|
const [filterText, setFilterText] = useState("");
|
|
const [filterText, setFilterText] = useState("");
|
|
|
|
|
|
const virtuosoRef = useRef<any>();
|
|
const virtuosoRef = useRef<any>();
|
|
const filterProxies = useFilterProxy(proxies, groupName, filterText);
|
|
const filterProxies = useFilterProxy(proxies, groupName, filterText);
|
|
|
|
|
|
|
|
+ const sortedProxies = useMemo(() => {
|
|
|
|
+ if (sortType === 0) return filterProxies;
|
|
|
|
+
|
|
|
|
+ const list = filterProxies.slice();
|
|
|
|
+
|
|
|
|
+ if (sortType === 1) {
|
|
|
|
+ list.sort((a, b) => a.name.localeCompare(b.name));
|
|
|
|
+ } else {
|
|
|
|
+ list.sort((a, b) => {
|
|
|
|
+ const ad = delayManager.getDelay(a.name, groupName);
|
|
|
|
+ const bd = delayManager.getDelay(b.name, groupName);
|
|
|
|
+
|
|
|
|
+ if (ad === -1) return 1;
|
|
|
|
+ if (bd === -1) return -1;
|
|
|
|
+
|
|
|
|
+ return ad - bd;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return list;
|
|
|
|
+ }, [filterProxies, sortType, groupName]);
|
|
|
|
+
|
|
const { data: profiles } = useSWR("getProfiles", getProfiles);
|
|
const { data: profiles } = useSWR("getProfiles", getProfiles);
|
|
|
|
|
|
const onChangeProxy = useLockFn(async (name: string) => {
|
|
const onChangeProxy = useLockFn(async (name: string) => {
|
|
@@ -61,7 +78,7 @@ const ProxyGlobal = (props: Props) => {
|
|
});
|
|
});
|
|
|
|
|
|
const onLocation = (smooth = true) => {
|
|
const onLocation = (smooth = true) => {
|
|
- const index = filterProxies.findIndex((p) => p.name === now);
|
|
|
|
|
|
+ const index = sortedProxies.findIndex((p) => p.name === now);
|
|
|
|
|
|
if (index >= 0) {
|
|
if (index >= 0) {
|
|
virtuosoRef.current?.scrollToIndex?.({
|
|
virtuosoRef.current?.scrollToIndex?.({
|
|
@@ -73,7 +90,7 @@ const ProxyGlobal = (props: Props) => {
|
|
};
|
|
};
|
|
|
|
|
|
const onCheckAll = useLockFn(async () => {
|
|
const onCheckAll = useLockFn(async () => {
|
|
- const names = filterProxies.map((p) => p.name);
|
|
|
|
|
|
+ const names = sortedProxies.map((p) => p.name);
|
|
|
|
|
|
await delayManager.checkListDelay(
|
|
await delayManager.checkListDelay(
|
|
{ names, groupName, skipNum: 8, maxTimeout: 600 },
|
|
{ names, groupName, skipNum: 8, maxTimeout: 600 },
|
|
@@ -85,10 +102,6 @@ const ProxyGlobal = (props: Props) => {
|
|
|
|
|
|
useEffect(() => onLocation(false), [groupName]);
|
|
useEffect(() => onLocation(false), [groupName]);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
|
- if (!showFilter) setFilterText("");
|
|
|
|
- }, [showFilter]);
|
|
|
|
-
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
if (groupName === "DIRECT") setNow("DIRECT");
|
|
if (groupName === "DIRECT") setNow("DIRECT");
|
|
else if (groupName === "GLOBAL") {
|
|
else if (groupName === "GLOBAL") {
|
|
@@ -112,74 +125,29 @@ const ProxyGlobal = (props: Props) => {
|
|
|
|
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
- <Box
|
|
|
|
- sx={{
|
|
|
|
- px: 3,
|
|
|
|
- my: 0.5,
|
|
|
|
- display: "flex",
|
|
|
|
- alignItems: "center",
|
|
|
|
- button: { mr: 0.5 },
|
|
|
|
- }}
|
|
|
|
- >
|
|
|
|
- <IconButton
|
|
|
|
- size="small"
|
|
|
|
- title="location"
|
|
|
|
- color="inherit"
|
|
|
|
- onClick={() => onLocation(true)}
|
|
|
|
- >
|
|
|
|
- <MyLocationRounded />
|
|
|
|
- </IconButton>
|
|
|
|
-
|
|
|
|
- <IconButton
|
|
|
|
- size="small"
|
|
|
|
- title="delay check"
|
|
|
|
- color="inherit"
|
|
|
|
- onClick={onCheckAll}
|
|
|
|
- >
|
|
|
|
- <NetworkCheckRounded />
|
|
|
|
- </IconButton>
|
|
|
|
-
|
|
|
|
- <IconButton
|
|
|
|
- size="small"
|
|
|
|
- title="proxy detail"
|
|
|
|
- color="inherit"
|
|
|
|
- onClick={() => setShowType(!showType)}
|
|
|
|
- >
|
|
|
|
- {showType ? <VisibilityRounded /> : <VisibilityOffRounded />}
|
|
|
|
- </IconButton>
|
|
|
|
-
|
|
|
|
- <IconButton
|
|
|
|
- size="small"
|
|
|
|
- title="filter"
|
|
|
|
- color="inherit"
|
|
|
|
- onClick={() => setShowFilter(!showFilter)}
|
|
|
|
- >
|
|
|
|
- {showFilter ? <FilterAltRounded /> : <FilterAltOffRounded />}
|
|
|
|
- </IconButton>
|
|
|
|
-
|
|
|
|
- {showFilter && (
|
|
|
|
- <TextField
|
|
|
|
- autoFocus
|
|
|
|
- hiddenLabel
|
|
|
|
- value={filterText}
|
|
|
|
- size="small"
|
|
|
|
- variant="outlined"
|
|
|
|
- placeholder="Filter conditions"
|
|
|
|
- onChange={(e) => setFilterText(e.target.value)}
|
|
|
|
- sx={{ ml: 0.5, flex: "1 1 auto", input: { py: 0.65, px: 1 } }}
|
|
|
|
- />
|
|
|
|
- )}
|
|
|
|
- </Box>
|
|
|
|
|
|
+ <ProxyHead
|
|
|
|
+ sx={{ px: 3, my: 0.5, button: { mr: 0.5 } }}
|
|
|
|
+ showType={showType}
|
|
|
|
+ sortType={sortType}
|
|
|
|
+ urlText={urlText}
|
|
|
|
+ filterText={filterText}
|
|
|
|
+ onLocation={onLocation}
|
|
|
|
+ onCheckDelay={onCheckAll}
|
|
|
|
+ onShowType={setShowType}
|
|
|
|
+ onSortType={setSortType}
|
|
|
|
+ onUrlText={setUrlText}
|
|
|
|
+ onFilterText={setFilterText}
|
|
|
|
+ />
|
|
|
|
|
|
<Virtuoso
|
|
<Virtuoso
|
|
ref={virtuosoRef}
|
|
ref={virtuosoRef}
|
|
style={{ height: "calc(100% - 40px)" }}
|
|
style={{ height: "calc(100% - 40px)" }}
|
|
- totalCount={filterProxies.length}
|
|
|
|
|
|
+ totalCount={sortedProxies.length}
|
|
itemContent={(index) => (
|
|
itemContent={(index) => (
|
|
<ProxyItem
|
|
<ProxyItem
|
|
groupName={groupName}
|
|
groupName={groupName}
|
|
- proxy={filterProxies[index]}
|
|
|
|
- selected={filterProxies[index].name === now}
|
|
|
|
|
|
+ proxy={sortedProxies[index]}
|
|
|
|
+ selected={sortedProxies[index].name === now}
|
|
showType={showType}
|
|
showType={showType}
|
|
onClick={onChangeProxy}
|
|
onClick={onChangeProxy}
|
|
sx={{ py: 0, px: 2 }}
|
|
sx={{ py: 0, px: 2 }}
|