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
c927419c
There was an error fetching the commit references. Please try again later.
Unverified
Commit
c927419c
authored
3 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
refactor: enhanced mode ui component
parent
c0090269
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/profile/enhanced.tsx
+91
-0
91 additions, 0 deletions
src/components/profile/enhanced.tsx
src/pages/profiles.tsx
+4
-68
4 additions, 68 deletions
src/pages/profiles.tsx
with
95 additions
and
68 deletions
src/components/profile/enhanced.tsx
0 → 100644
+
91
−
0
View file @
c927419c
import
useSWR
from
"
swr
"
;
import
{
useLockFn
}
from
"
ahooks
"
;
import
{
Box
,
Grid
}
from
"
@mui/material
"
;
import
{
getProfiles
,
deleteProfile
,
enhanceProfiles
,
changeProfileChain
,
}
from
"
../../services/cmds
"
;
import
{
CmdType
}
from
"
../../services/types
"
;
import
Notice
from
"
../base/base-notice
"
;
import
ProfileMore
from
"
./profile-more
"
;
interface
Props
{
items
:
CmdType
.
ProfileItem
[];
chain
:
string
[];
}
const
EnhancedMode
=
(
props
:
Props
)
=>
{
const
{
items
,
chain
}
=
props
;
const
{
mutate
}
=
useSWR
(
"
getProfiles
"
,
getProfiles
);
// handler
const
onEnhance
=
useLockFn
(
enhanceProfiles
);
const
onEnhanceEnable
=
useLockFn
(
async
(
uid
:
string
)
=>
{
if
(
chain
.
includes
(
uid
))
return
;
const
newChain
=
[...
chain
,
uid
];
await
changeProfileChain
(
newChain
);
mutate
((
conf
=
{})
=>
({
...
conf
,
chain
:
newChain
}),
true
);
});
const
onEnhanceDisable
=
useLockFn
(
async
(
uid
:
string
)
=>
{
if
(
!
chain
.
includes
(
uid
))
return
;
const
newChain
=
chain
.
filter
((
i
)
=>
i
!==
uid
);
await
changeProfileChain
(
newChain
);
mutate
((
conf
=
{})
=>
({
...
conf
,
chain
:
newChain
}),
true
);
});
const
onEnhanceDelete
=
useLockFn
(
async
(
uid
:
string
)
=>
{
try
{
await
onEnhanceDisable
(
uid
);
await
deleteProfile
(
uid
);
mutate
();
}
catch
(
err
:
any
)
{
Notice
.
error
(
err
?.
message
||
err
.
toString
());
}
});
const
onMoveTop
=
useLockFn
(
async
(
uid
:
string
)
=>
{
if
(
!
chain
.
includes
(
uid
))
return
;
const
newChain
=
[
uid
].
concat
(
chain
.
filter
((
i
)
=>
i
!==
uid
));
await
changeProfileChain
(
newChain
);
mutate
((
conf
=
{})
=>
({
...
conf
,
chain
:
newChain
}),
true
);
});
const
onMoveEnd
=
useLockFn
(
async
(
uid
:
string
)
=>
{
if
(
!
chain
.
includes
(
uid
))
return
;
const
newChain
=
chain
.
filter
((
i
)
=>
i
!==
uid
).
concat
([
uid
]);
await
changeProfileChain
(
newChain
);
mutate
((
conf
=
{})
=>
({
...
conf
,
chain
:
newChain
}),
true
);
});
return
(
<
Box
sx
=
{
{
mt
:
4
}
}
>
<
Grid
container
spacing
=
{
2
}
>
{
items
.
map
((
item
)
=>
(
<
Grid
item
xs
=
{
12
}
sm
=
{
6
}
key
=
{
item
.
file
}
>
<
ProfileMore
selected
=
{
!!
chain
.
includes
(
item
.
uid
)
}
itemData
=
{
item
}
onEnable
=
{
()
=>
onEnhanceEnable
(
item
.
uid
)
}
onDisable
=
{
()
=>
onEnhanceDisable
(
item
.
uid
)
}
onDelete
=
{
()
=>
onEnhanceDelete
(
item
.
uid
)
}
onMoveTop
=
{
()
=>
onMoveTop
(
item
.
uid
)
}
onMoveEnd
=
{
()
=>
onMoveEnd
(
item
.
uid
)
}
onEnhance
=
{
onEnhance
}
/>
</
Grid
>
))
}
</
Grid
>
</
Box
>
);
};
export
default
EnhancedMode
;
This diff is collapsed.
Click to expand it.
src/pages/profiles.tsx
+
4
−
68
View file @
c927419c
...
@@ -6,18 +6,15 @@ import { useTranslation } from "react-i18next";
...
@@ -6,18 +6,15 @@ import { useTranslation } from "react-i18next";
import
{
import
{
getProfiles
,
getProfiles
,
patchProfile
,
patchProfile
,
deleteProfile
,
selectProfile
,
selectProfile
,
importProfile
,
importProfile
,
enhanceProfiles
,
changeProfileChain
,
}
from
"
../services/cmds
"
;
}
from
"
../services/cmds
"
;
import
{
getProxies
,
updateProxy
}
from
"
../services/api
"
;
import
{
getProxies
,
updateProxy
}
from
"
../services/api
"
;
import
Notice
from
"
../components/base/base-notice
"
;
import
Notice
from
"
../components/base/base-notice
"
;
import
BasePage
from
"
../components/base/base-page
"
;
import
BasePage
from
"
../components/base/base-page
"
;
import
ProfileNew
from
"
../components/profile/profile-new
"
;
import
ProfileNew
from
"
../components/profile/profile-new
"
;
import
ProfileItem
from
"
../components/profile/profile-item
"
;
import
ProfileItem
from
"
../components/profile/profile-item
"
;
import
Profile
Mo
r
e
from
"
../components/profile/
profile-more
"
;
import
Enhanced
Mo
d
e
from
"
../components/profile/
enhanced
"
;
const
ProfilePage
=
()
=>
{
const
ProfilePage
=
()
=>
{
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
...
@@ -130,54 +127,6 @@ const ProfilePage = () => {
...
@@ -130,54 +127,6 @@ const ProfilePage = () => {
}
}
});
});
/** enhanced profile mode */
const
chain
=
profiles
.
chain
||
[];
const
onEnhance
=
useLockFn
(
enhanceProfiles
);
const
onEnhanceEnable
=
useLockFn
(
async
(
uid
:
string
)
=>
{
if
(
chain
.
includes
(
uid
))
return
;
const
newChain
=
[...
chain
,
uid
];
await
changeProfileChain
(
newChain
);
mutate
(
"
getProfiles
"
,
{
...
profiles
,
chain
:
newChain
},
true
);
});
const
onEnhanceDisable
=
useLockFn
(
async
(
uid
:
string
)
=>
{
if
(
!
chain
.
includes
(
uid
))
return
;
const
newChain
=
chain
.
filter
((
i
)
=>
i
!==
uid
);
await
changeProfileChain
(
newChain
);
mutate
(
"
getProfiles
"
,
{
...
profiles
,
chain
:
newChain
},
true
);
});
const
onEnhanceDelete
=
useLockFn
(
async
(
uid
:
string
)
=>
{
try
{
await
onEnhanceDisable
(
uid
);
await
deleteProfile
(
uid
);
mutate
(
"
getProfiles
"
);
}
catch
(
err
:
any
)
{
Notice
.
error
(
err
?.
message
||
err
.
toString
());
}
});
const
onMoveTop
=
useLockFn
(
async
(
uid
:
string
)
=>
{
if
(
!
chain
.
includes
(
uid
))
return
;
const
newChain
=
[
uid
].
concat
(
chain
.
filter
((
i
)
=>
i
!==
uid
));
await
changeProfileChain
(
newChain
);
mutate
(
"
getProfiles
"
,
{
...
profiles
,
chain
:
newChain
},
true
);
});
const
onMoveEnd
=
useLockFn
(
async
(
uid
:
string
)
=>
{
if
(
!
chain
.
includes
(
uid
))
return
;
const
newChain
=
chain
.
filter
((
i
)
=>
i
!==
uid
).
concat
([
uid
]);
await
changeProfileChain
(
newChain
);
mutate
(
"
getProfiles
"
,
{
...
profiles
,
chain
:
newChain
},
true
);
});
return
(
return
(
<
BasePage
title
=
{
t
(
"
Profiles
"
)
}
>
<
BasePage
title
=
{
t
(
"
Profiles
"
)
}
>
<
Box
sx
=
{
{
display
:
"
flex
"
,
mb
:
2.5
}
}
>
<
Box
sx
=
{
{
display
:
"
flex
"
,
mb
:
2.5
}
}
>
...
@@ -216,22 +165,9 @@ const ProfilePage = () => {
...
@@ -216,22 +165,9 @@ const ProfilePage = () => {
))
}
))
}
</
Grid
>
</
Grid
>
<
Grid
container
spacing
=
{
2
}
sx
=
{
{
mt
:
3
}
}
>
{
enhanceItems
.
length
&&
(
{
enhanceItems
.
map
((
item
)
=>
(
<
EnhancedMode
items
=
{
enhanceItems
}
chain
=
{
profiles
.
chain
||
[]
}
/>
<
Grid
item
xs
=
{
12
}
sm
=
{
6
}
key
=
{
item
.
file
}
>
)
}
<
ProfileMore
selected
=
{
!!
profiles
.
chain
?.
includes
(
item
.
uid
)
}
itemData
=
{
item
}
onEnable
=
{
()
=>
onEnhanceEnable
(
item
.
uid
)
}
onDisable
=
{
()
=>
onEnhanceDisable
(
item
.
uid
)
}
onDelete
=
{
()
=>
onEnhanceDelete
(
item
.
uid
)
}
onMoveTop
=
{
()
=>
onMoveTop
(
item
.
uid
)
}
onMoveEnd
=
{
()
=>
onMoveEnd
(
item
.
uid
)
}
onEnhance
=
{
onEnhance
}
/>
</
Grid
>
))
}
</
Grid
>
<
ProfileNew
open
=
{
dialogOpen
}
onClose
=
{
()
=>
setDialogOpen
(
false
)
}
/>
<
ProfileNew
open
=
{
dialogOpen
}
onClose
=
{
()
=>
setDialogOpen
(
false
)
}
/>
</
BasePage
>
</
BasePage
>
...
...
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