From b3cbce44fd26983e1949aeda23a8e38182cde09f Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 7 Aug 2024 11:58:38 -0500 Subject: [PATCH] Improve feedback and handle errors in dropdown --- src/view/com/util/forms/PostDropdownBtn.tsx | 70 +++++++++++++++------ 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/src/view/com/util/forms/PostDropdownBtn.tsx b/src/view/com/util/forms/PostDropdownBtn.tsx index 0c35f07dd0..bfdf9b168d 100644 --- a/src/view/com/util/forms/PostDropdownBtn.tsx +++ b/src/view/com/util/forms/PostDropdownBtn.tsx @@ -269,29 +269,61 @@ let PostDropdownBtn = ({ [navigation, postUri], ) - const onToggleReplyVisibility = React.useCallback(() => { + const onToggleReplyVisibility = React.useCallback(async () => { if (!rootPostUri) return - // TODO handle failure - toggleReplyVisibility({ - postUri: rootPostUri, - replyUri: postUri, - action: isReplyHiddenByThreadgate ? 'show' : 'hide', - }) - }, [isReplyHiddenByThreadgate, rootPostUri, postUri, toggleReplyVisibility]) + const action = isReplyHiddenByThreadgate ? 'show' : 'hide' + const isHide = action === 'hide' - const onToggleQuotePostAttachment = React.useCallback(() => { + try { + await toggleReplyVisibility({ + postUri: rootPostUri, + replyUri: postUri, + action, + }) + Toast.show( + isHide + ? _(msg`Reply was successfully hidden`) + : _(msg`Reply visibility updated`), + ) + } catch (e: any) { + Toast.show(_(msg`Updating reply visibility failed`)) + logger.error(`Failed to ${action} reply`, {safeMessage: e.message}) + } + }, [ + _, + isReplyHiddenByThreadgate, + rootPostUri, + postUri, + toggleReplyVisibility, + ]) + + const onToggleQuotePostAttachment = React.useCallback(async () => { if (!quoteEmbed) return - // TODO handle failure - toggleQuoteDetachment({ - post, - quoteUri: quoteEmbed.uri, - action: quoteEmbed.isDetached ? 'reattach' : 'detach', - }) - }, [quoteEmbed, post, toggleQuoteDetachment]) + const action = quoteEmbed.isDetached ? 'reattach' : 'detach' + const isDetach = action === 'detach' + + try { + await toggleQuoteDetachment({ + post, + quoteUri: quoteEmbed.uri, + action: quoteEmbed.isDetached ? 'reattach' : 'detach', + }) + Toast.show( + isDetach + ? _(msg`Quote post was successfully detached`) + : _(msg`Quote post was re-attached`), + ) + } catch (e: any) { + Toast.show(_(msg`Updating quote attachment failed`)) + logger.error(`Failed to ${action} quote`, {safeMessage: e.message}) + } + }, [_, quoteEmbed, post, toggleQuoteDetachment]) const canEmbed = isWeb && gtMobile && !hideInPWI + const canHideReply = !isAuthor && !isPostHidden && rootPostUri && isReply + const canDetachQuote = quoteEmbed && quoteEmbed.isOwnedByViewer return ( @@ -446,11 +478,11 @@ let PostDropdownBtn = ({ )} - {hasSession && ( + {hasSession && (canHideReply || canDetachQuote) && ( <> - {!isAuthor && !isPostHidden && rootPostUri && isReply && ( + {canHideReply && ( )} - {quoteEmbed && quoteEmbed.isOwnedByViewer && ( + {canDetachQuote && (