mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at session/schema 108 lines 2.7 kB view raw
1import React, {memo, useCallback} from 'react' 2import {StyleProp, StyleSheet, TouchableOpacity, ViewStyle} from 'react-native' 3import {RepostIcon} from 'lib/icons' 4import {s, colors} from 'lib/styles' 5import {useTheme} from 'lib/ThemeContext' 6import {Text} from '../text/Text' 7import {pluralize} from 'lib/strings/helpers' 8import {HITSLOP_10, HITSLOP_20} from 'lib/constants' 9import {useModalControls} from '#/state/modals' 10import {useRequireAuth} from '#/state/session' 11import {msg} from '@lingui/macro' 12import {useLingui} from '@lingui/react' 13 14interface Props { 15 isReposted: boolean 16 repostCount?: number 17 big?: boolean 18 onRepost: () => void 19 onQuote: () => void 20} 21 22let RepostButton = ({ 23 isReposted, 24 repostCount, 25 big, 26 onRepost, 27 onQuote, 28}: Props): React.ReactNode => { 29 const theme = useTheme() 30 const {_} = useLingui() 31 const {openModal} = useModalControls() 32 const requireAuth = useRequireAuth() 33 34 const defaultControlColor = React.useMemo( 35 () => ({ 36 color: theme.palette.default.postCtrl, 37 }), 38 [theme], 39 ) 40 41 const onPressToggleRepostWrapper = useCallback(() => { 42 openModal({ 43 name: 'repost', 44 onRepost: onRepost, 45 onQuote: onQuote, 46 isReposted, 47 }) 48 }, [onRepost, onQuote, isReposted, openModal]) 49 50 return ( 51 <TouchableOpacity 52 testID="repostBtn" 53 onPress={() => { 54 requireAuth(() => onPressToggleRepostWrapper()) 55 }} 56 style={[styles.btn, !big && styles.btnPad]} 57 accessibilityRole="button" 58 accessibilityLabel={`${ 59 isReposted 60 ? _(msg`Undo repost`) 61 : _(msg({message: 'Repost', context: 'action'})) 62 } (${repostCount} ${pluralize(repostCount || 0, 'repost')})`} 63 accessibilityHint="" 64 hitSlop={big ? HITSLOP_20 : HITSLOP_10}> 65 <RepostIcon 66 style={ 67 isReposted 68 ? (styles.reposted as StyleProp<ViewStyle>) 69 : defaultControlColor 70 } 71 strokeWidth={2.4} 72 size={big ? 24 : 20} 73 /> 74 {typeof repostCount !== 'undefined' && repostCount > 0 ? ( 75 <Text 76 testID="repostCount" 77 style={ 78 isReposted 79 ? [s.bold, s.green3, s.f15, s.ml5] 80 : [defaultControlColor, s.f15, s.ml5] 81 }> 82 {repostCount} 83 </Text> 84 ) : undefined} 85 </TouchableOpacity> 86 ) 87} 88RepostButton = memo(RepostButton) 89export {RepostButton} 90 91const styles = StyleSheet.create({ 92 btn: { 93 flexDirection: 'row', 94 alignItems: 'center', 95 }, 96 btnPad: { 97 paddingTop: 5, 98 paddingBottom: 5, 99 paddingLeft: 5, 100 paddingRight: 5, 101 }, 102 reposted: { 103 color: colors.green3, 104 }, 105 repostCount: { 106 color: 'currentColor', 107 }, 108})