Skip to content

Commit fa00c0a

Browse files
committed
firmware/sagas: fix progress alerts
These were being replaced (dismissed then new alert) instead of updated.
1 parent 4400c06 commit fa00c0a

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

src/alerts/actions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ import { AlertActions, AlertDomain, AlertProps, AlertSpecific } from '../alerts'
1111
* @param specific The specific alert for the domain.
1212
* @param props Any additional properties required by this specific alert.
1313
* @param key Optional key to use as unique identifier for toast instead `<domain>.<specific>.<props>`.
14+
* @param update Optional boolean flag to update existing alert instead of replacing it.
1415
*/
1516
export const alertsShowAlert = createAction(
1617
<D extends AlertDomain, S extends AlertSpecific<D>>(
1718
domain: D,
1819
specific: S,
1920
...args: AlertProps<D, S> extends never
20-
? [props?: never]
21-
: [props: AlertProps<D, S>, key?: string]
21+
? [args?: never]
22+
: [props: AlertProps<D, S>, key?: string, update?: boolean]
2223
) => ({
2324
type: 'alerts.action.showAlert',
2425
domain,
2526
specific,
2627
// HACK: using varargs to allow props and key to be optional
2728
props: args.at(0),
2829
key: args.at(1),
30+
update: args.at(2),
2931
}),
3032
);
3133

src/alerts/sagas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function* handleShowAlert(action: ReturnType<typeof alertsShowAlert>): Generator
2323

2424
// if a toast with the same parameters is already open, close it so we
2525
// can open it again without duplicates.
26-
if (existing.length > 0) {
26+
if (!action.update && existing.length > 0) {
2727
toaster.dismiss(key);
2828
yield* delay(500);
2929
}

src/firmware/sagas.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ describe('flashFirmware', () => {
140140
'flashProgress',
141141
{ action: 'erase', progress: undefined },
142142
'firmware.ble.progress',
143+
true,
143144
),
144145
);
145146

@@ -187,6 +188,7 @@ describe('flashFirmware', () => {
187188
progress: offset / totalFirmwareSize,
188189
},
189190
'firmware.ble.progress',
191+
true,
190192
),
191193
);
192194

@@ -224,6 +226,7 @@ describe('flashFirmware', () => {
224226
progress: 1,
225227
},
226228
'firmware.ble.progress',
229+
true,
227230
),
228231
);
229232

@@ -303,6 +306,7 @@ describe('flashFirmware', () => {
303306
'flashProgress',
304307
{ action: 'erase', progress: undefined },
305308
'firmware.ble.progress',
309+
true,
306310
),
307311
);
308312

@@ -350,6 +354,7 @@ describe('flashFirmware', () => {
350354
progress: offset / totalFirmwareSize,
351355
},
352356
'firmware.ble.progress',
357+
true,
353358
),
354359
);
355360

@@ -387,6 +392,7 @@ describe('flashFirmware', () => {
387392
progress: 1,
388393
},
389394
'firmware.ble.progress',
395+
true,
390396
),
391397
);
392398

@@ -1030,6 +1036,7 @@ describe('flashFirmware', () => {
10301036
'flashProgress',
10311037
{ action: 'erase', progress: undefined },
10321038
'firmware.ble.progress',
1039+
true,
10331040
),
10341041
);
10351042

@@ -1142,6 +1149,7 @@ describe('flashFirmware', () => {
11421149
'flashProgress',
11431150
{ action: 'erase', progress: undefined },
11441151
'firmware.ble.progress',
1152+
true,
11451153
),
11461154
);
11471155

@@ -1263,6 +1271,7 @@ describe('flashFirmware', () => {
12631271
'flashProgress',
12641272
{ action: 'erase', progress: undefined },
12651273
'firmware.ble.progress',
1274+
true,
12661275
),
12671276
);
12681277

@@ -1310,6 +1319,7 @@ describe('flashFirmware', () => {
13101319
progress: offset / totalFirmwareSize,
13111320
},
13121321
'firmware.ble.progress',
1322+
true,
13131323
),
13141324
);
13151325

@@ -1437,6 +1447,7 @@ describe('flashFirmware', () => {
14371447
'flashProgress',
14381448
{ action: 'erase', progress: undefined },
14391449
'firmware.ble.progress',
1450+
true,
14401451
),
14411452
);
14421453

@@ -1484,6 +1495,7 @@ describe('flashFirmware', () => {
14841495
progress: offset / totalFirmwareSize,
14851496
},
14861497
'firmware.ble.progress',
1498+
true,
14871499
),
14881500
);
14891501

@@ -1616,6 +1628,7 @@ describe('flashFirmware', () => {
16161628
'flashProgress',
16171629
{ action: 'erase', progress: undefined },
16181630
'firmware.ble.progress',
1631+
true,
16191632
),
16201633
);
16211634

@@ -1664,6 +1677,7 @@ describe('flashFirmware', () => {
16641677
progress: offset / totalFirmwareSize,
16651678
},
16661679
'firmware.ble.progress',
1680+
true,
16671681
),
16681682
);
16691683

@@ -1701,6 +1715,7 @@ describe('flashFirmware', () => {
17011715
progress: 1,
17021716
},
17031717
'firmware.ble.progress',
1718+
true,
17041719
),
17051720
);
17061721

@@ -2181,6 +2196,7 @@ describe('flashFirmware', () => {
21812196
'flashProgress',
21822197
{ action: 'erase', progress: undefined },
21832198
'firmware.ble.progress',
2199+
true,
21842200
),
21852201
);
21862202

@@ -2227,6 +2243,7 @@ describe('flashFirmware', () => {
22272243
progress: offset / totalFirmwareSize,
22282244
},
22292245
'firmware.ble.progress',
2246+
true,
22302247
),
22312248
);
22322249

@@ -2263,6 +2280,7 @@ describe('flashFirmware', () => {
22632280
progress: 1,
22642281
},
22652282
'firmware.ble.progress',
2283+
true,
22662284
),
22672285
);
22682286

src/firmware/sagas.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ function* handleFlashFirmware(action: ReturnType<typeof flashFirmware>): Generat
443443
progress: undefined,
444444
},
445445
firmwareBleProgressToastId,
446+
true,
446447
),
447448
);
448449

@@ -508,6 +509,7 @@ function* handleFlashFirmware(action: ReturnType<typeof flashFirmware>): Generat
508509
progress: offset / firmware.length,
509510
},
510511
firmwareBleProgressToastId,
512+
true,
511513
),
512514
);
513515

@@ -593,6 +595,7 @@ function* handleFlashFirmware(action: ReturnType<typeof flashFirmware>): Generat
593595
progress: 1,
594596
},
595597
firmwareBleProgressToastId,
598+
true,
596599
),
597600
);
598601

@@ -632,6 +635,7 @@ function* handleDfuEraseProcess(event: {
632635
progress: event.bytesSent / event.expectedSize,
633636
},
634637
firmwareDfuProgressToastId,
638+
true,
635639
),
636640
);
637641
}
@@ -649,6 +653,7 @@ function* handleDfuWriteProcess(event: {
649653
progress: event.bytesSent / event.expectedSize,
650654
},
651655
firmwareDfuProgressToastId,
656+
true,
652657
),
653658
);
654659
}

0 commit comments

Comments
 (0)