aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/common/AlertHost.tsx
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-06-11 23:15:10 +0800
committercrupest <crupest@outlook.com>2020-06-11 23:15:10 +0800
commit64c4376ed388af106c1de5ec8bd1d1743950a27e (patch)
treec1b4d3f4b83f5114febecb6f2e2cc6e982ec97f2 /Timeline/ClientApp/src/app/common/AlertHost.tsx
parent93ce8560fa19c3a91de99643fdbbe4f895a47b84 (diff)
downloadtimeline-64c4376ed388af106c1de5ec8bd1d1743950a27e.tar.gz
timeline-64c4376ed388af106c1de5ec8bd1d1743950a27e.tar.bz2
timeline-64c4376ed388af106c1de5ec8bd1d1743950a27e.zip
feat(front): Application upgrade ui.
Diffstat (limited to 'Timeline/ClientApp/src/app/common/AlertHost.tsx')
-rw-r--r--Timeline/ClientApp/src/app/common/AlertHost.tsx29
1 files changed, 25 insertions, 4 deletions
diff --git a/Timeline/ClientApp/src/app/common/AlertHost.tsx b/Timeline/ClientApp/src/app/common/AlertHost.tsx
index c815db2b..23b6c5f4 100644
--- a/Timeline/ClientApp/src/app/common/AlertHost.tsx
+++ b/Timeline/ClientApp/src/app/common/AlertHost.tsx
@@ -9,6 +9,7 @@ import {
kAlertHostId,
AlertInfo,
} from './alert-service';
+import { useTranslation } from 'react-i18next';
interface AutoCloseAlertProps {
alert: AlertInfo;
@@ -17,15 +18,35 @@ interface AutoCloseAlertProps {
export const AutoCloseAlert: React.FC<AutoCloseAlertProps> = (props) => {
const { alert } = props;
+ const { dismissTime } = alert;
+
+ const { t } = useTranslation();
React.useEffect(() => {
- const tag = window.setTimeout(props.close, 5000);
- return () => window.clearTimeout(tag);
- }, [props.close]);
+ const tag =
+ dismissTime === 'never'
+ ? null
+ : typeof dismissTime === 'number'
+ ? window.setTimeout(props.close, dismissTime)
+ : window.setTimeout(props.close, 5000);
+ return () => {
+ if (tag != null) {
+ window.clearTimeout(tag);
+ }
+ };
+ }, [dismissTime, props.close]);
return (
<Alert className="m-3" color={alert.type ?? 'primary'} toggle={props.close}>
- {alert.message}
+ {(() => {
+ const { message } = alert;
+ if (typeof message === 'function') {
+ const Message = message;
+ return <Message />;
+ } else if (typeof message === 'object' && message.type === 'i18n') {
+ return t(message.key);
+ } else return alert.message;
+ })()}
</Alert>
);
};