import React from 'react' import { ActivityIndicator, FlatList, RefreshControl, StyleSheet, View, } from 'react-native' import {AppBskyActorDefs as ActorDefs} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useFocusEffect} from '@react-navigation/native' import {NativeStackScreenProps} from '@react-navigation/native-stack' import {usePalette} from '#/lib/hooks/usePalette' import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' import {CommonNavigatorParams} from '#/lib/routes/types' import {cleanError} from '#/lib/strings/errors' import {logger} from '#/logger' import {useMyMutedAccountsQuery} from '#/state/queries/my-muted-accounts' import {useSetMinimalShellMode} from '#/state/shell' import {ProfileCard} from '#/view/com/profile/ProfileCard' import {ErrorScreen} from '#/view/com/util/error/ErrorScreen' import {Text} from '#/view/com/util/text/Text' import {ViewHeader} from '#/view/com/util/ViewHeader' import {atoms as a} from '#/alf' import * as Layout from '#/components/Layout' type Props = NativeStackScreenProps< CommonNavigatorParams, 'ModerationMutedAccounts' > export function ModerationMutedAccounts({}: Props) { const pal = usePalette('default') const {_} = useLingui() const setMinimalShellMode = useSetMinimalShellMode() const {isTabletOrDesktop} = useWebMediaQueries() const [isPTRing, setIsPTRing] = React.useState(false) const { data, isFetching, isError, error, refetch, hasNextPage, fetchNextPage, isFetchingNextPage, } = useMyMutedAccountsQuery() const isEmpty = !isFetching && !data?.pages[0]?.mutes.length const profiles = React.useMemo(() => { if (data?.pages) { return data.pages.flatMap(page => page.mutes) } return [] }, [data]) useFocusEffect( React.useCallback(() => { setMinimalShellMode(false) }, [setMinimalShellMode]), ) const onRefresh = React.useCallback(async () => { setIsPTRing(true) try { await refetch() } catch (err) { logger.error('Failed to refresh my muted accounts', {message: err}) } setIsPTRing(false) }, [refetch, setIsPTRing]) const onEndReached = React.useCallback(async () => { if (isFetching || !hasNextPage || isError) return try { await fetchNextPage() } catch (err) { logger.error('Failed to load more of my muted accounts', {message: err}) } }, [isFetching, hasNextPage, isError, fetchNextPage]) const renderItem = ({ item, index, }: { item: ActorDefs.ProfileView index: number }) => ( ) return ( Muted accounts have their posts removed from your feed and from your notifications. Mutes are completely private. {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={ } onEndReached={onEndReached} renderItem={renderItem} initialNumToRender={15} // FIXME(dan) ListFooterComponent={() => ( {(isFetching || isFetchingNextPage) && } )} // @ts-ignore our .web version only -prf desktopFixedHeight /> )} ) } 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', }, footer: { height: 200, paddingTop: 20, }, })