Rework notifications (#1465)

* Rework notifications

- dispatchUINotification returns a promise that contains the notification id
- notifications use i18n instead of plain text

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>

* Reformat code

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2021-08-31 22:21:29 +02:00 committed by GitHub
parent 808601eaba
commit 553e9f8ead
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 154 additions and 105 deletions

View file

@ -11,6 +11,7 @@ import { ForkAwesomeIcon } from '../common/fork-awesome/fork-awesome-icon'
import { ShowIf } from '../common/show-if/show-if'
import { IconName } from '../common/fork-awesome/types'
import { dismissUiNotification } from '../../redux/ui-notifications/methods'
import { Trans, useTranslation } from 'react-i18next'
const STEPS_PER_SECOND = 10
@ -19,8 +20,10 @@ export interface UiNotificationProps extends UiNotification {
}
export const UiNotificationToast: React.FC<UiNotificationProps> = ({
title,
content,
titleI18nKey,
contentI18nKey,
titleI18nOptions,
contentI18nOptions,
date,
icon,
dismissed,
@ -28,6 +31,7 @@ export const UiNotificationToast: React.FC<UiNotificationProps> = ({
durationInSecond,
buttons
}) => {
const { t } = useTranslation()
const [eta, setEta] = useState<number>()
const interval = useRef<NodeJS.Timeout | undefined>(undefined)
@ -89,15 +93,17 @@ export const UiNotificationToast: React.FC<UiNotificationProps> = ({
)
const contentDom = useMemo(() => {
return content.split('\n').map((value, lineNumber) => {
return (
<Fragment key={lineNumber}>
{value}
<br />
</Fragment>
)
})
}, [content])
return t(contentI18nKey, contentI18nOptions)
.split('\n')
.map((value, lineNumber) => {
return (
<Fragment key={lineNumber}>
{value}
<br />
</Fragment>
)
})
}, [contentI18nKey, contentI18nOptions, t])
return (
<Toast show={!dismissed && eta !== undefined} onClose={dismissThisNotification}>
@ -106,7 +112,7 @@ export const UiNotificationToast: React.FC<UiNotificationProps> = ({
<ShowIf condition={!!icon}>
<ForkAwesomeIcon icon={icon as IconName} fixedWidth={true} className={'mr-1'} />
</ShowIf>
{title}
<Trans i18nKey={titleI18nKey} tOptions={titleI18nOptions} />
</strong>
<small>{date.toRelative({ style: 'short' })}</small>
</Toast.Header>