Skip to content

Commit 3f443c6

Browse files
committed
ActionSheets: Get rid of makeButtonCallback function
Now that we want to pass different arguments to different types of action sheet buttons, it doesn't make much sense to have them all call the same makeButtonCallback function. I spent a little while trying to write makeButtonCallback with a type parameter, but I wasn't able to find a way to do that that made flow happy, and I suspect that even if I did, it'd be harder to understand than just duplicating a few lines of code. We can definitely come back to this if we end up with a lot of actionsheets, though.
1 parent 963c978 commit 3f443c6

File tree

1 file changed

+36
-58
lines changed

1 file changed

+36
-58
lines changed

src/message/messageActionSheet.js

Lines changed: 36 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -330,46 +330,6 @@ export const constructNonHeaderActionButtons = ({
330330
}
331331
};
332332

333-
function makeButtonCallback<ButtonType: HeaderButton | MessageButton>({
334-
buttonList,
335-
auth,
336-
subscriptions,
337-
ownUser,
338-
flags,
339-
message,
340-
callbacks,
341-
}: {|
342-
buttonList: ButtonType[],
343-
auth: Auth,
344-
subscriptions: Subscription[],
345-
ownUser: User,
346-
flags: FlagsState,
347-
message: Message | Outbox,
348-
callbacks: {|
349-
dispatch: Dispatch,
350-
startEditMessage: (editMessage: EditMessage) => void,
351-
_: GetText,
352-
|},
353-
|}) {
354-
return buttonIndex => {
355-
(async () => {
356-
const pressedButton: ButtonType = buttonList[buttonIndex];
357-
try {
358-
await pressedButton({
359-
subscriptions,
360-
auth,
361-
ownUser,
362-
flags,
363-
message,
364-
...callbacks,
365-
});
366-
} catch (err) {
367-
Alert.alert(callbacks._(pressedButton.errorMessage), err.message);
368-
}
369-
})();
370-
};
371-
}
372-
373333
export const showMessageActionSheet = (
374334
showActionSheetWithOptions: ShowActionSheetWithOptions,
375335
callbacks: {|
@@ -392,20 +352,29 @@ export const showMessageActionSheet = (
392352
message,
393353
narrow,
394354
});
355+
const callback = buttonIndex => {
356+
(async () => {
357+
const pressedButton = buttonList[buttonIndex];
358+
try {
359+
await pressedButton({
360+
subscriptions: params.subscriptions,
361+
auth: params.auth,
362+
ownUser: params.ownUser,
363+
flags: params.flags,
364+
message,
365+
...callbacks,
366+
});
367+
} catch (err) {
368+
Alert.alert(callbacks._(pressedButton.errorMessage), err.message);
369+
}
370+
})();
371+
};
395372
showActionSheetWithOptions(
396373
{
397374
options: buttonList.map(button => callbacks._(button.title)),
398375
cancelButtonIndex: buttonList.length - 1,
399376
},
400-
makeButtonCallback({
401-
buttonList,
402-
auth: params.auth,
403-
subscriptions: params.subscriptions,
404-
ownUser: params.ownUser,
405-
flags: params.flags,
406-
message,
407-
callbacks,
408-
}),
377+
callback,
409378
);
410379
};
411380

@@ -433,20 +402,29 @@ export const showHeaderActionSheet = (
433402
stream: streamNameOfStreamMessage(message),
434403
topic: message.subject,
435404
});
405+
const callback = buttonIndex => {
406+
(async () => {
407+
const pressedButton = buttonList[buttonIndex];
408+
try {
409+
await pressedButton({
410+
subscriptions: params.subscriptions,
411+
auth: params.auth,
412+
ownUser: params.ownUser,
413+
flags: params.flags,
414+
message,
415+
...callbacks,
416+
});
417+
} catch (err) {
418+
Alert.alert(callbacks._(pressedButton.errorMessage), err.message);
419+
}
420+
})();
421+
};
436422
showActionSheetWithOptions(
437423
{
438424
title: `#${streamNameOfStreamMessage(message)} > ${message.subject}`,
439425
options: buttonList.map(button => callbacks._(button.title)),
440426
cancelButtonIndex: buttonList.length - 1,
441427
},
442-
makeButtonCallback({
443-
buttonList,
444-
auth: params.auth,
445-
subscriptions: params.subscriptions,
446-
ownUser: params.ownUser,
447-
flags: params.flags,
448-
message,
449-
callbacks,
450-
}),
428+
callback,
451429
);
452430
};

0 commit comments

Comments
 (0)