From f3ade055e9ea98e99a8e343e163bb6a12c4b90f5 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 20 Aug 2024 08:52:42 -0500 Subject: [PATCH] Add Hider component --- src/components/moderation/Hider.tsx | 108 ++++++++++++++++++ src/view/screens/ProfileList.tsx | 166 ++++++++++++++-------------- 2 files changed, 194 insertions(+), 80 deletions(-) create mode 100644 src/components/moderation/Hider.tsx diff --git a/src/components/moderation/Hider.tsx b/src/components/moderation/Hider.tsx new file mode 100644 index 0000000000..caf76d51c6 --- /dev/null +++ b/src/components/moderation/Hider.tsx @@ -0,0 +1,108 @@ +import React from 'react' +import {ModerationUI} from '@atproto/api' + +import { + ModerationCauseDescription, + useModerationCauseDescription, +} from '#/lib/moderation/useModerationCauseDescription' +import { + ModerationDetailsDialog, + useModerationDetailsDialogControl, +} from '#/components/moderation/ModerationDetailsDialog' + +type Context = { + isContentVisible: boolean + setIsContentVisible: (show: boolean) => void + info: ModerationCauseDescription + showInfoDialog: () => void + meta: { + isNoPwi: boolean + noOverride: boolean + } +} + +const Context = React.createContext({ + isContentVisible: false, + setIsContentVisible: () => {}, + // @ts-ignore + info: {}, + showInfoDialog: () => {}, + meta: { + isNoPwi: false, + noOverride: false, + }, +}) + +export function Outer({ + modui, + children, +}: React.PropsWithChildren<{ + modui: ModerationUI +}>) { + const control = useModerationDetailsDialogControl() + const blur = modui.blurs[0] + const [isContentVisible, setIsContentVisible] = React.useState(!blur) + const info = useModerationCauseDescription(blur) + + const meta = React.useMemo( + () => ({ + isNoPwi: !!modui.blurs.find( + cause => + cause.type === 'label' && + cause.labelDef.identifier === '!no-unauthenticated', + ), + noOverride: modui.noOverride, + }), + [modui], + ) + + const showInfoDialog = React.useCallback(() => { + control.open() + }, [control]) + + const onSetContentVisible = React.useCallback( + (show: boolean) => { + if (meta.noOverride) return + setIsContentVisible(show) + }, + [setIsContentVisible, meta], + ) + + const ctx = React.useMemo( + () => ({ + isContentVisible, + setIsContentVisible: onSetContentVisible, + showInfoDialog, + info, + meta, + }), + [isContentVisible, onSetContentVisible, info, meta, showInfoDialog], + ) + + return ( + + {children} + + + ) +} + +export function Content({ + children, +}: { + children: (context: Context) => React.ReactNode +}) { + const ctx = React.useContext(Context) + const child = React.useMemo(() => children(ctx), [ctx, children]) + return ctx.isContentVisible ? child : null +} + +export function Mask({ + children, +}: { + children: (context: Context) => React.ReactNode +}) { + const ctx = React.useContext(Context) + const child = React.useMemo(() => children(ctx), [ctx, children]) + return !ctx.isContentVisible ? child : null +} diff --git a/src/view/screens/ProfileList.tsx b/src/view/screens/ProfileList.tsx index c3a59095ae..3b3d2ec5c6 100644 --- a/src/view/screens/ProfileList.tsx +++ b/src/view/screens/ProfileList.tsx @@ -71,7 +71,7 @@ import {CenteredView} from 'view/com/util/Views' import {ListHiddenScreen} from '#/screens/List/ListHiddenScreen' import {atoms as a, useTheme} from '#/alf' import {useDialogControl} from '#/components/Dialog' -import {ScreenHider} from '#/components/moderation/ScreenHider' +import * as Hider from '#/components/moderation/Hider' import * as Prompt from '#/components/Prompt' import {ReportDialog, useReportDialogControl} from '#/components/ReportDialog' import {RichText} from '#/components/RichText' @@ -189,92 +189,98 @@ function ProfileListScreenLoaded({ return
}, [rkey, list, preferences]) - if (isHidden) { - return - } - if (isCurateList) { return ( - - - - {({headerHeight, scrollElRef, isFocused}) => ( - + + {() => } + + + {() => ( + + + {({headerHeight, scrollElRef, isFocused}) => ( + + )} + {({headerHeight, scrollElRef}) => ( + + )} + + openComposer({})} + icon={ + + } + accessibilityRole="button" + accessibilityLabel={_(msg`New post`)} + accessibilityHint="" /> - )} - {({headerHeight, scrollElRef}) => ( - - )} - - openComposer({})} - icon={ - - } - accessibilityRole="button" - accessibilityLabel={_(msg`New post`)} - accessibilityHint="" - /> - - + + )} + + ) } return ( - - - - {({headerHeight, scrollElRef}) => ( - + + {() => } + + + {() => ( + + + {({headerHeight, scrollElRef}) => ( + + )} + + openComposer({})} + icon={ + + } + accessibilityRole="button" + accessibilityLabel={_(msg`New post`)} + accessibilityHint="" /> - )} - - openComposer({})} - icon={ - - } - accessibilityRole="button" - accessibilityLabel={_(msg`New post`)} - accessibilityHint="" - /> - - + + )} + + ) }