Improve feedback and handle errors in dropdown
This commit is contained in:
@@ -269,29 +269,61 @@ let PostDropdownBtn = ({
|
|||||||
[navigation, postUri],
|
[navigation, postUri],
|
||||||
)
|
)
|
||||||
|
|
||||||
const onToggleReplyVisibility = React.useCallback(() => {
|
const onToggleReplyVisibility = React.useCallback(async () => {
|
||||||
if (!rootPostUri) return
|
if (!rootPostUri) return
|
||||||
|
|
||||||
// TODO handle failure
|
const action = isReplyHiddenByThreadgate ? 'show' : 'hide'
|
||||||
toggleReplyVisibility({
|
const isHide = action === 'hide'
|
||||||
postUri: rootPostUri,
|
|
||||||
replyUri: postUri,
|
|
||||||
action: isReplyHiddenByThreadgate ? 'show' : 'hide',
|
|
||||||
})
|
|
||||||
}, [isReplyHiddenByThreadgate, rootPostUri, postUri, toggleReplyVisibility])
|
|
||||||
|
|
||||||
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
|
if (!quoteEmbed) return
|
||||||
|
|
||||||
// TODO handle failure
|
const action = quoteEmbed.isDetached ? 'reattach' : 'detach'
|
||||||
toggleQuoteDetachment({
|
const isDetach = action === 'detach'
|
||||||
post,
|
|
||||||
quoteUri: quoteEmbed.uri,
|
try {
|
||||||
action: quoteEmbed.isDetached ? 'reattach' : 'detach',
|
await toggleQuoteDetachment({
|
||||||
})
|
post,
|
||||||
}, [quoteEmbed, post, toggleQuoteDetachment])
|
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 canEmbed = isWeb && gtMobile && !hideInPWI
|
||||||
|
const canHideReply = !isAuthor && !isPostHidden && rootPostUri && isReply
|
||||||
|
const canDetachQuote = quoteEmbed && quoteEmbed.isOwnedByViewer
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EventStopper onKeyDown={false}>
|
<EventStopper onKeyDown={false}>
|
||||||
@@ -446,11 +478,11 @@ let PostDropdownBtn = ({
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{hasSession && (
|
{hasSession && (canHideReply || canDetachQuote) && (
|
||||||
<>
|
<>
|
||||||
<Menu.Divider />
|
<Menu.Divider />
|
||||||
<Menu.Group>
|
<Menu.Group>
|
||||||
{!isAuthor && !isPostHidden && rootPostUri && isReply && (
|
{canHideReply && (
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
testID="postDropdownHideBtn"
|
testID="postDropdownHideBtn"
|
||||||
label={
|
label={
|
||||||
@@ -471,7 +503,7 @@ let PostDropdownBtn = ({
|
|||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{quoteEmbed && quoteEmbed.isOwnedByViewer && (
|
{canDetachQuote && (
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
disabled={isPending}
|
disabled={isPending}
|
||||||
testID="postDropdownHideBtn"
|
testID="postDropdownHideBtn"
|
||||||
|
|||||||
Reference in New Issue
Block a user