From 98d068124a0c2e5e27a06b634b805a1711d9c255 Mon Sep 17 00:00:00 2001 From: Abdurrahman Rajab Date: Sun, 11 Jun 2023 22:41:43 +0300 Subject: [PATCH] chore: add a user feedback in case if an error (#171) undefined --- src/popup/pages/posthighlight.tsx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/popup/pages/posthighlight.tsx b/src/popup/pages/posthighlight.tsx index 20a71037..7006ee19 100644 --- a/src/popup/pages/posthighlight.tsx +++ b/src/popup/pages/posthighlight.tsx @@ -15,15 +15,23 @@ const PostOnHighlight = ({ prUrl, prTitle }: { prUrl: string, prTitle: string }) const [highlightContent, setHighlightContent] = useState(""); const [isSendButtonEnabled, enableSendButton] = useState(true); - const generateAiDescription = async () => { - const toastId = toast.loading("Generating summary..."); - + const generateAiDescription = () => { enableSendButton(false); - const description = await getAiDescription(prUrl); + const description = getAiDescription(prUrl); - toast.dismiss(toastId); - setHighlightContent(description); - enableSendButton(true); + toast.promise(description, { + loading: "Generating summary...", + success: data => { + enableSendButton(true); + setHighlightContent(data); + + return "Successfully Generated Summary"; + }, + error: e => { + enableSendButton(true); + return `Uh oh, there was an error! ${e.message}`; + }, + }).catch(console.error); };