From fa00c0aea62ec2a5978a2ac6df5b9380ead1be5e Mon Sep 17 00:00:00 2001 From: David Lechner Date: Fri, 21 Oct 2022 15:38:05 -0500 Subject: [PATCH] firmware/sagas: fix progress alerts These were being replaced (dismissed then new alert) instead of updated. --- src/alerts/actions.ts | 6 ++++-- src/alerts/sagas.ts | 2 +- src/firmware/sagas.test.ts | 18 ++++++++++++++++++ src/firmware/sagas.ts | 5 +++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/alerts/actions.ts b/src/alerts/actions.ts index c8efe510..5e37e85c 100644 --- a/src/alerts/actions.ts +++ b/src/alerts/actions.ts @@ -11,14 +11,15 @@ import { AlertActions, AlertDomain, AlertProps, AlertSpecific } from '../alerts' * @param specific The specific alert for the domain. * @param props Any additional properties required by this specific alert. * @param key Optional key to use as unique identifier for toast instead `..`. + * @param update Optional boolean flag to update existing alert instead of replacing it. */ export const alertsShowAlert = createAction( >( domain: D, specific: S, ...args: AlertProps extends never - ? [props?: never] - : [props: AlertProps, key?: string] + ? [args?: never] + : [props: AlertProps, key?: string, update?: boolean] ) => ({ type: 'alerts.action.showAlert', domain, @@ -26,6 +27,7 @@ export const alertsShowAlert = createAction( // HACK: using varargs to allow props and key to be optional props: args.at(0), key: args.at(1), + update: args.at(2), }), ); diff --git a/src/alerts/sagas.ts b/src/alerts/sagas.ts index 3a97694b..edd25636 100644 --- a/src/alerts/sagas.ts +++ b/src/alerts/sagas.ts @@ -23,7 +23,7 @@ function* handleShowAlert(action: ReturnType): Generator // if a toast with the same parameters is already open, close it so we // can open it again without duplicates. - if (existing.length > 0) { + if (!action.update && existing.length > 0) { toaster.dismiss(key); yield* delay(500); } diff --git a/src/firmware/sagas.test.ts b/src/firmware/sagas.test.ts index 14168009..b335a58d 100644 --- a/src/firmware/sagas.test.ts +++ b/src/firmware/sagas.test.ts @@ -140,6 +140,7 @@ describe('flashFirmware', () => { 'flashProgress', { action: 'erase', progress: undefined }, 'firmware.ble.progress', + true, ), ); @@ -187,6 +188,7 @@ describe('flashFirmware', () => { progress: offset / totalFirmwareSize, }, 'firmware.ble.progress', + true, ), ); @@ -224,6 +226,7 @@ describe('flashFirmware', () => { progress: 1, }, 'firmware.ble.progress', + true, ), ); @@ -303,6 +306,7 @@ describe('flashFirmware', () => { 'flashProgress', { action: 'erase', progress: undefined }, 'firmware.ble.progress', + true, ), ); @@ -350,6 +354,7 @@ describe('flashFirmware', () => { progress: offset / totalFirmwareSize, }, 'firmware.ble.progress', + true, ), ); @@ -387,6 +392,7 @@ describe('flashFirmware', () => { progress: 1, }, 'firmware.ble.progress', + true, ), ); @@ -1030,6 +1036,7 @@ describe('flashFirmware', () => { 'flashProgress', { action: 'erase', progress: undefined }, 'firmware.ble.progress', + true, ), ); @@ -1142,6 +1149,7 @@ describe('flashFirmware', () => { 'flashProgress', { action: 'erase', progress: undefined }, 'firmware.ble.progress', + true, ), ); @@ -1263,6 +1271,7 @@ describe('flashFirmware', () => { 'flashProgress', { action: 'erase', progress: undefined }, 'firmware.ble.progress', + true, ), ); @@ -1310,6 +1319,7 @@ describe('flashFirmware', () => { progress: offset / totalFirmwareSize, }, 'firmware.ble.progress', + true, ), ); @@ -1437,6 +1447,7 @@ describe('flashFirmware', () => { 'flashProgress', { action: 'erase', progress: undefined }, 'firmware.ble.progress', + true, ), ); @@ -1484,6 +1495,7 @@ describe('flashFirmware', () => { progress: offset / totalFirmwareSize, }, 'firmware.ble.progress', + true, ), ); @@ -1616,6 +1628,7 @@ describe('flashFirmware', () => { 'flashProgress', { action: 'erase', progress: undefined }, 'firmware.ble.progress', + true, ), ); @@ -1664,6 +1677,7 @@ describe('flashFirmware', () => { progress: offset / totalFirmwareSize, }, 'firmware.ble.progress', + true, ), ); @@ -1701,6 +1715,7 @@ describe('flashFirmware', () => { progress: 1, }, 'firmware.ble.progress', + true, ), ); @@ -2181,6 +2196,7 @@ describe('flashFirmware', () => { 'flashProgress', { action: 'erase', progress: undefined }, 'firmware.ble.progress', + true, ), ); @@ -2227,6 +2243,7 @@ describe('flashFirmware', () => { progress: offset / totalFirmwareSize, }, 'firmware.ble.progress', + true, ), ); @@ -2263,6 +2280,7 @@ describe('flashFirmware', () => { progress: 1, }, 'firmware.ble.progress', + true, ), ); diff --git a/src/firmware/sagas.ts b/src/firmware/sagas.ts index d1674ca4..957d8eba 100644 --- a/src/firmware/sagas.ts +++ b/src/firmware/sagas.ts @@ -443,6 +443,7 @@ function* handleFlashFirmware(action: ReturnType): Generat progress: undefined, }, firmwareBleProgressToastId, + true, ), ); @@ -508,6 +509,7 @@ function* handleFlashFirmware(action: ReturnType): Generat progress: offset / firmware.length, }, firmwareBleProgressToastId, + true, ), ); @@ -593,6 +595,7 @@ function* handleFlashFirmware(action: ReturnType): Generat progress: 1, }, firmwareBleProgressToastId, + true, ), ); @@ -632,6 +635,7 @@ function* handleDfuEraseProcess(event: { progress: event.bytesSent / event.expectedSize, }, firmwareDfuProgressToastId, + true, ), ); } @@ -649,6 +653,7 @@ function* handleDfuWriteProcess(event: { progress: event.bytesSent / event.expectedSize, }, firmwareDfuProgressToastId, + true, ), ); }