From 69f656f28300a6a33526020725c61cac78501cb0 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 25 Apr 2025 00:36:39 +0300 Subject: cleanup mod screens (#8199) --- src/view/screens/ModerationBlockedAccounts.tsx | 186 ++++++++++++------------- src/view/screens/ModerationMutedAccounts.tsx | 182 +++++++++++------------- 2 files changed, 170 insertions(+), 198 deletions(-) (limited to 'src') diff --git a/src/view/screens/ModerationBlockedAccounts.tsx b/src/view/screens/ModerationBlockedAccounts.tsx index cefa29f6c..bb94f8083 100644 --- a/src/view/screens/ModerationBlockedAccounts.tsx +++ b/src/view/screens/ModerationBlockedAccounts.tsx @@ -1,19 +1,10 @@ -import React from 'react' -import { - ActivityIndicator, - FlatList, - RefreshControl, - StyleSheet, - View, -} from 'react-native' +import {useCallback, useMemo, useState} from 'react' +import {type StyleProp, View, type ViewStyle} from 'react-native' import {type AppBskyActorDefs as ActorDefs} from '@atproto/api' -import {msg, Trans} from '@lingui/macro' -import {useLingui} from '@lingui/react' +import {Trans} from '@lingui/macro' import {useFocusEffect} from '@react-navigation/native' import {type NativeStackScreenProps} from '@react-navigation/native-stack' -import {usePalette} from '#/lib/hooks/usePalette' -import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' import {type CommonNavigatorParams} from '#/lib/routes/types' import {cleanError} from '#/lib/strings/errors' import {logger} from '#/logger' @@ -21,11 +12,12 @@ import {useModerationOpts} from '#/state/preferences/moderation-opts' import {useMyBlockedAccountsQuery} from '#/state/queries/my-blocked-accounts' import {useSetMinimalShellMode} from '#/state/shell' import {ErrorScreen} from '#/view/com/util/error/ErrorScreen' -import {Text} from '#/view/com/util/text/Text' -import {ViewHeader} from '#/view/com/util/ViewHeader' +import {List} from '#/view/com/util/List' import {atoms as a, useTheme} from '#/alf' import * as Layout from '#/components/Layout' +import {ListFooter} from '#/components/Lists' import * as ProfileCard from '#/components/ProfileCard' +import {Text} from '#/components/Typography' type Props = NativeStackScreenProps< CommonNavigatorParams, @@ -33,13 +25,10 @@ type Props = NativeStackScreenProps< > export function ModerationBlockedAccounts({}: Props) { const t = useTheme() - const pal = usePalette('default') - const {_} = useLingui() const setMinimalShellMode = useSetMinimalShellMode() - const {isTabletOrDesktop} = useWebMediaQueries() const moderationOpts = useModerationOpts() - const [isPTRing, setIsPTRing] = React.useState(false) + const [isPTRing, setIsPTRing] = useState(false) const { data, isFetching, @@ -51,7 +40,7 @@ export function ModerationBlockedAccounts({}: Props) { isFetchingNextPage, } = useMyBlockedAccountsQuery() const isEmpty = !isFetching && !data?.pages[0]?.blocks.length - const profiles = React.useMemo(() => { + const profiles = useMemo(() => { if (data?.pages) { return data.pages.flatMap(page => page.blocks) } @@ -59,12 +48,12 @@ export function ModerationBlockedAccounts({}: Props) { }, [data]) useFocusEffect( - React.useCallback(() => { + useCallback(() => { setMinimalShellMode(false) }, [setMinimalShellMode]), ) - const onRefresh = React.useCallback(async () => { + const onRefresh = useCallback(async () => { setIsPTRing(true) try { await refetch() @@ -74,7 +63,7 @@ export function ModerationBlockedAccounts({}: Props) { setIsPTRing(false) }, [refetch, setIsPTRing]) - const onEndReached = React.useCallback(async () => { + const onEndReached = useCallback(async () => { if (isFetching || !hasNextPage || isError) return try { @@ -104,28 +93,22 @@ export function ModerationBlockedAccounts({}: Props) { ) } + return ( - - - - - Blocked accounts cannot reply in your threads, mention you, or - otherwise interact with you. You will not see their content and they - will be prevented from seeing yours. - - + + + + + + Blocked Accounts + + + + {isEmpty ? ( - + + {isError ? ( ) : ( - - - - You have not blocked any accounts yet. To block an account, - go to their profile and select "Block account" from the menu - on their account. - - - + )} ) : ( - item.did} - refreshControl={ - - } + refreshing={isPTRing} + onRefresh={onRefresh} onEndReached={onEndReached} renderItem={renderItem} initialNumToRender={15} // FIXME(dan) - ListFooterComponent={() => ( - - {(isFetching || isFetchingNextPage) && } - - )} - // @ts-ignore our .web version only -prf - desktopFixedHeight + ListHeaderComponent={Info} + ListFooterComponent={ + + } /> )} @@ -176,37 +146,53 @@ export function ModerationBlockedAccounts({}: Props) { ) } -const styles = StyleSheet.create({ - title: { - textAlign: 'center', - marginTop: 12, - marginBottom: 12, - }, - description: { - textAlign: 'center', - paddingHorizontal: 30, - marginBottom: 14, - }, - descriptionDesktop: { - marginTop: 14, - }, - - flex1: { - flex: 1, - }, - empty: { - paddingHorizontal: 20, - paddingVertical: 20, - borderRadius: 16, - marginHorizontal: 24, - marginTop: 10, - }, - emptyText: { - textAlign: 'center', - }, +function Empty() { + const t = useTheme() + return ( + + + + + You have not blocked any accounts yet. To block an account, go to + their profile and select "Block account" from the menu on their + account. + + + + + ) +} - footer: { - height: 200, - paddingTop: 20, - }, -}) +function Info({style}: {style?: StyleProp}) { + const t = useTheme() + return ( + + + + Blocked accounts cannot reply in your threads, mention you, or + otherwise interact with you. You will not see their content and they + will be prevented from seeing yours. + + + + ) +} diff --git a/src/view/screens/ModerationMutedAccounts.tsx b/src/view/screens/ModerationMutedAccounts.tsx index f49337b7c..11d787ca1 100644 --- a/src/view/screens/ModerationMutedAccounts.tsx +++ b/src/view/screens/ModerationMutedAccounts.tsx @@ -1,19 +1,11 @@ -import React from 'react' -import { - ActivityIndicator, - FlatList, - RefreshControl, - StyleSheet, - View, -} from 'react-native' +import {useCallback, useMemo, useState} from 'react' +import {type StyleProp, View, type ViewStyle} from 'react-native' import {type AppBskyActorDefs as ActorDefs} from '@atproto/api' -import {msg, Trans} from '@lingui/macro' +import {Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useFocusEffect} from '@react-navigation/native' import {type NativeStackScreenProps} from '@react-navigation/native-stack' -import {usePalette} from '#/lib/hooks/usePalette' -import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' import {type CommonNavigatorParams} from '#/lib/routes/types' import {cleanError} from '#/lib/strings/errors' import {logger} from '#/logger' @@ -21,11 +13,12 @@ import {useModerationOpts} from '#/state/preferences/moderation-opts' import {useMyMutedAccountsQuery} from '#/state/queries/my-muted-accounts' import {useSetMinimalShellMode} from '#/state/shell' import {ErrorScreen} from '#/view/com/util/error/ErrorScreen' -import {Text} from '#/view/com/util/text/Text' -import {ViewHeader} from '#/view/com/util/ViewHeader' +import {List} from '#/view/com/util/List' import {atoms as a, useTheme} from '#/alf' import * as Layout from '#/components/Layout' +import {ListFooter} from '#/components/Lists' import * as ProfileCard from '#/components/ProfileCard' +import {Text} from '#/components/Typography' type Props = NativeStackScreenProps< CommonNavigatorParams, @@ -33,13 +26,11 @@ type Props = NativeStackScreenProps< > export function ModerationMutedAccounts({}: Props) { const t = useTheme() - const pal = usePalette('default') + const moderationOpts = useModerationOpts() const {_} = useLingui() const setMinimalShellMode = useSetMinimalShellMode() - const {isTabletOrDesktop} = useWebMediaQueries() - const moderationOpts = useModerationOpts() - const [isPTRing, setIsPTRing] = React.useState(false) + const [isPTRing, setIsPTRing] = useState(false) const { data, isFetching, @@ -51,7 +42,7 @@ export function ModerationMutedAccounts({}: Props) { isFetchingNextPage, } = useMyMutedAccountsQuery() const isEmpty = !isFetching && !data?.pages[0]?.mutes.length - const profiles = React.useMemo(() => { + const profiles = useMemo(() => { if (data?.pages) { return data.pages.flatMap(page => page.mutes) } @@ -59,12 +50,12 @@ export function ModerationMutedAccounts({}: Props) { }, [data]) useFocusEffect( - React.useCallback(() => { + useCallback(() => { setMinimalShellMode(false) }, [setMinimalShellMode]), ) - const onRefresh = React.useCallback(async () => { + const onRefresh = useCallback(async () => { setIsPTRing(true) try { await refetch() @@ -74,7 +65,7 @@ export function ModerationMutedAccounts({}: Props) { setIsPTRing(false) }, [refetch, setIsPTRing]) - const onEndReached = React.useCallback(async () => { + const onEndReached = useCallback(async () => { if (isFetching || !hasNextPage || isError) return try { @@ -120,25 +111,19 @@ export function ModerationMutedAccounts({}: Props) { } return ( - - - - - Muted accounts have their posts removed from your feed and from your - notifications. Mutes are completely private. - - + + + + + Muted Accounts + + + + + {isEmpty ? ( - + + {isError ? ( ) : ( - - - - You have not muted any accounts yet. To mute an account, go - to their profile and select "Mute account" from the menu on - their account. - - - + )} ) : ( - item.did} - refreshControl={ - - } + refreshing={isPTRing} + onRefresh={onRefresh} onEndReached={onEndReached} renderItem={renderItem} initialNumToRender={15} // FIXME(dan) - ListFooterComponent={() => ( - - {(isFetching || isFetchingNextPage) && } - - )} - // @ts-ignore our .web version only -prf - desktopFixedHeight + ListHeaderComponent={Info} + ListFooterComponent={ + + } /> )} @@ -189,37 +161,51 @@ export function ModerationMutedAccounts({}: Props) { ) } -const styles = StyleSheet.create({ - title: { - textAlign: 'center', - marginTop: 12, - marginBottom: 12, - }, - description: { - textAlign: 'center', - paddingHorizontal: 30, - marginBottom: 14, - }, - descriptionDesktop: { - marginTop: 14, - }, - - flex1: { - flex: 1, - }, - empty: { - paddingHorizontal: 20, - paddingVertical: 20, - borderRadius: 16, - marginHorizontal: 24, - marginTop: 10, - }, - emptyText: { - textAlign: 'center', - }, +function Empty() { + const t = useTheme() + return ( + + + + + You have not muted any accounts yet. To mute an account, go to their + profile and select "Mute account" from the menu on their account. + + + + + ) +} - footer: { - height: 200, - paddingTop: 20, - }, -}) +function Info({style}: {style?: StyleProp}) { + const t = useTheme() + return ( + + + + Muted accounts have their posts removed from your feed and from your + notifications. Mutes are completely private. + + + + ) +} -- cgit 1.4.1