Compute moderation decision, filter contentList contexts, pass into card
This commit is contained in:
+37
-10
@@ -1,6 +1,10 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {ActivityIndicator, type FlatList, StyleSheet, View} from 'react-native'
|
import {ActivityIndicator, type FlatList, StyleSheet, View} from 'react-native'
|
||||||
import {AppBskyFeedDefs} from '@atproto/api'
|
import {
|
||||||
|
AppBskyFeedDefs,
|
||||||
|
moderateFeedGenerator,
|
||||||
|
ModerationDecision,
|
||||||
|
} from '@atproto/api'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {useFocusEffect} from '@react-navigation/native'
|
import {useFocusEffect} from '@react-navigation/native'
|
||||||
@@ -38,6 +42,7 @@ import {FilterTimeline_Stroke2_Corner0_Rounded as FilterTimeline} from '#/compon
|
|||||||
import {ListMagnifyingGlass_Stroke2_Corner0_Rounded} from '#/components/icons/ListMagnifyingGlass'
|
import {ListMagnifyingGlass_Stroke2_Corner0_Rounded} from '#/components/icons/ListMagnifyingGlass'
|
||||||
import {ListSparkle_Stroke2_Corner0_Rounded} from '#/components/icons/ListSparkle'
|
import {ListSparkle_Stroke2_Corner0_Rounded} from '#/components/icons/ListSparkle'
|
||||||
import hairlineWidth = StyleSheet.hairlineWidth
|
import hairlineWidth = StyleSheet.hairlineWidth
|
||||||
|
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||||
import {Divider} from '#/components/Divider'
|
import {Divider} from '#/components/Divider'
|
||||||
import * as FeedCard from '#/components/FeedCard'
|
import * as FeedCard from '#/components/FeedCard'
|
||||||
import {ChevronRight_Stroke2_Corner0_Rounded as ChevronRight} from '#/components/icons/Chevron'
|
import {ChevronRight_Stroke2_Corner0_Rounded as ChevronRight} from '#/components/icons/Chevron'
|
||||||
@@ -89,6 +94,7 @@ type FlatlistSlice =
|
|||||||
key: string
|
key: string
|
||||||
feedUri: string
|
feedUri: string
|
||||||
feed: AppBskyFeedDefs.GeneratorView
|
feed: AppBskyFeedDefs.GeneratorView
|
||||||
|
moderation: ModerationDecision
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'popularFeedsLoadingMore'
|
type: 'popularFeedsLoadingMore'
|
||||||
@@ -101,6 +107,7 @@ type FlatlistSlice =
|
|||||||
|
|
||||||
export function FeedsScreen(_props: Props) {
|
export function FeedsScreen(_props: Props) {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
|
const moderationOpts = useModerationOpts()
|
||||||
const {openComposer} = useComposerControls()
|
const {openComposer} = useComposerControls()
|
||||||
const {isMobile, isTabletOrDesktop} = useWebMediaQueries()
|
const {isMobile, isTabletOrDesktop} = useWebMediaQueries()
|
||||||
const [query, setQuery] = React.useState('')
|
const [query, setQuery] = React.useState('')
|
||||||
@@ -300,7 +307,7 @@ export function FeedsScreen(_props: Props) {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (isUserSearching) {
|
if (isUserSearching) {
|
||||||
if (isSearchPending || !searchResults) {
|
if (isSearchPending || !searchResults || !moderationOpts) {
|
||||||
slices.push({
|
slices.push({
|
||||||
key: 'popularFeedsLoading',
|
key: 'popularFeedsLoading',
|
||||||
type: 'popularFeedsLoading',
|
type: 'popularFeedsLoading',
|
||||||
@@ -313,19 +320,30 @@ export function FeedsScreen(_props: Props) {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
slices = slices.concat(
|
slices = slices.concat(
|
||||||
searchResults.map(feed => {
|
searchResults
|
||||||
return {
|
.map(feed => {
|
||||||
|
const moderation = moderateFeedGenerator(
|
||||||
|
feed,
|
||||||
|
moderationOpts,
|
||||||
|
)
|
||||||
|
const slice: FlatlistSlice = {
|
||||||
key: `popularFeed:${feed.uri}`,
|
key: `popularFeed:${feed.uri}`,
|
||||||
type: 'popularFeed',
|
type: 'popularFeed',
|
||||||
feedUri: feed.uri,
|
feedUri: feed.uri,
|
||||||
feed,
|
feed,
|
||||||
|
moderation,
|
||||||
}
|
}
|
||||||
}),
|
return slice
|
||||||
|
})
|
||||||
|
.filter(i => !i.moderation.ui('contentList').filter),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isPopularFeedsFetching && !popularFeeds?.pages) {
|
if (
|
||||||
|
(isPopularFeedsFetching && !popularFeeds?.pages) ||
|
||||||
|
!moderationOpts
|
||||||
|
) {
|
||||||
slices.push({
|
slices.push({
|
||||||
key: 'popularFeedsLoading',
|
key: 'popularFeedsLoading',
|
||||||
type: 'popularFeedsLoading',
|
type: 'popularFeedsLoading',
|
||||||
@@ -339,14 +357,22 @@ export function FeedsScreen(_props: Props) {
|
|||||||
} else {
|
} else {
|
||||||
for (const page of popularFeeds.pages || []) {
|
for (const page of popularFeeds.pages || []) {
|
||||||
slices = slices.concat(
|
slices = slices.concat(
|
||||||
page.feeds.map(feed => {
|
page.feeds
|
||||||
return {
|
.map(feed => {
|
||||||
|
const moderation = moderateFeedGenerator(
|
||||||
|
feed,
|
||||||
|
moderationOpts,
|
||||||
|
)
|
||||||
|
const slice: FlatlistSlice = {
|
||||||
key: `popularFeed:${feed.uri}`,
|
key: `popularFeed:${feed.uri}`,
|
||||||
type: 'popularFeed',
|
type: 'popularFeed',
|
||||||
feedUri: feed.uri,
|
feedUri: feed.uri,
|
||||||
feed,
|
feed,
|
||||||
|
moderation,
|
||||||
}
|
}
|
||||||
}),
|
return slice
|
||||||
|
})
|
||||||
|
.filter(i => !i.moderation.ui('contentList').filter),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,6 +402,7 @@ export function FeedsScreen(_props: Props) {
|
|||||||
isSearchPending,
|
isSearchPending,
|
||||||
searchError,
|
searchError,
|
||||||
isUserSearching,
|
isUserSearching,
|
||||||
|
moderationOpts,
|
||||||
])
|
])
|
||||||
|
|
||||||
const renderHeaderBtn = React.useCallback(() => {
|
const renderHeaderBtn = React.useCallback(() => {
|
||||||
@@ -500,7 +527,7 @@ export function FeedsScreen(_props: Props) {
|
|||||||
} else if (item.type === 'popularFeed') {
|
} else if (item.type === 'popularFeed') {
|
||||||
return (
|
return (
|
||||||
<View style={[a.px_lg, a.pt_lg, a.gap_lg]}>
|
<View style={[a.px_lg, a.pt_lg, a.gap_lg]}>
|
||||||
<FeedCard.Default view={item.feed} />
|
<FeedCard.Default view={item.feed} moderation={item.moderation} />
|
||||||
<Divider />
|
<Divider />
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user