fix: useTranslation hook in react components

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2023-03-25 14:46:22 +01:00 committed by Philip Molares
parent 8d497bcfc5
commit 97389fe0c4
3 changed files with 9 additions and 5 deletions

View file

@ -13,8 +13,8 @@ import { replaceInContent } from '../tool-bar/formatters/replace-in-content'
import { replaceSelection } from '../tool-bar/formatters/replace-selection' import { replaceSelection } from '../tool-bar/formatters/replace-selection'
import type { CursorSelection } from '../tool-bar/formatters/types/cursor-selection' import type { CursorSelection } from '../tool-bar/formatters/types/cursor-selection'
import type { EditorView } from '@codemirror/view' import type { EditorView } from '@codemirror/view'
import { t } from 'i18next'
import { useCallback } from 'react' import { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
/** /**
* @param view the codemirror instance that is used to insert the Markdown code * @param view the codemirror instance that is used to insert the Markdown code
@ -35,6 +35,7 @@ type handleUploadSignature = (
* Provides a callback that uploads a given file and inserts the correct Markdown code into the current editor. * Provides a callback that uploads a given file and inserts the correct Markdown code into the current editor.
*/ */
export const useHandleUpload = (): handleUploadSignature => { export const useHandleUpload = (): handleUploadSignature => {
const { t } = useTranslation()
const { showErrorNotification } = useUiNotifications() const { showErrorNotification } = useUiNotifications()
return useCallback( return useCallback(
@ -70,6 +71,6 @@ export const useHandleUpload = (): handleUploadSignature => {
]) ])
}) })
}, },
[showErrorNotification] [showErrorNotification, t]
) )
} }

View file

@ -7,10 +7,10 @@ import type { CommonModalProps } from '../../common/modals/common-modal'
import { CommonModal } from '../../common/modals/common-modal' import { CommonModal } from '../../common/modals/common-modal'
import { EditorSettingsTabContent } from './editor/editor-settings-tab-content' import { EditorSettingsTabContent } from './editor/editor-settings-tab-content'
import { GlobalSettingsTabContent } from './global/global-settings-tab-content' import { GlobalSettingsTabContent } from './global/global-settings-tab-content'
import { t } from 'i18next'
import React from 'react' import React from 'react'
import { Modal, Tab, Tabs } from 'react-bootstrap' import { Modal, Tab, Tabs } from 'react-bootstrap'
import { Gear as IconGear } from 'react-bootstrap-icons' import { Gear as IconGear } from 'react-bootstrap-icons'
import { useTranslation } from 'react-i18next'
/** /**
* Shows global and scope specific settings * Shows global and scope specific settings
@ -19,6 +19,8 @@ import { Gear as IconGear } from 'react-bootstrap-icons'
* @param onHide callback that is executed if the modal should be closed * @param onHide callback that is executed if the modal should be closed
*/ */
export const SettingsModal: React.FC<CommonModalProps> = ({ show, onHide }) => { export const SettingsModal: React.FC<CommonModalProps> = ({ show, onHide }) => {
const { t } = useTranslation()
return ( return (
<CommonModal <CommonModal
show={show} show={show}

View file

@ -7,11 +7,11 @@ import { Logger } from '../../utils/logger'
import type { DispatchOptions, UiNotification } from './types' import type { DispatchOptions, UiNotification } from './types'
import { UiNotifications } from './ui-notifications' import { UiNotifications } from './ui-notifications'
import type { TOptions } from 'i18next' import type { TOptions } from 'i18next'
import { t } from 'i18next'
import { DateTime } from 'luxon' import { DateTime } from 'luxon'
import type { PropsWithChildren } from 'react' import type { PropsWithChildren } from 'react'
import React, { createContext, useCallback, useContext, useMemo, useState } from 'react' import React, { createContext, useCallback, useContext, useMemo, useState } from 'react'
import { ExclamationTriangle as IconExclamationTriangle } from 'react-bootstrap-icons' import { ExclamationTriangle as IconExclamationTriangle } from 'react-bootstrap-icons'
import { useTranslation } from 'react-i18next'
import { v4 as uuid } from 'uuid' import { v4 as uuid } from 'uuid'
const log = new Logger('Notifications') const log = new Logger('Notifications')
@ -48,6 +48,7 @@ const uiNotificationContext = createContext<UiNotificationContext | undefined>(u
* @param children The children that receive the context * @param children The children that receive the context
*/ */
export const UiNotificationBoundary: React.FC<PropsWithChildren> = ({ children }) => { export const UiNotificationBoundary: React.FC<PropsWithChildren> = ({ children }) => {
const { t } = useTranslation()
const [uiNotifications, setUiNotifications] = useState<UiNotification[]>([]) const [uiNotifications, setUiNotifications] = useState<UiNotification[]>([])
const dispatchUiNotification = useCallback( const dispatchUiNotification = useCallback(
@ -84,7 +85,7 @@ export const UiNotificationBoundary: React.FC<PropsWithChildren> = ({ children }
icon: IconExclamationTriangle icon: IconExclamationTriangle
}) })
}, },
[dispatchUiNotification] [dispatchUiNotification, t]
) )
const dismissNotification = useCallback((notificationUuid: string): void => { const dismissNotification = useCallback((notificationUuid: string): void => {