mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {memo} from 'react' 2import {View} from 'react-native' 3import {msg, Plural, Trans} from '@lingui/macro' 4import {useLingui} from '@lingui/react' 5 6import { 7 type PostThreadParams, 8 type ThreadItem, 9} from '#/state/queries/usePostThread' 10import { 11 LINEAR_AVI_WIDTH, 12 REPLY_LINE_WIDTH, 13 TREE_AVI_WIDTH, 14 TREE_INDENT, 15} from '#/screens/PostThread/const' 16import {atoms as a, useTheme} from '#/alf' 17import {CirclePlus_Stroke2_Corner0_Rounded as CirclePlus} from '#/components/icons/CirclePlus' 18import {Link} from '#/components/Link' 19import {Text} from '#/components/Typography' 20 21export const ThreadItemReadMore = memo(function ThreadItemReadMore({ 22 item, 23 view, 24}: { 25 item: Extract<ThreadItem, {type: 'readMore'}> 26 view: PostThreadParams['view'] 27}) { 28 const t = useTheme() 29 const {_} = useLingui() 30 const isTreeView = view === 'tree' 31 const indent = Math.max(0, item.depth - 1) 32 33 const spacers = isTreeView 34 ? Array.from(Array(indent)).map((_, n: number) => { 35 const isSkipped = item.skippedIndentIndices.has(n) 36 return ( 37 <View 38 key={`${item.key}-padding-${n}`} 39 style={[ 40 t.atoms.border_contrast_low, 41 { 42 borderRightWidth: isSkipped ? 0 : REPLY_LINE_WIDTH, 43 width: TREE_INDENT + TREE_AVI_WIDTH / 2, 44 left: 1, 45 }, 46 ]} 47 /> 48 ) 49 }) 50 : null 51 52 return ( 53 <View style={[a.flex_row]}> 54 {spacers} 55 <View 56 style={[ 57 t.atoms.border_contrast_low, 58 { 59 marginLeft: isTreeView 60 ? TREE_INDENT + TREE_AVI_WIDTH / 2 - 1 61 : (LINEAR_AVI_WIDTH - REPLY_LINE_WIDTH) / 2 + 16, 62 borderLeftWidth: 2, 63 borderBottomWidth: 2, 64 borderBottomLeftRadius: a.rounded_sm.borderRadius, 65 height: 18, // magic, Link below is 38px tall 66 width: isTreeView ? TREE_INDENT : LINEAR_AVI_WIDTH / 2 + 10, 67 }, 68 ]} 69 /> 70 <Link 71 label={_(msg`Read more replies`)} 72 to={item.href} 73 style={[a.pt_sm, a.pb_md, a.gap_xs]}> 74 {({hovered, pressed}) => { 75 const interacted = hovered || pressed 76 return ( 77 <> 78 <CirclePlus 79 fill={ 80 interacted 81 ? t.atoms.text_contrast_high.color 82 : t.atoms.text_contrast_low.color 83 } 84 width={18} 85 /> 86 <Text 87 style={[ 88 a.text_sm, 89 t.atoms.text_contrast_medium, 90 interacted && a.underline, 91 ]}> 92 <Trans> 93 Read{' '} 94 <Plural 95 one="# more reply" 96 other="# more replies" 97 value={item.moreReplies} 98 /> 99 </Trans> 100 </Text> 101 </> 102 ) 103 }} 104 </Link> 105 </View> 106 ) 107})