From 3b8f43f02d86096168e9933b9284c4d099269762 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 27 Mar 2023 15:36:55 -0500 Subject: [PATCH] AuthorizeRejectButtons: fix onReject never being called --- app/soapbox/components/authorize-reject-buttons.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/soapbox/components/authorize-reject-buttons.tsx b/app/soapbox/components/authorize-reject-buttons.tsx index de28be80c..10ab2bbf2 100644 --- a/app/soapbox/components/authorize-reject-buttons.tsx +++ b/app/soapbox/components/authorize-reject-buttons.tsx @@ -14,7 +14,11 @@ const AuthorizeRejectButtons: React.FC = ({ onAuthorize const [state, setState] = useState<'authorizing' | 'rejecting' | 'authorized' | 'rejected' | 'pending'>('pending'); const timeout = useRef(); - function handleAction(present: 'authorizing' | 'rejecting', past: 'authorized' | 'rejected'): void { + function handleAction( + present: 'authorizing' | 'rejecting', + past: 'authorized' | 'rejected', + action: () => Promise | unknown, + ): void { if (state === present) { if (timeout.current) { clearTimeout(timeout.current); @@ -24,7 +28,7 @@ const AuthorizeRejectButtons: React.FC = ({ onAuthorize setState(present); timeout.current = setTimeout(async () => { try { - await onAuthorize(); + await action(); setState(past); } catch (e) { console.error(e); @@ -33,8 +37,8 @@ const AuthorizeRejectButtons: React.FC = ({ onAuthorize } } - const handleAuthorize = async () => handleAction('authorizing', 'authorized'); - const handleReject = async () => handleAction('rejecting', 'rejected'); + const handleAuthorize = async () => handleAction('authorizing', 'authorized', onAuthorize); + const handleReject = async () => handleAction('rejecting', 'rejected', onReject); useEffect(() => { return () => {