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
17f1c487
There was an error fetching the commit references. Please try again later.
Unverified
Commit
17f1c487
authored
3 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
feat: edit profile item
parent
8dc2c1a3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/components/profile/profile-edit.tsx
+93
-0
93 additions, 0 deletions
src/components/profile/profile-edit.tsx
src/components/profile/profile-item.tsx
+30
-9
30 additions, 9 deletions
src/components/profile/profile-item.tsx
src/services/types.ts
+0
-1
0 additions, 1 deletion
src/services/types.ts
with
123 additions
and
10 deletions
src/components/profile/profile-edit.tsx
0 → 100644
+
93
−
0
View file @
17f1c487
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
useLockFn
}
from
"
ahooks
"
;
import
{
mutate
}
from
"
swr
"
;
import
{
Button
,
Dialog
,
DialogActions
,
DialogContent
,
DialogTitle
,
TextField
,
}
from
"
@mui/material
"
;
import
{
CmdType
}
from
"
../../services/types
"
;
import
{
patchProfile
}
from
"
../../services/cmds
"
;
import
Notice
from
"
../base/base-notice
"
;
interface
Props
{
open
:
boolean
;
itemData
:
CmdType
.
ProfileItem
;
onClose
:
()
=>
void
;
}
// edit the profile item
const
ProfileEdit
=
(
props
:
Props
)
=>
{
const
{
open
,
itemData
,
onClose
}
=
props
;
// todo: more type
const
[
name
,
setName
]
=
useState
(
itemData
.
name
);
const
[
desc
,
setDesc
]
=
useState
(
itemData
.
desc
);
const
[
url
,
setUrl
]
=
useState
(
itemData
.
url
);
useEffect
(()
=>
{
if
(
itemData
)
{
setName
(
itemData
.
name
);
setDesc
(
itemData
.
desc
);
setUrl
(
itemData
.
url
);
}
},
[
itemData
]);
const
onUpdate
=
useLockFn
(
async
()
=>
{
try
{
const
{
uid
}
=
itemData
;
await
patchProfile
(
uid
,
{
uid
,
name
,
desc
,
url
});
mutate
(
"
getProfiles
"
);
onClose
();
}
catch
(
err
:
any
)
{
Notice
.
error
(
err
?.
message
||
err
?.
toString
());
}
});
return
(
<
Dialog
open
=
{
open
}
onClose
=
{
onClose
}
>
<
DialogTitle
>
Edit Profile
</
DialogTitle
>
<
DialogContent
sx
=
{
{
width
:
360
,
pb
:
0.5
}
}
>
<
TextField
autoFocus
fullWidth
label
=
"Name"
margin
=
"dense"
variant
=
"outlined"
value
=
{
name
}
onChange
=
{
(
e
)
=>
setName
(
e
.
target
.
value
)
}
/>
<
TextField
fullWidth
label
=
"Descriptions"
margin
=
"normal"
variant
=
"outlined"
value
=
{
desc
}
onChange
=
{
(
e
)
=>
setDesc
(
e
.
target
.
value
)
}
/>
<
TextField
fullWidth
label
=
"Remote URL"
margin
=
"normal"
variant
=
"outlined"
value
=
{
url
}
onChange
=
{
(
e
)
=>
setUrl
(
e
.
target
.
value
)
}
/>
</
DialogContent
>
<
DialogActions
sx
=
{
{
px
:
2
,
pb
:
2
}
}
>
<
Button
onClick
=
{
onClose
}
>
Cancel
</
Button
>
<
Button
onClick
=
{
onUpdate
}
variant
=
"contained"
>
Update
</
Button
>
</
DialogActions
>
</
Dialog
>
);
};
export
default
ProfileEdit
;
This diff is collapsed.
Click to expand it.
src/components/profile/profile-item.tsx
+
30
−
9
View file @
17f1c487
import
React
,
{
useState
}
from
"
react
"
;
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
dayjs
from
"
dayjs
"
;
import
{
alpha
,
...
...
@@ -16,9 +16,10 @@ import { useSWRConfig } from "swr";
import
{
RefreshRounded
}
from
"
@mui/icons-material
"
;
import
{
CmdType
}
from
"
../../services/types
"
;
import
{
updateProfile
,
deleteProfile
,
viewProfile
}
from
"
../../services/cmds
"
;
import
Notice
from
"
../base/base-notice
"
;
import
parseTraffic
from
"
../../utils/parse-traffic
"
;
import
relativeTime
from
"
dayjs/plugin/relativeTime
"
;
import
parseTraffic
from
"
../../utils/parse-traffic
"
;
import
ProfileEdit
from
"
./profile-edit
"
;
import
Notice
from
"
../base/base-notice
"
;
dayjs
.
extend
(
relativeTime
);
...
...
@@ -38,8 +39,10 @@ const round = keyframes`
to { transform: rotate(360deg); }
`
;
// save the state of each item loading
const
loadingCache
:
Record
<
string
,
boolean
>
=
{};
interface
Props
{
// index: number;
selected
:
boolean
;
itemData
:
CmdType
.
ProfileItem
;
onSelect
:
(
force
:
boolean
)
=>
void
;
...
...
@@ -49,7 +52,7 @@ const ProfileItem: React.FC<Props> = (props) => {
const
{
selected
,
itemData
,
onSelect
}
=
props
;
const
{
mutate
}
=
useSWRConfig
();
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
loading
,
setLoading
]
=
useState
(
loadingCache
[
itemData
.
uid
]
??
false
);
const
[
anchorEl
,
setAnchorEl
]
=
useState
<
any
>
(
null
);
const
[
position
,
setPosition
]
=
useState
({
left
:
0
,
top
:
0
});
...
...
@@ -66,6 +69,16 @@ const ProfileItem: React.FC<Props> = (props) => {
const
hasUrl
=
!!
itemData
.
url
;
const
hasExtra
=
!!
extra
;
// only subscription url has extra info
useEffect
(()
=>
{
loadingCache
[
itemData
.
uid
]
=
loading
;
},
[
itemData
,
loading
]);
const
[
editOpen
,
setEditOpen
]
=
useState
(
false
);
const
onEdit
=
()
=>
{
setAnchorEl
(
null
);
setEditOpen
(
true
);
};
const
onView
=
async
()
=>
{
setAnchorEl
(
null
);
try
{
...
...
@@ -86,11 +99,11 @@ const ProfileItem: React.FC<Props> = (props) => {
setLoading
(
true
);
try
{
await
updateProfile
(
itemData
.
uid
,
withProxy
);
setLoading
(
false
);
mutate
(
"
getProfiles
"
);
}
catch
(
err
:
any
)
{
Notice
.
error
(
err
.
toString
());
}
finally
{
setLoading
(
false
);
Notice
.
error
(
err
?.
message
||
err
.
toString
());
}
};
...
...
@@ -101,7 +114,7 @@ const ProfileItem: React.FC<Props> = (props) => {
await
deleteProfile
(
itemData
.
uid
);
mutate
(
"
getProfiles
"
);
}
catch
(
err
:
any
)
{
Notice
.
error
(
err
.
toString
());
Notice
.
error
(
err
?.
message
||
err
.
toString
());
}
});
...
...
@@ -123,6 +136,7 @@ const ProfileItem: React.FC<Props> = (props) => {
const
urlModeMenu
=
[
{
label
:
"
Select
"
,
handler
:
onForceSelect
},
{
label
:
"
Edit
"
,
handler
:
onEdit
},
{
label
:
"
View
"
,
handler
:
onView
},
{
label
:
"
Update
"
,
handler
:
onUpdateWrapper
(
false
)
},
{
label
:
"
Update(Proxy)
"
,
handler
:
onUpdateWrapper
(
true
)
},
...
...
@@ -130,7 +144,8 @@ const ProfileItem: React.FC<Props> = (props) => {
];
const
fileModeMenu
=
[
{
label
:
"
Select
"
,
handler
:
onForceSelect
},
{
label
:
"
Edit
"
,
handler
:
onView
},
{
label
:
"
Edit
"
,
handler
:
onEdit
},
{
label
:
"
View
"
,
handler
:
onView
},
{
label
:
"
Delete
"
,
handler
:
onDelete
},
];
...
...
@@ -261,6 +276,12 @@ const ProfileItem: React.FC<Props> = (props) => {
</
MenuItem
>
))
}
</
Menu
>
<
ProfileEdit
open
=
{
editOpen
}
itemData
=
{
itemData
}
onClose
=
{
()
=>
setEditOpen
(
false
)
}
/>
</>
);
};
...
...
This diff is collapsed.
Click to expand it.
src/services/types.ts
+
0
−
1
View file @
17f1c487
...
...
@@ -91,7 +91,6 @@ export namespace CmdType {
name
?:
string
;
desc
?:
string
;
file
?:
string
;
mode
?:
string
;
url
?:
string
;
updated
?:
number
;
selected
?:
{
...
...
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