Misc cleanup (#1925)
* Remove unused prefs * Cleanup * Remove my-follows cache * Replace moderationOpts in ProfileCard comp * Replace moderationOpts in FeedSlice * Remove preferences model
This commit is contained in:
parent
e749f2f3a5
commit
0de8d40981
12 changed files with 37 additions and 907 deletions
|
@ -1,9 +1,8 @@
|
|||
import React from 'react'
|
||||
import {View, StyleSheet, ActivityIndicator} from 'react-native'
|
||||
import {ProfileModeration} from '@atproto/api'
|
||||
import {ProfileModeration, AppBskyActorDefs} from '@atproto/api'
|
||||
import {Button} from '#/view/com/util/forms/Button'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {SuggestedActor} from 'state/models/discovery/suggested-actors'
|
||||
import {sanitizeDisplayName} from 'lib/strings/display-names'
|
||||
import {sanitizeHandle} from 'lib/strings/handles'
|
||||
import {s} from 'lib/styles'
|
||||
|
@ -21,7 +20,7 @@ import {
|
|||
import {logger} from '#/logger'
|
||||
|
||||
type Props = {
|
||||
profile: SuggestedActor
|
||||
profile: AppBskyActorDefs.ProfileViewBasic
|
||||
dataUpdatedAt: number
|
||||
moderation: ProfileModeration
|
||||
onFollowStateChange: (props: {
|
||||
|
@ -67,7 +66,7 @@ export function ProfileCard({
|
|||
onFollowStateChange,
|
||||
moderation,
|
||||
}: {
|
||||
profile: Shadow<SuggestedActor>
|
||||
profile: Shadow<AppBskyActorDefs.ProfileViewBasic>
|
||||
moderation: ProfileModeration
|
||||
onFollowStateChange: (props: {
|
||||
did: string
|
||||
|
|
|
@ -24,6 +24,7 @@ import {
|
|||
FeedParams,
|
||||
usePostFeedQuery,
|
||||
} from '#/state/queries/post-feed'
|
||||
import {useModerationOpts} from '#/state/queries/preferences'
|
||||
|
||||
const LOADING_ITEM = {_reactKey: '__loading__'}
|
||||
const EMPTY_FEED_ITEM = {_reactKey: '__empty__'}
|
||||
|
@ -71,6 +72,7 @@ export function Feed({
|
|||
const [isPTRing, setIsPTRing] = React.useState(false)
|
||||
const checkForNewRef = React.useRef<(() => void) | null>(null)
|
||||
|
||||
const moderationOpts = useModerationOpts()
|
||||
const opts = React.useMemo(() => ({enabled}), [enabled])
|
||||
const {
|
||||
data,
|
||||
|
@ -115,7 +117,7 @@ export function Feed({
|
|||
|
||||
const feedItems = React.useMemo(() => {
|
||||
let arr: any[] = []
|
||||
if (isFetched) {
|
||||
if (isFetched && moderationOpts) {
|
||||
if (isError && isEmpty) {
|
||||
arr = arr.concat([ERROR_ITEM])
|
||||
}
|
||||
|
@ -133,7 +135,7 @@ export function Feed({
|
|||
arr.push(LOADING_ITEM)
|
||||
}
|
||||
return arr
|
||||
}, [isFetched, isError, isEmpty, data])
|
||||
}, [isFetched, isError, isEmpty, data, moderationOpts])
|
||||
|
||||
// events
|
||||
// =
|
||||
|
@ -195,7 +197,14 @@ export function Feed({
|
|||
} else if (item === LOADING_ITEM) {
|
||||
return <PostFeedLoadingPlaceholder />
|
||||
}
|
||||
return <FeedSlice slice={item} dataUpdatedAt={dataUpdatedAt} />
|
||||
return (
|
||||
<FeedSlice
|
||||
slice={item}
|
||||
dataUpdatedAt={dataUpdatedAt}
|
||||
// we check for this before creating the feedItems array
|
||||
moderationOpts={moderationOpts!}
|
||||
/>
|
||||
)
|
||||
},
|
||||
[
|
||||
feed,
|
||||
|
@ -204,6 +213,7 @@ export function Feed({
|
|||
onPressTryAgain,
|
||||
onPressRetryLoadMore,
|
||||
renderEmptyState,
|
||||
moderationOpts,
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
@ -2,30 +2,28 @@ import React from 'react'
|
|||
import {StyleSheet, View} from 'react-native'
|
||||
import {observer} from 'mobx-react-lite'
|
||||
import {FeedPostSlice} from '#/state/queries/post-feed'
|
||||
import {AtUri, moderatePost} from '@atproto/api'
|
||||
import {AtUri, moderatePost, ModerationOpts} from '@atproto/api'
|
||||
import {Link} from '../util/Link'
|
||||
import {Text} from '../util/text/Text'
|
||||
import Svg, {Circle, Line} from 'react-native-svg'
|
||||
import {FeedItem} from './FeedItem'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {makeProfileLink} from 'lib/routes/links'
|
||||
import {useStores} from '#/state'
|
||||
|
||||
export const FeedSlice = observer(function FeedSliceImpl({
|
||||
slice,
|
||||
dataUpdatedAt,
|
||||
ignoreFilterFor,
|
||||
moderationOpts,
|
||||
}: {
|
||||
slice: FeedPostSlice
|
||||
dataUpdatedAt: number
|
||||
ignoreFilterFor?: string
|
||||
moderationOpts: ModerationOpts
|
||||
}) {
|
||||
const store = useStores()
|
||||
const moderations = React.useMemo(() => {
|
||||
return slice.items.map(item =>
|
||||
moderatePost(item.post, store.preferences.moderationOpts),
|
||||
)
|
||||
}, [slice, store.preferences.moderationOpts])
|
||||
return slice.items.map(item => moderatePost(item.post, moderationOpts))
|
||||
}, [slice, moderationOpts])
|
||||
|
||||
// apply moderation filter
|
||||
for (let i = 0; i < slice.items.length; i++) {
|
||||
|
|
|
@ -11,7 +11,6 @@ import {Text} from '../util/text/Text'
|
|||
import {UserAvatar} from '../util/UserAvatar'
|
||||
import {s} from 'lib/styles'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useStores} from 'state/index'
|
||||
import {FollowButton} from './FollowButton'
|
||||
import {sanitizeDisplayName} from 'lib/strings/display-names'
|
||||
import {sanitizeHandle} from 'lib/strings/handles'
|
||||
|
@ -158,19 +157,26 @@ const FollowersList = observer(function FollowersListImpl({
|
|||
}: {
|
||||
followers?: AppBskyActorDefs.ProfileView[] | undefined
|
||||
}) {
|
||||
const store = useStores()
|
||||
const pal = usePalette('default')
|
||||
if (!followers?.length) {
|
||||
const moderationOpts = useModerationOpts()
|
||||
|
||||
const followersWithMods = React.useMemo(() => {
|
||||
if (!followers || !moderationOpts) {
|
||||
return []
|
||||
}
|
||||
|
||||
return followers
|
||||
.map(f => ({
|
||||
f,
|
||||
mod: moderateProfile(f, moderationOpts),
|
||||
}))
|
||||
.filter(({mod}) => !mod.account.filter)
|
||||
}, [followers, moderationOpts])
|
||||
|
||||
if (!followersWithMods?.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
const followersWithMods = followers
|
||||
.map(f => ({
|
||||
f,
|
||||
mod: moderateProfile(f, store.preferences.moderationOpts),
|
||||
}))
|
||||
.filter(({mod}) => !mod.account.filter)
|
||||
|
||||
return (
|
||||
<View style={styles.followedBy}>
|
||||
<Text
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue