fix(editor): catch error when refreshing note metadata

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-05-08 17:40:35 +02:00
parent 0dcfb0524c
commit 29afcce555

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { updateMetadata } from '../../../../../redux/note-details/methods' import { updateMetadata } from '../../../../../redux/note-details/methods'
import { useUiNotifications } from '../../../../notifications/ui-notification-boundary'
import type { MessageTransporter } from '@hedgedoc/commons' import type { MessageTransporter } from '@hedgedoc/commons'
import { MessageType } from '@hedgedoc/commons' import { MessageType } from '@hedgedoc/commons'
import type { Listener } from 'eventemitter2' import type { Listener } from 'eventemitter2'
@ -15,12 +16,20 @@ import { useEffect } from 'react'
* @param websocketConnection The websocket connection that emits the metadata changed event * @param websocketConnection The websocket connection that emits the metadata changed event
*/ */
export const useOnMetadataUpdated = (websocketConnection: MessageTransporter): void => { export const useOnMetadataUpdated = (websocketConnection: MessageTransporter): void => {
const { showErrorNotification } = useUiNotifications()
useEffect(() => { useEffect(() => {
const listener = websocketConnection.on(MessageType.METADATA_UPDATED, () => void updateMetadata(), { const listener = websocketConnection.on(
MessageType.METADATA_UPDATED,
() => {
updateMetadata().catch(showErrorNotification('common.errorWhileLoading', { name: 'note metadata refresh' }))
},
{
objectify: true objectify: true
}) as Listener }
) as Listener
return () => { return () => {
listener.off() listener.off()
} }
}, [websocketConnection]) }, [showErrorNotification, websocketConnection])
} }