diff options
author | crupest <crupest@outlook.com> | 2020-06-11 23:15:10 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-06-11 23:15:10 +0800 |
commit | 64c4376ed388af106c1de5ec8bd1d1743950a27e (patch) | |
tree | c1b4d3f4b83f5114febecb6f2e2cc6e982ec97f2 /Timeline/ClientApp/src/app/common/AlertHost.tsx | |
parent | 93ce8560fa19c3a91de99643fdbbe4f895a47b84 (diff) | |
download | timeline-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.tsx | 29 |
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> ); }; |