move useI18n to i18n.ts

Since we are using the react-i18n babel loader plugin, useI18n can only
be used once per file. Also we have to remember to add the istanbul
ignore next comment each time we use it. By moving this to a common
file, it can be easily copied and pasted when a new submodule is
created and we don't have to remember the rules when calling it.
This commit is contained in:
David Lechner
2022-05-21 13:57:58 -05:00
parent e7366c8afd
commit a3e55c828a
46 changed files with 256 additions and 168 deletions
@@ -2,18 +2,16 @@
// Copyright (c) 2022 The Pybricks Authors
import { Alert, Classes, Intent } from '@blueprintjs/core';
import { useI18n } from '@shopify/react-i18n';
import React, { useCallback } from 'react';
import { useDispatch } from 'react-redux';
import { useSelector } from '../../reducers';
import { deleteFileAlertDidAccept, deleteFileAlertDidCancel } from './actions';
import { I18nId } from './i18n';
import { I18nId, useI18n } from './i18n';
const DeleteFileAlert: React.VoidFunctionComponent = () => {
const { isOpen, fileName } = useSelector((s) => s.explorer.deleteFileAlert);
const dispatch = useDispatch();
// istanbul ignore next: babel rewrites this line
const [i18n] = useI18n();
const i18n = useI18n();
// a11y: focus primary button when dialog is opened
const handleOpened = useCallback((node: HTMLElement) => {
+8
View File
@@ -1,6 +1,14 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
import { I18n, useI18n as useShopifyI18n } from '@shopify/react-i18n';
export function useI18n(): I18n {
// istanbul ignore next: babel-loader rewrites this line
const [i18n] = useShopifyI18n();
return i18n;
}
export enum I18nId {
Accept = 'action.accept',
Cancel = 'action.cancel',