@@ -321,6 +321,22 @@ export const constructNonHeaderActionButtons = ({
321
321
}
322
322
} ;
323
323
324
+ function makeButtonCallback < Args : HeaderArgs | MessageArgs > (
325
+ buttonList: Button< Args > [],
326
+ args: Args,
327
+ ) {
328
+ return buttonIndex => {
329
+ ( async ( ) => {
330
+ const pressedButton : Button < Args > = buttonList[buttonIndex];
331
+ try {
332
+ await pressedButton ( args ) ;
333
+ } catch (err) {
334
+ Alert . alert ( args . _ ( pressedButton . errorMessage ) , err . message ) ;
335
+ }
336
+ } ) ( ) ;
337
+ } ;
338
+ }
339
+
324
340
export const showMessageActionSheet = ({
325
341
showActionSheetWithOptions ,
326
342
callbacks ,
@@ -345,27 +361,17 @@ export const showMessageActionSheet = ({
345
361
narrow : Narrow ,
346
362
| } ): void => {
347
363
const buttonList = constructNonHeaderActionButtons ( { backgroundData, message, narrow } ) ;
348
- const callback = buttonIndex => {
349
- ( async ( ) => {
350
- const pressedButton : Button < MessageArgs > = buttonList[buttonIndex];
351
- try {
352
- await pressedButton ( {
353
- ...backgroundData ,
354
- ...callbacks ,
355
- message,
356
- narrow,
357
- } ) ;
358
- } catch (err) {
359
- Alert . alert ( callbacks . _ ( pressedButton . errorMessage ) , err . message ) ;
360
- }
361
- } ) ( ) ;
362
- } ;
363
364
showActionSheetWithOptions (
364
365
{
365
366
options : buttonList . map ( button => callbacks . _ ( button . title ) ) ,
366
367
cancelButtonIndex : buttonList . length - 1 ,
367
368
} ,
368
- callback ,
369
+ makeButtonCallback ( buttonList , {
370
+ ...backgroundData ,
371
+ ...callbacks ,
372
+ message,
373
+ narrow,
374
+ } ) ,
369
375
) ;
370
376
} ;
371
377
@@ -397,27 +403,17 @@ export const showHeaderActionSheet = ({
397
403
stream,
398
404
topic,
399
405
} ) ;
400
- const callback = buttonIndex => {
401
- ( async ( ) => {
402
- const pressedButton : Button < HeaderArgs > = buttonList[buttonIndex];
403
- try {
404
- await pressedButton ( {
405
- ...backgroundData ,
406
- ...callbacks ,
407
- stream,
408
- topic,
409
- } ) ;
410
- } catch (err) {
411
- Alert . alert ( callbacks . _ ( pressedButton . errorMessage ) , err . message ) ;
412
- }
413
- } ) ( ) ;
414
- } ;
415
406
showActionSheetWithOptions (
416
407
{
417
408
title : `#${ stream } > ${ topic } ` ,
418
409
options : buttonList . map ( button => callbacks . _ ( button . title ) ) ,
419
410
cancelButtonIndex : buttonList . length - 1 ,
420
411
} ,
421
- callback ,
412
+ makeButtonCallback ( buttonList , {
413
+ ...backgroundData ,
414
+ ...callbacks ,
415
+ stream,
416
+ topic,
417
+ } ) ,
422
418
) ;
423
419
} ;
0 commit comments