mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 10:35:11 +00:00
toasterTypes: change toaster to ref
Instead of rendering the toaster separate from the main index, add it there so we can inherit all of the context providers. This requires passing the ref object instead of the toaster instance itself, so sagas have to be updated.
This commit is contained in:
committed by
David Lechner
parent
be9272ca9c
commit
fa27649fe3
@@ -3,7 +3,7 @@
|
||||
|
||||
import { Button, Intent } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { CreateToast } from '../../i18nToaster';
|
||||
import type { CreateToast } from '../../toasterTypes';
|
||||
import { useI18n } from './i18n';
|
||||
|
||||
type DfuErrorProps = {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { CreateToast } from '../../i18nToaster';
|
||||
import type { CreateToast } from '../../toasterTypes';
|
||||
import { useI18n } from './i18n';
|
||||
|
||||
const FirmwareMismatch: React.VoidFunctionComponent = () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { Intent, ProgressBar } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { CreateToast } from '../../i18nToaster';
|
||||
import type { CreateToast } from '../../toasterTypes';
|
||||
import { useI18n } from './i18n';
|
||||
|
||||
type FlashProgressProps = {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { AnchorButton, Intent } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { pybricksUsbDfuTroubleshootingUrl } from '../../app/constants';
|
||||
import { CreateToast } from '../../i18nToaster';
|
||||
import type { CreateToast } from '../../toasterTypes';
|
||||
import ExternalLinkIcon from '../../utils/ExternalLinkIcon';
|
||||
import { isLinux, isWindows } from '../../utils/os';
|
||||
import { useI18n } from './i18n';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { CreateToast } from '../../i18nToaster';
|
||||
import type { CreateToast } from '../../toasterTypes';
|
||||
import { useI18n } from './i18n';
|
||||
|
||||
const NoDfuInterface: React.VoidFunctionComponent = () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { CreateToast } from '../../i18nToaster';
|
||||
import type { CreateToast } from '../../toasterTypes';
|
||||
import { useI18n } from './i18n';
|
||||
|
||||
const NoWebUsb: React.VoidFunctionComponent = () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { CreateToast } from '../../i18nToaster';
|
||||
import type { CreateToast } from '../../toasterTypes';
|
||||
import { useI18n } from './i18n';
|
||||
|
||||
const ReleaseButton: React.VoidFunctionComponent = () => {
|
||||
|
||||
+23
-23
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2021-2022 The Pybricks Authors
|
||||
|
||||
import { ToasterInstance } from '@blueprintjs/core';
|
||||
import type { ToasterInstance } from '@blueprintjs/core';
|
||||
import {
|
||||
FirmwareMetadata,
|
||||
FirmwareMetadataV110,
|
||||
@@ -83,7 +83,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -231,7 +231,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -361,7 +361,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -411,7 +411,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -479,7 +479,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -543,7 +543,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -610,7 +610,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -670,7 +670,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -736,7 +736,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -819,7 +819,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -885,7 +885,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -984,7 +984,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1092,7 +1092,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1240,7 +1240,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1386,7 +1386,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1538,7 +1538,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1585,7 +1585,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1631,7 +1631,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1691,7 +1691,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1752,7 +1752,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1816,7 +1816,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1905,7 +1905,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
toasterRef: { current: mock<ToasterInstance>() },
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020-2022 The Pybricks Authors
|
||||
|
||||
import { ToasterInstance } from '@blueprintjs/core';
|
||||
import {
|
||||
FirmwareReader,
|
||||
FirmwareReaderError,
|
||||
@@ -56,6 +55,7 @@ import { MaxProgramFlashSize, Result } from '../lwp3-bootloader/protocol';
|
||||
import { BootloaderConnectionState } from '../lwp3-bootloader/reducers';
|
||||
import { compile, didCompile, didFailToCompile } from '../mpy/actions';
|
||||
import { RootState } from '../reducers';
|
||||
import type { ToasterRef } from '../toasterTypes';
|
||||
import { LegoUsbProductId, legoUsbVendorId } from '../usb';
|
||||
import { defined, ensureError, hex, maybe } from '../utils';
|
||||
import { crc32, fmod, sumComplement32 } from '../utils/math';
|
||||
@@ -92,7 +92,8 @@ const firmwareZipMap = new Map<HubType, string>([
|
||||
* parent task).
|
||||
*/
|
||||
function* disconnectAndCancel(): SagaGenerator<void> {
|
||||
const toaster = yield* getContext<ToasterInstance>('toaster');
|
||||
const toaster = (yield* getContext<ToasterRef>('toasterRef')).current;
|
||||
defined(toaster);
|
||||
|
||||
toaster.dismiss('firmware.ble.progress');
|
||||
|
||||
@@ -375,7 +376,8 @@ function* loadFirmware(
|
||||
* @param action The action that triggered this saga.
|
||||
*/
|
||||
function* handleFlashFirmware(action: ReturnType<typeof flashFirmware>): Generator {
|
||||
const toaster = yield* getContext<ToasterInstance>('toaster');
|
||||
const toaster = (yield* getContext<ToasterRef>('toasterRef')).current;
|
||||
defined(toaster);
|
||||
|
||||
try {
|
||||
let firmware: Uint8Array | undefined = undefined;
|
||||
@@ -703,7 +705,8 @@ function* handleFlashUsbDfu(action: ReturnType<typeof firmwareFlashUsbDfu>): Gen
|
||||
dfu.dfuseStartAddress = dfuFirmwareStartAddress;
|
||||
const writeProc = dfu.write(1024, firmware, true);
|
||||
|
||||
const toaster = yield* getContext<ToasterInstance>('toaster');
|
||||
const toaster = (yield* getContext<ToasterRef>('toasterRef')).current;
|
||||
defined(toaster);
|
||||
|
||||
defer.push(
|
||||
writeProc.events.on('erase/process', (sent, total) => {
|
||||
|
||||
Reference in New Issue
Block a user