diff --git a/src/components/moderation/BlockDialog.tsx b/src/components/moderation/BlockDialog.tsx index 22895941d..f2c19ec42 100644 --- a/src/components/moderation/BlockDialog.tsx +++ b/src/components/moderation/BlockDialog.tsx @@ -1,5 +1,6 @@ import {useState} from 'react' -import {View} from 'react-native' +import {type StyleProp, View, type ViewStyle} from 'react-native' +import {plural} from '@lingui/core/macro' import {Trans, useLingui} from '@lingui/react/macro' import {useQueryClient} from '@tanstack/react-query' @@ -14,12 +15,13 @@ import { } from '#/state/queries/messages/list-mutual-groups' import {useRemoveFromGroupChat} from '#/state/queries/messages/remove-from-group' import {useSession} from '#/state/session' -import {atoms as a, native, useTheme, web} from '#/alf' +import {atoms as a, platform, useBreakpoints, useTheme, web} from '#/alf' import {AvatarBubbles} from '#/components/AvatarBubbles' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import {type DialogControlProps} from '#/components/Dialog' import {parseConvoView} from '#/components/dms/util' +import {TimesLarge_Stroke2_Corner0_Rounded as XIcon} from '#/components/icons/Times' import {Loader} from '#/components/Loader' import * as Toast from '#/components/Toast' import {Text} from '#/components/Typography' @@ -28,6 +30,12 @@ import {type AnyProfileView} from '#/types/bsky/profile' type Item = chat.bsky.convo.defs.ConvoView +/** + * How many mutual group chats to show in the block dialog itself. The rest + * are behind a "See more" button that opens the full list. + */ +const MAX_PREVIEW_GROUP_CHATS = 3 + type BlockDialogProps = { control: DialogControlProps profile: Shadow @@ -35,6 +43,16 @@ type BlockDialogProps = { currentConvoId?: string } +/** + * Props shared by every mutual group chat row, wherever it's rendered. + */ +type MutualGroupChatRowProps = { + profileDid: string + currentConvoId?: string + onOptimisticallyRemoveConvo: (convoId: string) => void + onRestoreConvo: (convoId: string) => void +} + export function BlockDialog({ control, profile, @@ -42,17 +60,14 @@ export function BlockDialog({ currentConvoId, }: BlockDialogProps) { return ( - - - - - - + + + ) } @@ -70,9 +85,7 @@ function BlockDialogInner({ }) { const t = useTheme() const {t: l} = useLingui() - - const [headerHeight, setHeaderHeight] = useState(0) - const [footerHeight, setFooterHeight] = useState(0) + const mutualGroupChatsControl = Dialog.useDialogControl() /* * Optimistically hide convos the viewer has left or removed the profile @@ -82,19 +95,23 @@ function BlockDialogInner({ const [removedConvoIds, setRemovedConvoIds] = useState>( () => new Set(), ) - const onOptimisticallyRemoveConvo = (convoId: string) => { - setRemovedConvoIds(prev => { - const next = new Set(prev) - next.add(convoId) - return next - }) - } - const onRestoreConvo = (convoId: string) => { - setRemovedConvoIds(prev => { - const next = new Set(prev) - next.delete(convoId) - return next - }) + const rowProps: MutualGroupChatRowProps = { + profileDid: profile.did, + currentConvoId, + onOptimisticallyRemoveConvo: (convoId: string) => { + setRemovedConvoIds(prev => { + const next = new Set(prev) + next.add(convoId) + return next + }) + }, + onRestoreConvo: (convoId: string) => { + setRemovedConvoIds(prev => { + const next = new Set(prev) + next.delete(convoId) + return next + }) + }, } const {data, isLoading, hasNextPage, isFetchingNextPage, fetchNextPage} = @@ -105,7 +122,8 @@ function BlockDialogInner({ const items: Item[] = (data?.pages.flatMap(page => page.convos) ?? []).filter( item => !removedConvoIds.has(item.id), ) - const hasMutualGroupChats = items.length > 0 + const previewItems = items.slice(0, MAX_PREVIEW_GROUP_CHATS) + const hiddenCount = items.length - previewItems.length const onEndReached = async () => { if (isFetchingNextPage || !hasNextPage) return @@ -116,111 +134,224 @@ function BlockDialogInner({ } } - const renderItems = ({item}: {item: Item}) => { - return ( - + + + + {profile.viewer?.blocking ? ( + Unblock account? + ) : ( + Block account? + )} + + + {profile.viewer?.blocking ? ( + + The account will be able to interact with you after unblocking. + + ) : profile.associated?.labeler ? ( + + Blocking will not prevent labels from being applied on your + account, but it will stop this account from replying in your + threads or interacting with you. + + ) : ( + + Blocked accounts cannot reply in your threads, mention you, or + otherwise interact with you. + + )} + + + + {previewItems.length > 0 && ( + + + Mutual group chats + + + {previewItems.map((item, index) => ( + 0 && [a.border_t, t.atoms.border_contrast_low], + ]} + /> + ))} + {(hiddenCount > 0 || hasNextPage) && ( + mutualGroupChatsControl.open()} + /> + )} + + + )} + + + + + + + + + void onEndReached()} /> - ) - } + + ) +} - const listHeader = ( - setHeaderHeight(evt.nativeEvent.layout.height)}> - - - {profile.viewer?.blocking ? ( - Unblock account? - ) : ( - Block account? - )} - - - {profile.viewer?.blocking ? ( - - The account will be able to interact with you after unblocking. - - ) : profile.associated?.labeler ? ( - - Blocking will not prevent labels from being applied on your - account, but it will stop this account from replying in your - threads or interacting with you. - - ) : ( - - Blocked accounts cannot reply in your threads, mention you, or - otherwise interact with you. - - )} - - - {hasMutualGroupChats ? ( - +function SeeMoreButton({label, onPress}: {label: string; onPress: () => void}) { + const t = useTheme() + return ( + ) +} - const footer = ( - - +/** + * Every mutual group chat, opened from the block dialog when there are more + * than fit in its preview. + */ +function MutualGroupChatsDialog({ + control, + ...props +}: { + control: DialogControlProps + items: Item[] + rowProps: MutualGroupChatRowProps + isFetchingNextPage: boolean + onEndReached: () => void +}) { + return ( + + + + + ) +} + +function MutualGroupChatsList({ + items, + rowProps, + isFetchingNextPage, + onEndReached, +}: { + items: Item[] + rowProps: MutualGroupChatRowProps + isFetchingNextPage: boolean + onEndReached: () => void +}) { + const t = useTheme() + const {t: l} = useLingui() + const {gtMobile} = useBreakpoints() + const {close} = Dialog.useDialogContext() + + const listHeader = ( + + + Mutual group chats + ) - if (isLoading || !hasMutualGroupChats) { - return ( - - {listHeader} - {footer} - - ) - } - return ( ( + 0 && [a.border_t, t.atoms.border_contrast_low], + ]} + /> + )} + keyExtractor={(item: Item) => item.id} ListHeaderComponent={listHeader} - stickyHeaderIndices={[0]} + stickyHeaderIndices={web([0])} ListFooterComponent={ isFetchingNextPage ? ( @@ -228,18 +359,14 @@ function BlockDialogInner({ ) : undefined } - footer={ - setFooterHeight(evt.nativeEvent.layout.height)}> - {footer} - - } - contentContainerStyle={[a.gap_0, {paddingBottom: footerHeight}]} - scrollIndicatorInsets={{top: headerHeight, bottom: footerHeight}} - onEndReached={() => void onEndReached()} + onEndReached={onEndReached} onEndReachedThreshold={0.5} - style={[web([{height: '100vh', maxHeight: 600}])]} - webInnerStyle={[{maxWidth: 420}]} + webInnerContentContainerStyle={[a.py_0]} + webInnerStyle={[a.py_0, {maxWidth: 500, minWidth: 200}]} + style={platform({ + web: [a.px_2xl, a.pb_md], + native: [a.px_2xl, a.pt_lg], + })} /> ) } @@ -250,12 +377,10 @@ function MutualGroupChat({ currentConvoId, onOptimisticallyRemoveConvo, onRestoreConvo, -}: { + style, +}: MutualGroupChatRowProps & { view: chat.bsky.convo.defs.ConvoView - profileDid: string - currentConvoId?: string - onOptimisticallyRemoveConvo: (convoId: string) => void - onRestoreConvo: (convoId: string) => void + style?: StyleProp }) { const t = useTheme() const {t: l} = useLingui() @@ -331,14 +456,7 @@ function MutualGroupChat({ return ( + style={[a.flex_row, a.align_center, a.gap_sm, a.justify_between, style]}>