reducers: use typed useSelector hook

This refactors the code to use a typed useSelector() hook.
This commit is contained in:
David Lechner
2021-12-27 17:48:41 -06:00
parent 8527cf86b2
commit 8d26f768bf
13 changed files with 65 additions and 84 deletions
+4 -6
View File
@@ -2,11 +2,11 @@
// Copyright (c) 2020-2021 The Pybricks Authors
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useDispatch } from 'react-redux';
import { toggleBluetooth } from '../ble/actions';
import { BleConnectionState } from '../ble/reducers';
import { BootloaderConnectionState } from '../lwp3-bootloader/reducers';
import { RootState } from '../reducers';
import { useSelector } from '../reducers';
import ActionButton, { ActionButtonProps } from '../toolbar/ActionButton';
import { TooltipId } from '../toolbar/i18n';
import btConnectedIcon from './bt-connected.svg';
@@ -15,10 +15,8 @@ import btDisconnectedIcon from './bt-disconnected.svg';
type BluetoothButtonProps = Pick<ActionButtonProps, 'id'>;
const BluetoothButton: React.FunctionComponent<BluetoothButtonProps> = (props) => {
const bootloaderConnection = useSelector(
(state: RootState) => state.bootloader.connection,
);
const bleConnection = useSelector((state: RootState) => state.ble.connection);
const bootloaderConnection = useSelector((s) => s.bootloader.connection);
const bleConnection = useSelector((s) => s.ble.connection);
const isDisconnected =
bootloaderConnection === BootloaderConnectionState.Disconnected &&
+5 -7
View File
@@ -2,8 +2,8 @@
// Copyright (c) 2020-2021 The Pybricks Authors
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { RootState } from '../reducers';
import { useDispatch } from 'react-redux';
import { useSelector } from '../reducers';
import ActionButton, { ActionButtonProps } from '../toolbar/ActionButton';
import { TooltipId } from '../toolbar/i18n';
import { downloadAndRun } from './actions';
@@ -14,11 +14,9 @@ type RunButtonProps = Pick<ActionButtonProps, 'id'> &
Pick<ActionButtonProps, 'keyboardShortcut'>;
const RunButton: React.FunctionComponent<RunButtonProps> = (props) => {
const editor = useSelector((state: RootState) => state.editor.current);
const downloadProgress = useSelector(
(state: RootState) => state.hub.downloadProgress,
);
const runtime = useSelector((state: RootState) => state.hub.runtime);
const editor = useSelector((s) => s.editor.current);
const downloadProgress = useSelector((s) => s.hub.downloadProgress);
const runtime = useSelector((s) => s.hub.runtime);
const dispatch = useDispatch();
+3 -3
View File
@@ -2,8 +2,8 @@
// Copyright (c) 2020-2021 The Pybricks Authors
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { RootState } from '../reducers';
import { useDispatch } from 'react-redux';
import { useSelector } from '../reducers';
import ActionButton, { ActionButtonProps } from '../toolbar/ActionButton';
import { TooltipId } from '../toolbar/i18n';
import { stop } from './actions';
@@ -14,7 +14,7 @@ type StopButtonProps = Pick<ActionButtonProps, 'id'> &
Pick<ActionButtonProps, 'keyboardShortcut'>;
const StopButton: React.FunctionComponent<StopButtonProps> = (props) => {
const runtime = useSelector((state: RootState) => state.hub.runtime);
const runtime = useSelector((s) => s.hub.runtime);
const dispatch = useDispatch();