Skip to content

Commit e9e09c9

Browse files
Feat optimization (#16)
* feat: opt ui * feat: fix ui * feat: add toast * chore: update featureprobe js sdk * fix: proxy field
1 parent 1964c2d commit e9e09c9

File tree

22 files changed

+433
-342
lines changed

22 files changed

+433
-342
lines changed

package-lock.json

Lines changed: 28 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"dayjs": "^1.11.0",
2424
"diff": "^5.0.0",
2525
"diff2html": "^3.4.17",
26-
"featureprobe-client-sdk-js": "^1.0.3",
26+
"featureprobe-client-sdk-js": "^1.0.5",
2727
"json-bigint": "^1.0.0",
2828
"jsonlint-mod": "^1.7.6",
2929
"less-loader": "^7.3.0",
@@ -42,6 +42,7 @@
4242
"react-intl": "^5.25.1",
4343
"react-router-dom": "^5.3.0",
4444
"react-syntax-highlighter": "^15.5.0",
45+
"react-toastify": "^9.0.8",
4546
"sass-loader": "^13.0.0",
4647
"semantic-ui-less": "^2.4.1",
4748
"semantic-ui-react": "^2.1.2",
Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,29 @@
11
.message {
2-
position: fixed;
3-
top: 50px;
4-
left: 50%;
5-
transform: translate(-50%, 0);
6-
z-index: 1000;
7-
}
2+
padding: 0 12px 0 8px !important;
83

9-
.message-content {
10-
max-width: 800px;
11-
padding: 8px 16px;
12-
border-radius: 6px;
13-
font-size: 14px;
14-
margin-bottom: 10px;
4+
:global {
5+
.Toastify__toast-icon {
6+
margin-inline-end: 5px;
7+
}
8+
}
159
}
1610

1711
.icon-info-circle {
1812
color: #0A70F5;
1913
vertical-align: middle;
2014
}
2115

22-
.message-content-info {
23-
background: #EFF8FF;
24-
color: #005238;
25-
}
26-
2716
.icon-success-circle {
2817
color: #00B365;
2918
vertical-align: middle;
3019
}
3120

32-
.message-content-success {
33-
background: #EFFCF2;
34-
color: #005238;
35-
}
36-
3721
.icon-warning-circle {
3822
color: #FFC300;
3923
vertical-align: middle;
4024
}
4125

42-
.message-content-warn {
43-
background: #FFFAE0;
44-
color: #592D00;
45-
}
46-
4726
.icon-error-circle {
4827
color: #F5483B;
4928
vertical-align: middle;
5029
}
51-
52-
.message-content-error {
53-
background: #FFF5F4;
54-
color: #660E16;
55-
}
56-
57-
.message-icon {
58-
margin-right: 8px;
59-
font-size: 20px;
60-
margin-left: 8px;
61-
}
62-
63-
.message-content-text {
64-
font-size: 14px;
65-
margin-left: 8px;
66-
}
67-
Lines changed: 40 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
import { useEffect, useState } from 'react';
2-
import cloneDeep from 'lodash/cloneDeep';
3-
import ReactDOM from 'react-dom';
4-
1+
import { toast, ToastOptions, Slide } from 'react-toastify';
52
import styles from './index.module.scss';
63

7-
const RootDom = document.createElement('div');
8-
document.body.appendChild(RootDom);
9-
10-
interface IProps {
11-
type: string;
12-
content: string;
13-
duration: number;
14-
}
15-
164
interface IObject {
175
[key: string]: string;
186
}
@@ -24,88 +12,54 @@ interface IFunc {
2412
[key: string]: IFn;
2513
}
2614

27-
interface IMessageProps {
28-
item: IProps
29-
}
30-
3115
const iconObj: IObject = {
3216
info: 'icon-info-circle',
3317
success: 'icon-success-circle',
3418
warn: 'icon-warning-circle',
3519
error: 'icon-error-circle',
3620
};
3721

38-
const bgObj: IObject = {
39-
info: 'message-content-info',
40-
success: 'message-content-success',
41-
warn: 'message-content-warn',
42-
error: 'message-content-error',
43-
}
44-
45-
const MessageBox = (props: IProps) => {
46-
const [ msgs, setMsgs ] = useState<IProps[]>([]);
47-
48-
useEffect(() => {
49-
let msgscopy = cloneDeep(msgs);
50-
51-
setMsgs([...msgscopy, props]);
52-
// eslint-disable-next-line react-hooks/exhaustive-deps
53-
}, [props]);
54-
55-
return (
56-
<div className={styles.message}>
57-
{
58-
msgs.map((item: IProps, index: number) => {
59-
return (
60-
<Message
61-
key={index}
62-
item={{...props}}
63-
/>
64-
);
65-
})
66-
}
67-
</div>
68-
);
69-
}
70-
71-
const Message = (props: IMessageProps) => {
72-
const { item } = props;
73-
const { type, content, duration } = item;
74-
const [ visible, setVisible ] = useState<boolean>(false);
75-
76-
useEffect(() => {
77-
setVisible(true);
78-
const timer = setTimeout(() => {
79-
setVisible(false);
80-
}, duration * 1000);
81-
82-
return () => {
83-
clearTimeout(timer);
84-
}
85-
}, [duration]);
86-
87-
88-
if (!visible) return null;
8922

90-
return (
91-
<div className={`${styles[bgObj[type]]} ${styles['message-content']}`}>
92-
<i className={`${styles[iconObj[type]]} ${iconObj[type]} iconfont`}></i>
93-
<span className={styles['message-content-text']}>{ content }</span>
94-
</div>
95-
);
23+
const options: ToastOptions = {
24+
position: "top-center",
25+
hideProgressBar: true,
26+
closeOnClick: true,
27+
pauseOnHover: true,
28+
draggable: true,
29+
closeButton: false,
30+
transition: Slide,
31+
className: styles['message'],
9632
}
9733

98-
const message: IFunc = {};
99-
100-
const notice = (props: IProps) => {
101-
return ReactDOM.render(<MessageBox {...props} />, RootDom);
102-
}
103-
104-
['info', 'success', 'warn', 'error'].forEach((type: string) => {
105-
message[type] = (content: string, duration = 3) => {
106-
return notice({ content, duration, type });
107-
};
108-
});
34+
const message: IFunc = {
35+
info: (content: string, duration?: number) => {
36+
toast.info(content, {
37+
...options,
38+
icon: <i className={`${styles[iconObj['info']]} ${iconObj['info']} iconfont`}></i>,
39+
autoClose: duration || 3000,
40+
})
41+
},
42+
success: (content: string, duration?: number) => {
43+
toast.success(content, {
44+
...options,
45+
icon: <i className={`${styles[iconObj['success']]} ${iconObj['success']} iconfont`}></i>,
46+
autoClose: duration || 3000,
47+
})
48+
},
49+
warn: (content: string, duration?: number) => {
50+
toast.warning(content, {
51+
...options,
52+
icon: <i className={`${styles[iconObj['warn']]} ${iconObj['warn']} iconfont`}></i>,
53+
autoClose: duration || 3000,
54+
})
55+
},
56+
error: (content: string, duration?: number) => {
57+
toast.error(content, {
58+
...options,
59+
icon: <i className={`${styles[iconObj['error']]} ${iconObj['error']} iconfont`}></i>,
60+
autoClose: duration || 3000,
61+
})
62+
}
63+
};
10964

11065
export default message;
111-

src/index.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,24 @@ code {
99
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
1010
monospace;
1111
}
12+
13+
:root {
14+
--toastify-text-color-info: #0A70F5;
15+
--toastify-text-color-success: #00B365;
16+
--toastify-text-color-warning: #592D00;
17+
--toastify-text-color-error: #660E16;
18+
19+
--toastify-color-info: #EFF8FF;
20+
--toastify-color-success: #EFFCF2;
21+
--toastify-color-warning: #FFFAE0;
22+
--toastify-color-error: #FFF5F4;
23+
24+
--toastify-toast-min-height: 36px;
25+
--toastify-toast-max-height: 80px;
26+
27+
--toastify-toast-width: auto;
28+
}
29+
30+
.Toastify__toast-container--top-center {
31+
top: 48px !important;
32+
}

src/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import dayjs from 'dayjs';
4+
import { ToastContainer } from 'react-toastify';
45
import Router from './router';
56
import { I18NContainer } from './hooks';
67
import relativeTime from 'dayjs/plugin/relativeTime';
@@ -9,6 +10,7 @@ import Intl from './locales/intl';
910
import 'iconfont/iconfont.css';
1011
import 'semantic-ui-less/semantic.less';
1112
import "react-datetime/css/react-datetime.css";
13+
import 'react-toastify/dist/ReactToastify.css';
1214
import 'dayjs/locale/zh-cn';
1315

1416
import './index.scss';
@@ -22,6 +24,7 @@ ReactDOM.render(
2224
<Intl>
2325
<Router />
2426
</Intl>
27+
<ToastContainer theme='colored' />
2528
</I18NContainer.Provider>
2629
</React.StrictMode>,
2730
document.getElementById('root')

src/interfaces/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
declare interface Window {
33
jsonlint: any;
4-
fp: any;
4+
FP: any;
55
}
66

77
declare module 'jsonlint-mod';

0 commit comments

Comments
 (0)