diff --git a/src/actions.ts b/src/actions.ts index 085b38a8..33b1a6b3 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2020 The Pybricks Authors +// Copyright (c) 2020-2021 The Pybricks Authors +import { useDispatch as useReduxDispatch } from 'react-redux'; import { Dispatch as ReduxDispatch } from 'redux'; import { AppAction } from './app/actions'; import { BleDIServiceAction } from './ble-device-info-service/actions'; @@ -60,3 +61,8 @@ export type Action = * Dispatch function. */ export type Dispatch = ReduxDispatch; + +/** + * Typed version of Redux useDispatch() hook. + */ +export const useDispatch = (): Dispatch => useReduxDispatch(); diff --git a/src/app/App.tsx b/src/app/App.tsx index 60f7e211..bba931ce 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -3,8 +3,8 @@ import { Classes } from '@blueprintjs/core'; import React, { useEffect, useState } from 'react'; -import { useDispatch } from 'react-redux'; import SplitterLayout from 'react-splitter-layout'; +import { useDispatch } from '../actions'; import Editor from '../editor/Editor'; import { useSelector } from '../reducers'; import { toggleBoolean } from '../settings/actions'; diff --git a/src/editor/Editor.tsx b/src/editor/Editor.tsx index 7c3e37c6..99f777cf 100644 --- a/src/editor/Editor.tsx +++ b/src/editor/Editor.tsx @@ -12,8 +12,8 @@ import tomorrowNightEightiesTheme from 'monaco-themes/themes/Tomorrow-Night-Eigh import xcodeTheme from 'monaco-themes/themes/Xcode_default.json'; import React, { useEffect, useRef } from 'react'; import MonacoEditor, { monaco } from 'react-monaco-editor'; -import { useDispatch } from 'react-redux'; import { IDisposable } from 'xterm'; +import { useDispatch } from '../actions'; import { compile } from '../mpy/actions'; import { useSelector } from '../reducers'; import { toggleBoolean } from '../settings/actions'; diff --git a/src/editor/OpenButton.tsx b/src/editor/OpenButton.tsx index f5cf187e..b5e77ded 100644 --- a/src/editor/OpenButton.tsx +++ b/src/editor/OpenButton.tsx @@ -2,7 +2,7 @@ // Copyright (c) 2020-2021 The Pybricks Authors import React from 'react'; -import { useDispatch } from 'react-redux'; +import { useDispatch } from '../actions'; import * as notificationActions from '../notifications/actions'; import { useSelector } from '../reducers'; import OpenFileButton, { OpenFileButtonProps } from '../toolbar/OpenFileButton'; diff --git a/src/editor/SaveAsButton.tsx b/src/editor/SaveAsButton.tsx index d7c0d374..26e991d9 100644 --- a/src/editor/SaveAsButton.tsx +++ b/src/editor/SaveAsButton.tsx @@ -2,7 +2,7 @@ // Copyright (c) 2020-2021 The Pybricks Authors import React from 'react'; -import { useDispatch } from 'react-redux'; +import { useDispatch } from '../actions'; import * as editorActions from '../editor/actions'; import { useSelector } from '../reducers'; import ActionButton, { ActionButtonProps } from '../toolbar/ActionButton'; diff --git a/src/firmware/FlashButton.tsx b/src/firmware/FlashButton.tsx index 4c319837..781f14b2 100644 --- a/src/firmware/FlashButton.tsx +++ b/src/firmware/FlashButton.tsx @@ -2,7 +2,7 @@ // Copyright (c) 2020-2021 The Pybricks Authors import React from 'react'; -import { useDispatch } from 'react-redux'; +import { useDispatch } from '../actions'; import { BleConnectionState } from '../ble/reducers'; import { BootloaderConnectionState } from '../lwp3-bootloader/reducers'; import * as notificationActions from '../notifications/actions'; diff --git a/src/hub/BluetoothButton.tsx b/src/hub/BluetoothButton.tsx index 94eade97..51595388 100644 --- a/src/hub/BluetoothButton.tsx +++ b/src/hub/BluetoothButton.tsx @@ -2,7 +2,7 @@ // Copyright (c) 2020-2021 The Pybricks Authors import React from 'react'; -import { useDispatch } from 'react-redux'; +import { useDispatch } from '../actions'; import { toggleBluetooth } from '../ble/actions'; import { BleConnectionState } from '../ble/reducers'; import { BootloaderConnectionState } from '../lwp3-bootloader/reducers'; diff --git a/src/hub/RunButton.tsx b/src/hub/RunButton.tsx index 33955423..31961d62 100644 --- a/src/hub/RunButton.tsx +++ b/src/hub/RunButton.tsx @@ -2,7 +2,7 @@ // Copyright (c) 2020-2021 The Pybricks Authors import React from 'react'; -import { useDispatch } from 'react-redux'; +import { useDispatch } from '../actions'; import { useSelector } from '../reducers'; import ActionButton, { ActionButtonProps } from '../toolbar/ActionButton'; import { TooltipId } from '../toolbar/i18n'; diff --git a/src/hub/StopButton.tsx b/src/hub/StopButton.tsx index 69a24cf1..76fb80b1 100644 --- a/src/hub/StopButton.tsx +++ b/src/hub/StopButton.tsx @@ -2,7 +2,7 @@ // Copyright (c) 2020-2021 The Pybricks Authors import React from 'react'; -import { useDispatch } from 'react-redux'; +import { useDispatch } from '../actions'; import { useSelector } from '../reducers'; import ActionButton, { ActionButtonProps } from '../toolbar/ActionButton'; import { TooltipId } from '../toolbar/i18n'; diff --git a/src/licenses/LicenseDialog.tsx b/src/licenses/LicenseDialog.tsx index d4d8ad8e..bb20d3f3 100644 --- a/src/licenses/LicenseDialog.tsx +++ b/src/licenses/LicenseDialog.tsx @@ -14,7 +14,7 @@ import { } from '@blueprintjs/core'; import { useI18n } from '@shopify/react-i18n'; import React from 'react'; -import { useDispatch } from 'react-redux'; +import { useDispatch } from '../actions'; import { appName } from '../app/constants'; import { useSelector } from '../reducers'; import { fetchList, select } from './actions'; diff --git a/src/settings/SettingsDrawer.tsx b/src/settings/SettingsDrawer.tsx index 7e21e08c..7dd6686f 100644 --- a/src/settings/SettingsDrawer.tsx +++ b/src/settings/SettingsDrawer.tsx @@ -19,8 +19,8 @@ import { import { Tooltip2 } from '@blueprintjs/popover2'; import { useI18n } from '@shopify/react-i18n'; import React, { useMemo, useState } from 'react'; -import { useDispatch } from 'react-redux'; import AboutDialog from '../about/AboutDialog'; +import { useDispatch } from '../actions'; import { checkForUpdate, installPrompt, reload } from '../app/actions'; import { pybricksBugReportsUrl, diff --git a/src/terminal/Terminal.tsx b/src/terminal/Terminal.tsx index 45b1c55d..7dcf7b3b 100644 --- a/src/terminal/Terminal.tsx +++ b/src/terminal/Terminal.tsx @@ -5,9 +5,9 @@ import { Menu, MenuDivider, MenuItem, ResizeSensor } from '@blueprintjs/core'; import { ContextMenu2, ContextMenu2ContentProps } from '@blueprintjs/popover2'; import { useI18n } from '@shopify/react-i18n'; import React, { useContext, useEffect, useMemo, useRef } from 'react'; -import { useDispatch } from 'react-redux'; import { Terminal as XTerm } from 'xterm'; import { FitAddon } from 'xterm-addon-fit'; +import { useDispatch } from '../actions'; import { useSelector } from '../reducers'; import { isMacOS } from '../utils/os'; import { TerminalContext } from './TerminalContext';