mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at uiwork 98 lines 2.4 kB view raw
1import React, {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' 11 12interface Props { 13 isReposted: boolean 14 repostCount?: number 15 big?: boolean 16 onRepost: () => void 17 onQuote: () => void 18} 19 20export const RepostButton = ({ 21 isReposted, 22 repostCount, 23 big, 24 onRepost, 25 onQuote, 26}: Props) => { 27 const theme = useTheme() 28 const {openModal} = useModalControls() 29 const requireAuth = useRequireAuth() 30 31 const defaultControlColor = React.useMemo( 32 () => ({ 33 color: theme.palette.default.postCtrl, 34 }), 35 [theme], 36 ) 37 38 const onPressToggleRepostWrapper = useCallback(() => { 39 openModal({ 40 name: 'repost', 41 onRepost: onRepost, 42 onQuote: onQuote, 43 isReposted, 44 }) 45 }, [onRepost, onQuote, isReposted, openModal]) 46 47 return ( 48 <TouchableOpacity 49 testID="repostBtn" 50 onPress={() => { 51 requireAuth(() => onPressToggleRepostWrapper()) 52 }} 53 style={[styles.control, !big && styles.controlPad]} 54 accessibilityRole="button" 55 accessibilityLabel={`${ 56 isReposted ? 'Undo repost' : 'Repost' 57 } (${repostCount} ${pluralize(repostCount || 0, 'repost')})`} 58 accessibilityHint="" 59 hitSlop={big ? HITSLOP_20 : HITSLOP_10}> 60 <RepostIcon 61 style={ 62 isReposted 63 ? (styles.reposted as StyleProp<ViewStyle>) 64 : defaultControlColor 65 } 66 strokeWidth={2.4} 67 size={big ? 24 : 20} 68 /> 69 {typeof repostCount !== 'undefined' ? ( 70 <Text 71 testID="repostCount" 72 style={ 73 isReposted 74 ? [s.bold, s.green3, s.f15, s.ml5] 75 : [defaultControlColor, s.f15, s.ml5] 76 }> 77 {repostCount} 78 </Text> 79 ) : undefined} 80 </TouchableOpacity> 81 ) 82} 83 84const styles = StyleSheet.create({ 85 control: { 86 flexDirection: 'row', 87 alignItems: 'center', 88 }, 89 controlPad: { 90 padding: 5, 91 }, 92 reposted: { 93 color: colors.green3, 94 }, 95 repostCount: { 96 color: 'currentColor', 97 }, 98})