diff options
author | Hailey <me@haileyok.com> | 2024-08-20 15:43:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-20 15:43:40 -0700 |
commit | 723896a45f0fdf9612e5b6bb2a82ac7e894928ba (patch) | |
tree | 3822c9fa69da8d9ad771a2da49c69af9ca435669 /src/components/moderation/Hider.tsx | |
parent | e54298ec2c9a04aabe40ee7719962e2e33be23ec (diff) | |
download | voidsky-723896a45f0fdf9612e5b6bb2a82ac7e894928ba.tar.zst |
Add `list hidden` screen (#4958)
Co-authored-by: Hailey <me@haileyok.com> Co-authored-by: Eric Bailey <git@esb.lol>
Diffstat (limited to 'src/components/moderation/Hider.tsx')
-rw-r--r-- | src/components/moderation/Hider.tsx | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/components/moderation/Hider.tsx b/src/components/moderation/Hider.tsx new file mode 100644 index 000000000..fcb88ddd9 --- /dev/null +++ b/src/components/moderation/Hider.tsx @@ -0,0 +1,89 @@ +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 + allowOverride: boolean + } +} + +const Context = React.createContext<Context>({} as Context) + +export const useHider = () => React.useContext(Context) + +export function Outer({ + modui, + isContentVisibleInitialState, + allowOverride, + children, +}: React.PropsWithChildren<{ + isContentVisibleInitialState?: boolean + allowOverride?: boolean + modui: ModerationUI | undefined +}>) { + const control = useModerationDetailsDialogControl() + const blur = modui?.blurs[0] + const [isContentVisible, setIsContentVisible] = React.useState( + isContentVisibleInitialState || !blur, + ) + const info = useModerationCauseDescription(blur) + + const meta = { + isNoPwi: Boolean( + modui?.blurs.find( + cause => + cause.type === 'label' && + cause.labelDef.identifier === '!no-unauthenticated', + ), + ), + allowOverride: allowOverride ?? !modui?.noOverride, + } + + const showInfoDialog = () => { + control.open() + } + + const onSetContentVisible = (show: boolean) => { + if (meta.allowOverride) return + setIsContentVisible(show) + } + + const ctx = { + isContentVisible, + setIsContentVisible: onSetContentVisible, + showInfoDialog, + info, + meta, + } + + return ( + <Context.Provider value={ctx}> + {children} + <ModerationDetailsDialog control={control} modcause={blur} /> + </Context.Provider> + ) +} + +export function Content({children}: {children: React.ReactNode}) { + const ctx = useHider() + return ctx.isContentVisible ? children : null +} + +export function Mask({children}: {children: React.ReactNode}) { + const ctx = useHider() + return ctx.isContentVisible ? null : children +} |