mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 10:35:11 +00:00
firmware/sagas: fix progress alerts
These were being replaced (dismissed then new alert) instead of updated.
This commit is contained in:
@@ -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 `<domain>.<specific>.<props>`.
|
||||
* @param update Optional boolean flag to update existing alert instead of replacing it.
|
||||
*/
|
||||
export const alertsShowAlert = createAction(
|
||||
<D extends AlertDomain, S extends AlertSpecific<D>>(
|
||||
domain: D,
|
||||
specific: S,
|
||||
...args: AlertProps<D, S> extends never
|
||||
? [props?: never]
|
||||
: [props: AlertProps<D, S>, key?: string]
|
||||
? [args?: never]
|
||||
: [props: AlertProps<D, S>, 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),
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ function* handleShowAlert(action: ReturnType<typeof alertsShowAlert>): 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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -443,6 +443,7 @@ function* handleFlashFirmware(action: ReturnType<typeof flashFirmware>): Generat
|
||||
progress: undefined,
|
||||
},
|
||||
firmwareBleProgressToastId,
|
||||
true,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -508,6 +509,7 @@ function* handleFlashFirmware(action: ReturnType<typeof flashFirmware>): Generat
|
||||
progress: offset / firmware.length,
|
||||
},
|
||||
firmwareBleProgressToastId,
|
||||
true,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -593,6 +595,7 @@ function* handleFlashFirmware(action: ReturnType<typeof flashFirmware>): 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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user