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 sys-log 163 lines 4.3 kB view raw
1import React, {type ComponentProps} from 'react' 2import { 3 Pressable, 4 type StyleProp, 5 StyleSheet, 6 View, 7 type ViewStyle, 8} from 'react-native' 9import { 10 type AppBskyActorDefs, 11 type ModerationCause, 12 type ModerationUI, 13} from '@atproto/api' 14import {msg, Trans} from '@lingui/macro' 15import {useLingui} from '@lingui/react' 16import {useQueryClient} from '@tanstack/react-query' 17 18import {useModerationCauseDescription} from '#/lib/moderation/useModerationCauseDescription' 19import {addStyle} from '#/lib/styles' 20import {precacheProfile} from '#/state/queries/profile' 21// import {Link} from '#/components/Link' TODO this imposes some styles that screw things up 22import {Link} from '#/view/com/util/Link' 23import {atoms as a, useTheme} from '#/alf' 24import { 25 ModerationDetailsDialog, 26 useModerationDetailsDialogControl, 27} from '#/components/moderation/ModerationDetailsDialog' 28import {Text} from '#/components/Typography' 29 30interface Props extends ComponentProps<typeof Link> { 31 disabled: boolean 32 iconSize: number 33 iconStyles: StyleProp<ViewStyle> 34 modui: ModerationUI 35 profile: AppBskyActorDefs.ProfileViewBasic 36 interpretFilterAsBlur?: boolean 37} 38 39export function PostHider({ 40 testID, 41 href, 42 disabled, 43 modui, 44 style, 45 children, 46 iconSize, 47 iconStyles, 48 profile, 49 interpretFilterAsBlur, 50 ...props 51}: Props) { 52 const queryClient = useQueryClient() 53 const t = useTheme() 54 const {_} = useLingui() 55 const [override, setOverride] = React.useState(false) 56 const control = useModerationDetailsDialogControl() 57 const blur = 58 modui.blurs[0] || 59 (interpretFilterAsBlur ? getBlurrableFilter(modui) : undefined) 60 const desc = useModerationCauseDescription(blur) 61 62 const onBeforePress = React.useCallback(() => { 63 precacheProfile(queryClient, profile) 64 }, [queryClient, profile]) 65 66 if (!blur || (disabled && !modui.noOverride)) { 67 return ( 68 <Link 69 testID={testID} 70 style={style} 71 href={href} 72 accessible={false} 73 onBeforePress={onBeforePress} 74 {...props}> 75 {children} 76 </Link> 77 ) 78 } 79 80 return !override ? ( 81 <Pressable 82 onPress={() => { 83 if (!modui.noOverride) { 84 setOverride(v => !v) 85 } 86 }} 87 accessibilityRole="button" 88 accessibilityHint={ 89 override ? _(msg`Hides the content`) : _(msg`Shows the content`) 90 } 91 accessibilityLabel="" 92 style={[ 93 a.flex_row, 94 a.align_center, 95 a.gap_sm, 96 a.py_md, 97 { 98 paddingLeft: 6, 99 paddingRight: 18, 100 }, 101 override ? {paddingBottom: 0} : undefined, 102 t.atoms.bg, 103 ]}> 104 <ModerationDetailsDialog control={control} modcause={blur} /> 105 <Pressable 106 onPress={() => { 107 control.open() 108 }} 109 accessibilityRole="button" 110 accessibilityLabel={_(msg`Learn more about this warning`)} 111 accessibilityHint=""> 112 <View 113 style={[ 114 t.atoms.bg_contrast_25, 115 a.align_center, 116 a.justify_center, 117 { 118 width: iconSize, 119 height: iconSize, 120 borderRadius: iconSize, 121 }, 122 iconStyles, 123 ]}> 124 <desc.icon size="sm" fill={t.atoms.text_contrast_medium.color} /> 125 </View> 126 </Pressable> 127 <Text 128 style={[t.atoms.text_contrast_medium, a.flex_1, a.leading_snug]} 129 numberOfLines={1}> 130 {desc.name} 131 </Text> 132 {!modui.noOverride && ( 133 <Text style={[{color: t.palette.primary_500}]}> 134 {override ? <Trans>Hide</Trans> : <Trans>Show</Trans>} 135 </Text> 136 )} 137 </Pressable> 138 ) : ( 139 <Link 140 testID={testID} 141 style={addStyle(style, styles.child)} 142 href={href} 143 accessible={false} 144 {...props}> 145 {children} 146 </Link> 147 ) 148} 149 150function getBlurrableFilter(modui: ModerationUI): ModerationCause | undefined { 151 // moderation causes get "downgraded" when they originate from embedded content 152 // a downgraded cause should *only* drive filtering in feeds, so we want to look 153 // for filters that arent downgraded 154 return modui.filters.find(filter => !filter.downgraded) 155} 156 157const styles = StyleSheet.create({ 158 child: { 159 borderWidth: 0, 160 borderTopWidth: 0, 161 borderRadius: 8, 162 }, 163})