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
3cde0192
There was an error fetching the commit references. Please try again later.
Unverified
Commit
3cde0192
authored
3 years ago
by
GyDi
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: profile item loading state
parent
2f6efbed
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/profile-item.tsx
+14
-17
14 additions, 17 deletions
src/components/profile/profile-item.tsx
src/services/states.ts
+6
-0
6 additions, 0 deletions
src/services/states.ts
with
20 additions
and
17 deletions
src/components/profile/profile-item.tsx
+
14
−
17
View file @
3cde0192
import
dayjs
from
"
dayjs
"
;
import
dayjs
from
"
dayjs
"
;
import
{
useState
}
from
"
react
"
;
import
{
useLockFn
}
from
"
ahooks
"
;
import
{
useLockFn
}
from
"
ahooks
"
;
import
{
useSWRConfig
}
from
"
swr
"
;
import
{
useSWRConfig
}
from
"
swr
"
;
import
{
use
Effect
,
use
State
}
from
"
re
act
"
;
import
{
use
Recoil
State
}
from
"
re
coil
"
;
import
{
useTranslation
}
from
"
react-i18next
"
;
import
{
useTranslation
}
from
"
react-i18next
"
;
import
{
import
{
alpha
,
alpha
,
...
@@ -16,6 +17,7 @@ import {
...
@@ -16,6 +17,7 @@ import {
}
from
"
@mui/material
"
;
}
from
"
@mui/material
"
;
import
{
RefreshRounded
}
from
"
@mui/icons-material
"
;
import
{
RefreshRounded
}
from
"
@mui/icons-material
"
;
import
{
CmdType
}
from
"
../../services/types
"
;
import
{
CmdType
}
from
"
../../services/types
"
;
import
{
atomLoadingCache
}
from
"
../../services/states
"
;
import
{
updateProfile
,
deleteProfile
,
viewProfile
}
from
"
../../services/cmds
"
;
import
{
updateProfile
,
deleteProfile
,
viewProfile
}
from
"
../../services/cmds
"
;
import
parseTraffic
from
"
../../utils/parse-traffic
"
;
import
parseTraffic
from
"
../../utils/parse-traffic
"
;
import
ProfileEdit
from
"
./profile-edit
"
;
import
ProfileEdit
from
"
./profile-edit
"
;
...
@@ -37,9 +39,6 @@ const round = keyframes`
...
@@ -37,9 +39,6 @@ const round = keyframes`
to { transform: rotate(360deg); }
to { transform: rotate(360deg); }
`
;
`
;
// save the state of each item loading
const
loadingCache
:
Record
<
string
,
boolean
>
=
{};
interface
Props
{
interface
Props
{
selected
:
boolean
;
selected
:
boolean
;
itemData
:
CmdType
.
ProfileItem
;
itemData
:
CmdType
.
ProfileItem
;
...
@@ -51,9 +50,9 @@ const ProfileItem = (props: Props) => {
...
@@ -51,9 +50,9 @@ const ProfileItem = (props: Props) => {
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
{
mutate
}
=
useSWRConfig
();
const
{
mutate
}
=
useSWRConfig
();
const
[
loading
,
setLoading
]
=
useState
(
loadingCache
[
itemData
.
uid
]
??
false
);
const
[
anchorEl
,
setAnchorEl
]
=
useState
<
any
>
(
null
);
const
[
anchorEl
,
setAnchorEl
]
=
useState
<
any
>
(
null
);
const
[
position
,
setPosition
]
=
useState
({
left
:
0
,
top
:
0
});
const
[
position
,
setPosition
]
=
useState
({
left
:
0
,
top
:
0
});
const
[
loadingCache
,
setLoadingCache
]
=
useRecoilState
(
atomLoadingCache
);
const
{
name
=
"
Profile
"
,
extra
,
updated
=
0
}
=
itemData
;
const
{
name
=
"
Profile
"
,
extra
,
updated
=
0
}
=
itemData
;
const
{
upload
=
0
,
download
=
0
,
total
=
0
}
=
extra
??
{};
const
{
upload
=
0
,
download
=
0
,
total
=
0
}
=
extra
??
{};
...
@@ -68,9 +67,7 @@ const ProfileItem = (props: Props) => {
...
@@ -68,9 +67,7 @@ const ProfileItem = (props: Props) => {
const
hasUrl
=
!!
itemData
.
url
;
const
hasUrl
=
!!
itemData
.
url
;
const
hasExtra
=
!!
extra
;
// only subscription url has extra info
const
hasExtra
=
!!
extra
;
// only subscription url has extra info
useEffect
(()
=>
{
const
loading
=
loadingCache
[
itemData
.
uid
]
??
false
;
loadingCache
[
itemData
.
uid
]
=
loading
;
},
[
itemData
,
loading
]);
const
[
editOpen
,
setEditOpen
]
=
useState
(
false
);
const
[
editOpen
,
setEditOpen
]
=
useState
(
false
);
const
onEdit
=
()
=>
{
const
onEdit
=
()
=>
{
...
@@ -92,19 +89,19 @@ const ProfileItem = (props: Props) => {
...
@@ -92,19 +89,19 @@ const ProfileItem = (props: Props) => {
onSelect
(
true
);
onSelect
(
true
);
};
};
const
onUpdate
Wrapper
=
(
withProxy
:
boolean
)
=>
async
()
=>
{
const
onUpdate
=
useLockFn
(
async
(
withProxy
:
boolean
)
=>
{
setAnchorEl
(
null
);
setAnchorEl
(
null
);
if
(
l
oading
)
return
;
setL
oading
Cache
((
cache
)
=>
({
...
cache
,
[
itemData
.
uid
]:
true
}))
;
setLoading
(
true
);
try
{
try
{
await
updateProfile
(
itemData
.
uid
,
{
with_proxy
:
withProxy
});
await
updateProfile
(
itemData
.
uid
,
{
with_proxy
:
withProxy
});
setLoading
(
false
);
mutate
(
"
getProfiles
"
);
mutate
(
"
getProfiles
"
);
}
catch
(
err
:
any
)
{
}
catch
(
err
:
any
)
{
setLoading
(
false
);
Notice
.
error
(
err
?.
message
||
err
.
toString
());
Notice
.
error
(
err
?.
message
||
err
.
toString
());
}
finally
{
setLoadingCache
((
cache
)
=>
({
...
cache
,
[
itemData
.
uid
]:
false
}));
}
}
};
}
)
;
const
onDelete
=
useLockFn
(
async
()
=>
{
const
onDelete
=
useLockFn
(
async
()
=>
{
setAnchorEl
(
null
);
setAnchorEl
(
null
);
...
@@ -127,8 +124,8 @@ const ProfileItem = (props: Props) => {
...
@@ -127,8 +124,8 @@ const ProfileItem = (props: Props) => {
{
label
:
"
Select
"
,
handler
:
onForceSelect
},
{
label
:
"
Select
"
,
handler
:
onForceSelect
},
{
label
:
"
Edit
"
,
handler
:
onEdit
},
{
label
:
"
Edit
"
,
handler
:
onEdit
},
{
label
:
"
File
"
,
handler
:
onView
},
{
label
:
"
File
"
,
handler
:
onView
},
{
label
:
"
Update
"
,
handler
:
onUpdate
Wrapper
(
false
)
},
{
label
:
"
Update
"
,
handler
:
()
=>
onUpdate
(
false
)
},
{
label
:
"
Update(Proxy)
"
,
handler
:
onUpdate
Wrapper
(
true
)
},
{
label
:
"
Update(Proxy)
"
,
handler
:
()
=>
onUpdate
(
true
)
},
{
label
:
"
Delete
"
,
handler
:
onDelete
},
{
label
:
"
Delete
"
,
handler
:
onDelete
},
];
];
const
fileModeMenu
=
[
const
fileModeMenu
=
[
...
@@ -199,7 +196,7 @@ const ProfileItem = (props: Props) => {
...
@@ -199,7 +196,7 @@ const ProfileItem = (props: Props) => {
disabled
=
{
loading
}
disabled
=
{
loading
}
onClick
=
{
(
e
)
=>
{
onClick
=
{
(
e
)
=>
{
e
.
stopPropagation
();
e
.
stopPropagation
();
onUpdate
Wrapper
(
false
)
()
;
onUpdate
(
false
);
}
}
}
}
>
>
<
RefreshRounded
/>
<
RefreshRounded
/>
...
...
This diff is collapsed.
Click to expand it.
src/services/states.ts
+
6
−
0
View file @
3cde0192
...
@@ -10,3 +10,9 @@ export const atomLogData = atom<ApiType.LogItem[]>({
...
@@ -10,3 +10,9 @@ export const atomLogData = atom<ApiType.LogItem[]>({
key
:
"
atomLogData
"
,
key
:
"
atomLogData
"
,
default
:
[],
default
:
[],
});
});
// save the state of each profile item loading
export
const
atomLoadingCache
=
atom
<
Record
<
string
,
boolean
>>
({
key
:
"
atomLoadingCache
"
,
default
:
{},
});
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