From 97389fe0c4088ba1b1fdcf2382dcdc48c02c4297 Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Sat, 25 Mar 2023 14:46:22 +0100 Subject: [PATCH] fix: useTranslation hook in react components Signed-off-by: Erik Michelson --- .../editor-page/editor-pane/hooks/use-handle-upload.tsx | 5 +++-- .../src/components/layout/settings-dialog/settings-modal.tsx | 4 +++- .../components/notifications/ui-notification-boundary.tsx | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/editor-page/editor-pane/hooks/use-handle-upload.tsx b/frontend/src/components/editor-page/editor-pane/hooks/use-handle-upload.tsx index bdef03219..8e2839938 100644 --- a/frontend/src/components/editor-page/editor-pane/hooks/use-handle-upload.tsx +++ b/frontend/src/components/editor-page/editor-pane/hooks/use-handle-upload.tsx @@ -13,8 +13,8 @@ import { replaceInContent } from '../tool-bar/formatters/replace-in-content' import { replaceSelection } from '../tool-bar/formatters/replace-selection' import type { CursorSelection } from '../tool-bar/formatters/types/cursor-selection' import type { EditorView } from '@codemirror/view' -import { t } from 'i18next' import { useCallback } from 'react' +import { useTranslation } from 'react-i18next' /** * @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. */ export const useHandleUpload = (): handleUploadSignature => { + const { t } = useTranslation() const { showErrorNotification } = useUiNotifications() return useCallback( @@ -70,6 +71,6 @@ export const useHandleUpload = (): handleUploadSignature => { ]) }) }, - [showErrorNotification] + [showErrorNotification, t] ) } diff --git a/frontend/src/components/layout/settings-dialog/settings-modal.tsx b/frontend/src/components/layout/settings-dialog/settings-modal.tsx index c08f5f561..36181a311 100644 --- a/frontend/src/components/layout/settings-dialog/settings-modal.tsx +++ b/frontend/src/components/layout/settings-dialog/settings-modal.tsx @@ -7,10 +7,10 @@ import type { CommonModalProps } from '../../common/modals/common-modal' import { CommonModal } from '../../common/modals/common-modal' import { EditorSettingsTabContent } from './editor/editor-settings-tab-content' import { GlobalSettingsTabContent } from './global/global-settings-tab-content' -import { t } from 'i18next' import React from 'react' import { Modal, Tab, Tabs } from 'react-bootstrap' import { Gear as IconGear } from 'react-bootstrap-icons' +import { useTranslation } from 'react-i18next' /** * 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 */ export const SettingsModal: React.FC = ({ show, onHide }) => { + const { t } = useTranslation() + return ( (u * @param children The children that receive the context */ export const UiNotificationBoundary: React.FC = ({ children }) => { + const { t } = useTranslation() const [uiNotifications, setUiNotifications] = useState([]) const dispatchUiNotification = useCallback( @@ -84,7 +85,7 @@ export const UiNotificationBoundary: React.FC = ({ children } icon: IconExclamationTriangle }) }, - [dispatchUiNotification] + [dispatchUiNotification, t] ) const dismissNotification = useCallback((notificationUuid: string): void => {