import React from 'react' import {View} from 'react-native' import { AppBskyActorDefs, AppBskyGraphDefs, AtUri, moderateUserList, ModerationUI, } from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useQueryClient} from '@tanstack/react-query' import {sanitizeHandle} from '#/lib/strings/handles' import {useModerationOpts} from '#/state/preferences/moderation-opts' import {precacheList} from '#/state/queries/feed' import {useSession} from '#/state/session' import {atoms as a, useTheme} from '#/alf' import { Avatar, Description, Header, Outer, SaveButton, } from '#/components/FeedCard' import {Link as InternalLink, LinkProps} from '#/components/Link' import * as Hider from '#/components/moderation/Hider' import {Text} from '#/components/Typography' import {ButtonProps} from './Button' /* * This component is based on `FeedCard` and is tightly coupled with that * component. Please refer to `FeedCard` for more context. */ export { Avatar, AvatarPlaceholder, Description, Header, Outer, SaveButton, TitleAndBylinePlaceholder, } from '#/components/FeedCard' const CURATELIST = 'app.bsky.graph.defs#curatelist' const MODLIST = 'app.bsky.graph.defs#modlist' type Props = { view: AppBskyGraphDefs.ListView showPinButton?: boolean } & Omit export function Default(props: Props) { const {view, showPinButton} = props const moderationOpts = useModerationOpts() const moderation = moderationOpts ? moderateUserList(view, moderationOpts) : undefined return (
{showPinButton && view.purpose === CURATELIST && ( )}
) } export function Link({ view, children, ...props }: Props & Pick) { const queryClient = useQueryClient() const href = React.useMemo(() => { return createProfileListHref({list: view}) }, [view]) React.useEffect(() => { precacheList(queryClient, view) }, [view, queryClient]) return ( {children} ) } export function TitleAndByline({ title, creator, purpose = CURATELIST, modUi, }: { title: string creator?: AppBskyActorDefs.ProfileViewBasic purpose?: AppBskyGraphDefs.ListView['purpose'] modUi?: ModerationUI }) { const t = useTheme() const {_} = useLingui() const {currentAccount} = useSession() return ( Hidden list {title} {creator && ( {purpose === MODLIST ? _(msg`Moderation list by ${sanitizeHandle(creator.handle, '@')}`) : _(msg`List by ${sanitizeHandle(creator.handle, '@')}`)} )} ) } export function createProfileListHref({ list, }: { list: AppBskyGraphDefs.ListView }) { const urip = new AtUri(list.uri) const handleOrDid = list.creator.handle || list.creator.did return `/profile/${handleOrDid}/lists/${urip.rkey}` }