Merge pull request #3209 from bluesky-social/samuel/loggedout-warning-2

Add warning about sharing if post author has the !no-unauthenticated label
zio/stable
Samuel Newman 2024-03-14 18:52:47 +00:00 committed by GitHub
commit 6279c5cf31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 50 additions and 3 deletions

View File

@ -58,6 +58,11 @@ let ProfileMenu = ({
) )
const blockPromptControl = Prompt.usePromptControl() const blockPromptControl = Prompt.usePromptControl()
const loggedOutWarningPromptControl = Prompt.usePromptControl()
const showLoggedOutWarning = React.useMemo(() => {
return !!profile.labels?.find(label => label.val === '!no-unauthenticated')
}, [profile.labels])
const invalidateProfileQuery = React.useCallback(() => { const invalidateProfileQuery = React.useCallback(() => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
@ -192,7 +197,13 @@ let ProfileMenu = ({
<Menu.Item <Menu.Item
testID="profileHeaderDropdownShareBtn" testID="profileHeaderDropdownShareBtn"
label={_(msg`Share`)} label={_(msg`Share`)}
onPress={onPressShare}> onPress={() => {
if (showLoggedOutWarning) {
loggedOutWarningPromptControl.open()
} else {
onPressShare()
}
}}>
<Menu.ItemText> <Menu.ItemText>
<Trans>Share</Trans> <Trans>Share</Trans>
</Menu.ItemText> </Menu.ItemText>
@ -310,6 +321,16 @@ let ProfileMenu = ({
} }
confirmButtonColor={profile.viewer?.blocking ? undefined : 'negative'} confirmButtonColor={profile.viewer?.blocking ? undefined : 'negative'}
/> />
<Prompt.Basic
control={loggedOutWarningPromptControl}
title={_(msg`Note about sharing`)}
description={_(
msg`This profile is only visible to logged-in users. It won't be visible to people who aren't logged in.`,
)}
onConfirm={onPressShare}
confirmButtonCta={_(msg`Share anyway`)}
/>
</EventStopper> </EventStopper>
) )
} }

View File

@ -85,11 +85,13 @@ let PostDropdownBtn = ({
const {mutedWordsDialogControl} = useGlobalDialogsControlContext() const {mutedWordsDialogControl} = useGlobalDialogsControlContext()
const deletePromptControl = useDialogControl() const deletePromptControl = useDialogControl()
const hidePromptControl = useDialogControl() const hidePromptControl = useDialogControl()
const loggedOutWarningPromptControl = useDialogControl()
const rootUri = record.reply?.root?.uri || postUri const rootUri = record.reply?.root?.uri || postUri
const isThreadMuted = mutedThreads.includes(rootUri) const isThreadMuted = mutedThreads.includes(rootUri)
const isPostHidden = hiddenPosts && hiddenPosts.includes(postUri) const isPostHidden = hiddenPosts && hiddenPosts.includes(postUri)
const isAuthor = postAuthor.did === currentAccount?.did const isAuthor = postAuthor.did === currentAccount?.did
const href = React.useMemo(() => { const href = React.useMemo(() => {
const urip = new AtUri(postUri) const urip = new AtUri(postUri)
return makeProfileLink(postAuthor, 'post', urip.rkey) return makeProfileLink(postAuthor, 'post', urip.rkey)
@ -167,6 +169,17 @@ let PostDropdownBtn = ({
hidePost({uri: postUri}) hidePost({uri: postUri})
}, [postUri, hidePost]) }, [postUri, hidePost])
const shouldShowLoggedOutWarning = React.useMemo(() => {
return !!postAuthor.labels?.find(
label => label.val === '!no-unauthenticated',
)
}, [postAuthor])
const onSharePost = React.useCallback(() => {
const url = toShareUrl(href)
shareUrl(url)
}, [href])
return ( return (
<EventStopper onKeyDown={false}> <EventStopper onKeyDown={false}>
<Menu.Root> <Menu.Root>
@ -217,8 +230,11 @@ let PostDropdownBtn = ({
testID="postDropdownShareBtn" testID="postDropdownShareBtn"
label={isWeb ? _(msg`Copy link to post`) : _(msg`Share`)} label={isWeb ? _(msg`Copy link to post`) : _(msg`Share`)}
onPress={() => { onPress={() => {
const url = toShareUrl(href) if (shouldShowLoggedOutWarning) {
shareUrl(url) loggedOutWarningPromptControl.open()
} else {
onSharePost()
}
}}> }}>
<Menu.ItemText> <Menu.ItemText>
{isWeb ? _(msg`Copy link to post`) : _(msg`Share`)} {isWeb ? _(msg`Copy link to post`) : _(msg`Share`)}
@ -342,6 +358,16 @@ let PostDropdownBtn = ({
onConfirm={onHidePost} onConfirm={onHidePost}
confirmButtonCta={_(msg`Hide`)} confirmButtonCta={_(msg`Hide`)}
/> />
<Prompt.Basic
control={loggedOutWarningPromptControl}
title={_(msg`Note about sharing`)}
description={_(
msg`This post is only visible to logged-in users. It won't be visible to people who aren't logged in.`,
)}
onConfirm={onSharePost}
confirmButtonCta={_(msg`Share anyway`)}
/>
</EventStopper> </EventStopper>
) )
} }