mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 18:56:32 -05:00
fix(editor): catch error when refreshing note metadata
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
0dcfb0524c
commit
29afcce555
1 changed files with 13 additions and 4 deletions
|
@ -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(
|
||||||
objectify: true
|
MessageType.METADATA_UPDATED,
|
||||||
}) as Listener
|
() => {
|
||||||
|
updateMetadata().catch(showErrorNotification('common.errorWhileLoading', { name: 'note metadata refresh' }))
|
||||||
|
},
|
||||||
|
{
|
||||||
|
objectify: true
|
||||||
|
}
|
||||||
|
) as Listener
|
||||||
return () => {
|
return () => {
|
||||||
listener.off()
|
listener.off()
|
||||||
}
|
}
|
||||||
}, [websocketConnection])
|
}, [showErrorNotification, websocketConnection])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue