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
97f2bc87
There was an error fetching the commit references. Please try again later.
Commit
97f2bc87
authored
3 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
feat: add use-notice hook
parent
48f1b27d
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/pages/rules.tsx
+21
-47
21 additions, 47 deletions
src/pages/rules.tsx
src/utils/use-notice.tsx
+55
-0
55 additions, 0 deletions
src/utils/use-notice.tsx
with
76 additions
and
47 deletions
src/pages/rules.tsx
+
21
−
47
View file @
97f2bc87
import
{
useState
}
from
"
react
"
;
import
{
Box
,
Button
,
Grid
,
Slide
,
Snackbar
,
TextField
,
Typography
,
}
from
"
@mui/material
"
;
import
{
Box
,
Button
,
TextField
,
Typography
}
from
"
@mui/material
"
;
import
{
importProfile
}
from
"
../services/command
"
;
import
useNotice
from
"
../utils/use-notice
"
;
const
RulesPage
=
()
=>
{
const
[
url
,
setUrl
]
=
useState
(
""
);
const
[
message
,
setMessage
]
=
useState
(
""
);
const
[
disabled
,
setDisabled
]
=
useState
(
false
);
const
[
notice
,
noticeElement
]
=
useNotice
();
const
onClick
=
()
=>
{
if
(
!
url
)
return
;
setUrl
(
""
);
setDisabled
(
true
);
importProfile
(
url
)
.
then
(()
=>
setMessage
(
"
Successfully import profile.
"
))
.
catch
(()
=>
setMessage
(
"
Failed to import profile.
"
))
.
then
(()
=>
notice
.
success
(
"
Successfully import profile.
"
))
.
catch
(()
=>
notice
.
error
(
"
Failed to import profile.
"
))
.
finally
(()
=>
setDisabled
(
false
));
};
return
(
<
Box
sx
=
{
{
width
:
0.9
,
maxWidth
:
"
850px
"
,
mx
:
"
auto
"
,
mb
:
2
}
}
>
<
Typography
variant
=
"h4"
component
=
"h1"
sx
=
{
{
py
:
2
}
}
>
<
Typography
variant
=
"h4"
component
=
"h1"
sx
=
{
{
py
:
2
,
mb
:
1
}
}
>
Rules
</
Typography
>
<
Grid
container
spacing
=
{
2
}
justifyContent
=
"space-between"
alignItems
=
"center"
>
<
Grid
item
xs
=
{
9
}
>
<
TextField
label
=
"Profile Url"
size
=
"medium"
fullWidth
value
=
{
url
}
onChange
=
{
(
e
)
=>
setUrl
(
e
.
target
.
value
)
}
/>
</
Grid
>
<
Grid
item
>
<
Button
disabled
=
{
disabled
}
size
=
"large"
variant
=
"contained"
onClick
=
{
onClick
}
>
Import
</
Button
>
</
Grid
>
</
Grid
>
<
Box
sx
=
{
{
display
:
"
flex
"
}
}
>
<
TextField
label
=
"Profile URL"
size
=
"small"
fullWidth
value
=
{
url
}
onChange
=
{
(
e
)
=>
setUrl
(
e
.
target
.
value
)
}
sx
=
{
{
mr
:
4
}
}
/>
<
Button
disabled
=
{
disabled
}
variant
=
"contained"
onClick
=
{
onClick
}
>
Import
</
Button
>
</
Box
>
<
Snackbar
open
=
{
!!
message
}
anchorOrigin
=
{
{
vertical
:
"
top
"
,
horizontal
:
"
right
"
}
}
autoHideDuration
=
{
3000
}
onClose
=
{
()
=>
setMessage
(
""
)
}
message
=
{
message
}
TransitionComponent
=
{
(
p
)
=>
<
Slide
{
...
p
}
direction
=
"left"
/>
}
/>
{
noticeElement
}
</
Box
>
);
};
...
...
This diff is collapsed.
Click to expand it.
src/utils/use-notice.tsx
0 → 100644
+
55
−
0
View file @
97f2bc87
import
{
useMemo
,
useState
}
from
"
react
"
;
import
{
IconButton
,
Slide
,
Snackbar
}
from
"
@mui/material
"
;
import
{
Close
}
from
"
@mui/icons-material
"
;
interface
NoticeInstance
{
info
:
(
msg
:
string
)
=>
void
;
error
:
(
msg
:
string
)
=>
void
;
success
:
(
msg
:
string
)
=>
void
;
}
const
useNotice
=
()
=>
{
const
[
message
,
setMessage
]
=
useState
(
""
);
const
[
level
,
setLevel
]
=
useState
<
"
info
"
|
"
error
"
|
"
success
"
>
(
"
info
"
);
const
handleClose
=
(
_e
:
any
,
reason
:
string
)
=>
{
if
(
reason
!==
"
clickaway
"
)
setMessage
(
""
);
};
const
element
=
useMemo
(
()
=>
(
<
Snackbar
open
=
{
!!
message
}
anchorOrigin
=
{
{
vertical
:
"
top
"
,
horizontal
:
"
right
"
}
}
autoHideDuration
=
{
3000
}
onClose
=
{
handleClose
}
message
=
{
message
}
TransitionComponent
=
{
(
p
)
=>
<
Slide
{
...
p
}
direction
=
"left"
/>
}
action
=
{
<
IconButton
size
=
"small"
color
=
"inherit"
onClick
=
{
()
=>
setMessage
(
""
)
}
>
<
Close
fontSize
=
"small"
/>
</
IconButton
>
}
/>
),
[
message
]
);
const
instance
=
(
Object
.
fromEntries
(
([
"
info
"
,
"
error
"
,
"
success
"
]
as const
).
map
((
item
)
=>
[
item
,
(
msg
:
string
)
=>
{
setLevel
(
item
);
setMessage
(
msg
);
},
])
)
as
unknown
)
as
NoticeInstance
;
return
[
instance
,
element
]
as const
;
};
export
default
useNotice
;
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