Move labelers query on Mod screen

This commit is contained in:
Eric Bailey
2024-03-11 10:33:02 -05:00
parent 2e60680296
commit 02f949781a
+46 -35
View File
@@ -4,7 +4,7 @@ import {useFocusEffect} from '@react-navigation/native'
import {ComAtprotoLabelDefs} from '@atproto/api' import {ComAtprotoLabelDefs} from '@atproto/api'
import {Trans, msg} from '@lingui/macro' import {Trans, msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {AppBskyLabelerDefs, LABELS} from '@atproto/api' import {LABELS} from '@atproto/api'
import {useSafeAreaFrame} from 'react-native-safe-area-context' import {useSafeAreaFrame} from 'react-native-safe-area-context'
import {NativeStackScreenProps, CommonNavigatorParams} from '#/lib/routes/types' import {NativeStackScreenProps, CommonNavigatorParams} from '#/lib/routes/types'
@@ -86,16 +86,11 @@ export function ModerationScreen(
error: preferencesError, error: preferencesError,
data: preferences, data: preferences,
} = usePreferencesQuery() } = usePreferencesQuery()
const {
isLoading: isLabelersLoading,
data: labelers,
error: labelersError,
} = useMyLabelers()
const {gtMobile} = useBreakpoints() const {gtMobile} = useBreakpoints()
const {height} = useSafeAreaFrame() const {height} = useSafeAreaFrame()
const isLoading = isPreferencesLoading || isLabelersLoading const isLoading = isPreferencesLoading
const error = preferencesError || labelersError const error = preferencesError
return ( return (
<CenteredView <CenteredView
@@ -120,7 +115,7 @@ export function ModerationScreen(
} }
/> />
) : ( ) : (
<ModerationScreenInner preferences={preferences} labelers={labelers} /> <ModerationScreenInner preferences={preferences} />
)} )}
</CenteredView> </CenteredView>
) )
@@ -128,10 +123,8 @@ export function ModerationScreen(
export function ModerationScreenInner({ export function ModerationScreenInner({
preferences, preferences,
labelers = [],
}: { }: {
preferences: UsePreferencesQueryResponse preferences: UsePreferencesQueryResponse
labelers?: AppBskyLabelerDefs.LabelerViewDetailed[]
}) { }) {
const {_} = useLingui() const {_} = useLingui()
const t = useTheme() const t = useTheme()
@@ -140,6 +133,11 @@ export function ModerationScreenInner({
const {gtMobile} = useBreakpoints() const {gtMobile} = useBreakpoints()
const {mutedWordsDialogControl} = useGlobalDialogsControlContext() const {mutedWordsDialogControl} = useGlobalDialogsControlContext()
const {openModal} = useModalControls() const {openModal} = useModalControls()
const {
isLoading: isLabelersLoading,
data: labelers,
error: labelersError,
} = useMyLabelers()
useFocusEffect( useFocusEffect(
React.useCallback(() => { React.useCallback(() => {
@@ -381,30 +379,43 @@ export function ModerationScreenInner({
]}> ]}>
<Trans>Advanced</Trans> <Trans>Advanced</Trans>
</Text> </Text>
<View style={[a.rounded_sm, t.atoms.bg_contrast_25]}>
{labelers.map((mod, i) => { {isLabelersLoading ? (
return ( <Loader />
<React.Fragment key={mod.creator.did}> ) : labelersError || !labelers ? (
{i !== 0 && <Divider />} <View style={[a.p_lg, a.rounded_sm, t.atoms.bg_contrast_25]}>
<ModerationServiceCard.Link labeler={mod}> <Text>
<ModerationServiceCard.Card.Outer> <Trans>
<ModerationServiceCard.Card.Avatar We were unable to load your configured labelers at this time.
avatar={mod.creator.avatar} </Trans>
/> </Text>
<ModerationServiceCard.Card.Content </View>
title={getModerationServiceTitle({ ) : (
displayName: mod.creator.displayName, <View style={[a.rounded_sm, t.atoms.bg_contrast_25]}>
handle: mod.creator.handle, {labelers.map((mod, i) => {
})} return (
handle={mod.creator.handle} <React.Fragment key={mod.creator.did}>
description={mod.creator.description || ''} {i !== 0 && <Divider />}
/> <ModerationServiceCard.Link labeler={mod}>
</ModerationServiceCard.Card.Outer> <ModerationServiceCard.Card.Outer>
</ModerationServiceCard.Link> <ModerationServiceCard.Card.Avatar
</React.Fragment> avatar={mod.creator.avatar}
) />
})} <ModerationServiceCard.Card.Content
</View> title={getModerationServiceTitle({
displayName: mod.creator.displayName,
handle: mod.creator.handle,
})}
handle={mod.creator.handle}
description={mod.creator.description || ''}
/>
</ModerationServiceCard.Card.Outer>
</ModerationServiceCard.Link>
</React.Fragment>
)
})}
</View>
)}
<Text <Text
style={[ style={[