mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 11:37:02 -04:00
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:
parent
808601eaba
commit
553e9f8ead
13 changed files with 154 additions and 105 deletions
|
@ -6,8 +6,7 @@
|
|||
|
||||
import { Editor, Hint, Hints, Pos } from 'codemirror'
|
||||
import { findWordAtCursor, generateHintListByPrefix, Hinter } from './index'
|
||||
import { DEFAULT_DURATION_IN_SECONDS, dispatchUiNotification } from '../../../../redux/ui-notifications/methods'
|
||||
import i18n from 'i18next'
|
||||
import { showErrorNotification } from '../../../../redux/ui-notifications/methods'
|
||||
|
||||
type highlightJsImport = typeof import('../../../common/hljs/hljs')
|
||||
|
||||
|
@ -22,12 +21,7 @@ const loadHighlightJs = async (): Promise<highlightJsImport | null> => {
|
|||
try {
|
||||
return await import('../../../common/hljs/hljs')
|
||||
} catch (error) {
|
||||
dispatchUiNotification(
|
||||
i18n.t('common.errorOccurred'),
|
||||
i18n.t('common.errorWhileLoadingLibrary', { name: 'highlight.js' }),
|
||||
DEFAULT_DURATION_IN_SECONDS,
|
||||
'exclamation-circle'
|
||||
)
|
||||
showErrorNotification('common.errorWhileLoadingLibrary', { name: 'highlight.js' })(error as Error)
|
||||
console.error("can't load highlight js", error)
|
||||
return null
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import { showErrorNotification } from '../../../redux/ui-notifications/methods'
|
|||
import { useApplicationState } from '../../../hooks/common/use-application-state'
|
||||
|
||||
export const PinNoteSidebarEntry: React.FC<SpecificSidebarEntryProps> = ({ className, hide }) => {
|
||||
const { t } = useTranslation()
|
||||
useTranslation()
|
||||
const { id } = useParams<EditorPagePathParams>()
|
||||
const history = useApplicationState((state) => state.history)
|
||||
|
||||
|
@ -28,8 +28,8 @@ export const PinNoteSidebarEntry: React.FC<SpecificSidebarEntryProps> = ({ class
|
|||
}, [id, history])
|
||||
|
||||
const onPinClicked = useCallback(() => {
|
||||
toggleHistoryEntryPinning(id).catch(showErrorNotification(t('landing.history.error.updateEntry.text')))
|
||||
}, [id, t])
|
||||
toggleHistoryEntryPinning(id).catch(showErrorNotification('landing.history.error.updateEntry.text'))
|
||||
}, [id])
|
||||
|
||||
return (
|
||||
<SidebarButton
|
||||
|
|
|
@ -5,23 +5,29 @@
|
|||
*/
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import { DEFAULT_DURATION_IN_SECONDS, dispatchUiNotification } from '../../redux/ui-notifications/methods'
|
||||
import { dispatchUiNotification } from '../../redux/ui-notifications/methods'
|
||||
|
||||
const localStorageKey = 'dontshowtestnotification'
|
||||
|
||||
/**
|
||||
* Spawns a notification to test the system. Only for tech demo show case.
|
||||
*/
|
||||
export const useNotificationTest = (): void => {
|
||||
useEffect(() => {
|
||||
if (window.localStorage.getItem(localStorageKey)) {
|
||||
return
|
||||
}
|
||||
console.debug('[Notifications] Dispatched test notification')
|
||||
dispatchUiNotification('Notification-Test!', 'It Works!', DEFAULT_DURATION_IN_SECONDS, 'info-circle', [
|
||||
{
|
||||
label: "Don't show again",
|
||||
onClick: () => {
|
||||
window.localStorage.setItem(localStorageKey, '1')
|
||||
void dispatchUiNotification('notificationTest.title', 'notificationTest.content', {
|
||||
icon: 'info-circle',
|
||||
buttons: [
|
||||
{
|
||||
label: "Don't show again",
|
||||
onClick: () => {
|
||||
window.localStorage.setItem(localStorageKey, '1')
|
||||
}
|
||||
}
|
||||
}
|
||||
])
|
||||
]
|
||||
})
|
||||
}, [])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue