diff options
Diffstat (limited to 'src/view/com/util/post-ctrls')
-rw-r--r-- | src/view/com/util/post-ctrls/PostCtrls.tsx | 10 | ||||
-rw-r--r-- | src/view/com/util/post-ctrls/RepostButton.tsx | 6 | ||||
-rw-r--r-- | src/view/com/util/post-ctrls/RepostButton.web.tsx | 58 |
3 files changed, 51 insertions, 23 deletions
diff --git a/src/view/com/util/post-ctrls/PostCtrls.tsx b/src/view/com/util/post-ctrls/PostCtrls.tsx index 120aecf45..e548c45f7 100644 --- a/src/view/com/util/post-ctrls/PostCtrls.tsx +++ b/src/view/com/util/post-ctrls/PostCtrls.tsx @@ -25,6 +25,7 @@ import { } from '#/state/queries/post' import {useComposerControls} from '#/state/shell/composer' import {Shadow} from '#/state/cache/types' +import {useRequireAuth} from '#/state/session' export function PostCtrls({ big, @@ -46,6 +47,7 @@ export function PostCtrls({ const postUnlikeMutation = usePostUnlikeMutation() const postRepostMutation = usePostRepostMutation() const postUnrepostMutation = usePostUnrepostMutation() + const requireAuth = useRequireAuth() const defaultCtrlColor = React.useMemo( () => ({ @@ -107,7 +109,9 @@ export function PostCtrls({ <TouchableOpacity testID="replyBtn" style={[styles.ctrl, !big && styles.ctrlPad, {paddingLeft: 0}]} - onPress={onPressReply} + onPress={() => { + requireAuth(() => onPressReply()) + }} accessibilityRole="button" accessibilityLabel={`Reply (${post.replyCount} ${ post.replyCount === 1 ? 'reply' : 'replies' @@ -135,7 +139,9 @@ export function PostCtrls({ <TouchableOpacity testID="likeBtn" style={[styles.ctrl, !big && styles.ctrlPad]} - onPress={onPressToggleLike} + onPress={() => { + requireAuth(() => onPressToggleLike()) + }} accessibilityRole="button" accessibilityLabel={`${post.viewer?.like ? 'Unlike' : 'Like'} (${ post.likeCount diff --git a/src/view/com/util/post-ctrls/RepostButton.tsx b/src/view/com/util/post-ctrls/RepostButton.tsx index 0a7637252..1d34a88ab 100644 --- a/src/view/com/util/post-ctrls/RepostButton.tsx +++ b/src/view/com/util/post-ctrls/RepostButton.tsx @@ -7,6 +7,7 @@ import {Text} from '../text/Text' import {pluralize} from 'lib/strings/helpers' import {HITSLOP_10, HITSLOP_20} from 'lib/constants' import {useModalControls} from '#/state/modals' +import {useRequireAuth} from '#/state/session' interface Props { isReposted: boolean @@ -25,6 +26,7 @@ export const RepostButton = ({ }: Props) => { const theme = useTheme() const {openModal} = useModalControls() + const requireAuth = useRequireAuth() const defaultControlColor = React.useMemo( () => ({ @@ -45,7 +47,9 @@ export const RepostButton = ({ return ( <TouchableOpacity testID="repostBtn" - onPress={onPressToggleRepostWrapper} + onPress={() => { + requireAuth(() => onPressToggleRepostWrapper()) + }} style={[styles.control, !big && styles.controlPad]} accessibilityRole="button" accessibilityLabel={`${ diff --git a/src/view/com/util/post-ctrls/RepostButton.web.tsx b/src/view/com/util/post-ctrls/RepostButton.web.tsx index 6c5f816aa..329382132 100644 --- a/src/view/com/util/post-ctrls/RepostButton.web.tsx +++ b/src/view/com/util/post-ctrls/RepostButton.web.tsx @@ -1,5 +1,5 @@ import React from 'react' -import {StyleProp, StyleSheet, View, ViewStyle} from 'react-native' +import {StyleProp, StyleSheet, View, ViewStyle, Pressable} from 'react-native' import {RepostIcon} from 'lib/icons' import {colors} from 'lib/styles' import {useTheme} from 'lib/ThemeContext' @@ -12,6 +12,8 @@ import { import {EventStopper} from '../EventStopper' import {useLingui} from '@lingui/react' import {msg} from '@lingui/macro' +import {useRequireAuth} from '#/state/session' +import {useSession} from '#/state/session' interface Props { isReposted: boolean @@ -31,6 +33,8 @@ export const RepostButton = ({ }: Props) => { const theme = useTheme() const {_} = useLingui() + const {hasSession} = useSession() + const requireAuth = useRequireAuth() const defaultControlColor = React.useMemo( () => ({ @@ -62,32 +66,46 @@ export const RepostButton = ({ }, ] - return ( + const inner = ( + <View + style={[ + styles.control, + !big && styles.controlPad, + (isReposted + ? styles.reposted + : defaultControlColor) as StyleProp<ViewStyle>, + ]}> + <RepostIcon strokeWidth={2.2} size={big ? 24 : 20} /> + {typeof repostCount !== 'undefined' ? ( + <Text + testID="repostCount" + type={isReposted ? 'md-bold' : 'md'} + style={styles.repostCount}> + {repostCount ?? 0} + </Text> + ) : undefined} + </View> + ) + + return hasSession ? ( <EventStopper> <NativeDropdown items={dropdownItems} accessibilityLabel={_(msg`Repost or quote post`)} accessibilityHint=""> - <View - style={[ - styles.control, - !big && styles.controlPad, - (isReposted - ? styles.reposted - : defaultControlColor) as StyleProp<ViewStyle>, - ]}> - <RepostIcon strokeWidth={2.2} size={big ? 24 : 20} /> - {typeof repostCount !== 'undefined' ? ( - <Text - testID="repostCount" - type={isReposted ? 'md-bold' : 'md'} - style={styles.repostCount}> - {repostCount ?? 0} - </Text> - ) : undefined} - </View> + {inner} </NativeDropdown> </EventStopper> + ) : ( + <Pressable + accessibilityRole="button" + onPress={() => { + requireAuth(() => {}) + }} + accessibilityLabel={_(msg`Repost or quote post`)} + accessibilityHint=""> + {inner} + </Pressable> ) } |