Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Clash Verge
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Clash Verge
Commits
b09b7b11
There was an error fetching the commit references. Please try again later.
Unverified
Commit
b09b7b11
authored
3 years ago
by
GyDi
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: save global selected
parent
1a7b3c72
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/proxy/proxy-global.tsx
+22
-3
22 additions, 3 deletions
src/components/proxy/proxy-global.tsx
src/pages/profiles.tsx
+7
-5
7 additions, 5 deletions
src/pages/profiles.tsx
with
29 additions
and
8 deletions
src/components/proxy/proxy-global.tsx
+
22
−
3
View file @
b09b7b11
import
useSWR
,
{
useSWRConfig
}
from
"
swr
"
;
import
{
useEffect
,
useRef
,
useState
}
from
"
react
"
;
import
{
useEffect
,
useRef
,
useState
}
from
"
react
"
;
import
{
useSWRConfig
}
from
"
swr
"
;
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
{
Box
,
IconButton
,
TextField
}
from
"
@mui/material
"
;
...
@@ -13,6 +13,7 @@ import {
...
@@ -13,6 +13,7 @@ import {
}
from
"
@mui/icons-material
"
;
}
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
delayManager
from
"
../../services/delay
"
;
import
delayManager
from
"
../../services/delay
"
;
import
useFilterProxy
from
"
./use-filter-proxy
"
;
import
useFilterProxy
from
"
./use-filter-proxy
"
;
import
ProxyItem
from
"
./proxy-item
"
;
import
ProxyItem
from
"
./proxy-item
"
;
...
@@ -23,6 +24,7 @@ interface Props {
...
@@ -23,6 +24,7 @@ interface Props {
proxies
:
ApiType
.
ProxyItem
[];
proxies
:
ApiType
.
ProxyItem
[];
}
}
// this component will be used for DIRECT/GLOBAL
const
ProxyGlobal
=
(
props
:
Props
)
=>
{
const
ProxyGlobal
=
(
props
:
Props
)
=>
{
const
{
groupName
,
curProxy
,
proxies
}
=
props
;
const
{
groupName
,
curProxy
,
proxies
}
=
props
;
...
@@ -35,10 +37,27 @@ const ProxyGlobal = (props: Props) => {
...
@@ -35,10 +37,27 @@ const ProxyGlobal = (props: Props) => {
const
virtuosoRef
=
useRef
<
any
>
();
const
virtuosoRef
=
useRef
<
any
>
();
const
filterProxies
=
useFilterProxy
(
proxies
,
groupName
,
filterText
);
const
filterProxies
=
useFilterProxy
(
proxies
,
groupName
,
filterText
);
const
{
data
:
profiles
}
=
useSWR
(
"
getProfiles
"
,
getProfiles
);
const
onChangeProxy
=
useLockFn
(
async
(
name
:
string
)
=>
{
const
onChangeProxy
=
useLockFn
(
async
(
name
:
string
)
=>
{
await
updateProxy
(
"
GLOBAL
"
,
name
);
await
updateProxy
(
groupName
,
name
);
mutate
(
"
getProxies
"
);
setNow
(
name
);
setNow
(
name
);
if
(
groupName
===
"
DIRECT
"
)
return
;
// update global selected
const
profile
=
profiles
?.
items
?.
find
((
p
)
=>
p
.
uid
===
profiles
.
current
);
if
(
!
profile
)
return
;
if
(
!
profile
.
selected
)
profile
.
selected
=
[];
const
index
=
profile
.
selected
.
findIndex
((
item
)
=>
item
.
name
===
groupName
);
if
(
index
<
0
)
{
profile
.
selected
.
unshift
({
name
:
groupName
,
now
:
name
});
}
else
{
profile
.
selected
[
index
]
=
{
name
:
groupName
,
now
:
name
};
}
await
patchProfile
(
profiles
!
.
current
!
,
{
selected
:
profile
.
selected
});
});
});
const
onLocation
=
(
smooth
=
true
)
=>
{
const
onLocation
=
(
smooth
=
true
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
src/pages/profiles.tsx
+
7
−
5
View file @
b09b7b11
...
@@ -29,6 +29,7 @@ const ProfilePage = () => {
...
@@ -29,6 +29,7 @@ const ProfilePage = () => {
const
{
data
:
profiles
=
{}
}
=
useSWR
(
"
getProfiles
"
,
getProfiles
);
const
{
data
:
profiles
=
{}
}
=
useSWR
(
"
getProfiles
"
,
getProfiles
);
// distinguish type
const
{
regularItems
,
enhanceItems
}
=
useMemo
(()
=>
{
const
{
regularItems
,
enhanceItems
}
=
useMemo
(()
=>
{
const
items
=
profiles
.
items
||
[];
const
items
=
profiles
.
items
||
[];
const
chain
=
profiles
.
chain
||
[];
const
chain
=
profiles
.
chain
||
[];
...
@@ -48,6 +49,7 @@ const ProfilePage = () => {
...
@@ -48,6 +49,7 @@ const ProfilePage = () => {
return
{
regularItems
,
enhanceItems
};
return
{
regularItems
,
enhanceItems
};
},
[
profiles
]);
},
[
profiles
]);
// sync selected proxy
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
profiles
.
current
==
null
)
return
;
if
(
profiles
.
current
==
null
)
return
;
...
@@ -65,9 +67,10 @@ const ProfilePage = () => {
...
@@ -65,9 +67,10 @@ const ProfilePage = () => {
selected
.
map
((
each
)
=>
[
each
.
name
!
,
each
.
now
!
])
selected
.
map
((
each
)
=>
[
each
.
name
!
,
each
.
now
!
])
);
);
// todo: enhance error handle
let
hasChange
=
false
;
let
hasChange
=
false
;
proxiesData
.
groups
.
forEach
((
group
)
=>
{
const
{
global
,
groups
}
=
proxiesData
;
[
global
,
...
groups
].
forEach
((
group
)
=>
{
const
{
name
,
now
}
=
group
;
const
{
name
,
now
}
=
group
;
if
(
!
now
||
selectedMap
[
name
]
===
now
)
return
;
if
(
!
now
||
selectedMap
[
name
]
===
now
)
return
;
...
@@ -78,15 +81,14 @@ const ProfilePage = () => {
...
@@ -78,15 +81,14 @@ const ProfilePage = () => {
updateProxy
(
name
,
selectedMap
[
name
]);
updateProxy
(
name
,
selectedMap
[
name
]);
}
}
});
});
// update profile selected list
// update profile selected list
profile
.
selected
=
Object
.
entries
(
selectedMap
).
map
(([
name
,
now
])
=>
({
profile
.
selected
=
Object
.
entries
(
selectedMap
).
map
(([
name
,
now
])
=>
({
name
,
name
,
now
,
now
,
}));
}));
patchProfile
(
current
!
,
{
selected
:
profile
.
selected
}).
catch
(
patchProfile
(
current
!
,
{
selected
:
profile
.
selected
});
console
.
error
);
// update proxies cache
// update proxies cache
if
(
hasChange
)
mutate
(
"
getProxies
"
,
getProxies
());
if
(
hasChange
)
mutate
(
"
getProxies
"
,
getProxies
());
},
100
);
},
100
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment