import React from 'react' import {View} from 'react-native' import {AppBskyLabelerDefs} from '@atproto/api' import {msg, Plural, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {getLabelingServiceTitle} from '#/lib/moderation' import {sanitizeHandle} from '#/lib/strings/handles' import {useLabelerInfoQuery} from '#/state/queries/labeler' import {UserAvatar} from '#/view/com/util/UserAvatar' import {atoms as a, useTheme, ViewStyleProp} from '#/alf' import {Flag_Stroke2_Corner0_Rounded as Flag} from '#/components/icons/Flag' import {Link as InternalLink, LinkProps} from '#/components/Link' import {RichText} from '#/components/RichText' import {Text} from '#/components/Typography' import {ChevronRight_Stroke2_Corner0_Rounded as ChevronRight} from '../icons/Chevron' type LabelingServiceProps = { labeler: AppBskyLabelerDefs.LabelerViewDetailed } export function Outer({ children, style, }: React.PropsWithChildren) { return ( {children} ) } export function Avatar({avatar}: {avatar?: string}) { return } export function Title({value}: {value: string}) { return {value} } export function Description({value, handle}: {value?: string; handle: string}) { return value ? ( ) : ( By {sanitizeHandle(handle, '@')} ) } export function RegionalNotice() { const t = useTheme() return ( Required in your region ) } export function LikeCount({count}: {count: number}) { const t = useTheme() return ( ) } export function Content({children}: React.PropsWithChildren<{}>) { const t = useTheme() return ( {children} ) } /** * The canonical view for a labeling service. Use this or compose your own. */ export function Default({ labeler, style, }: LabelingServiceProps & ViewStyleProp) { return ( <Description value={labeler.creator.description} handle={labeler.creator.handle} /> {labeler.likeCount ? <LikeCount count={labeler.likeCount} /> : null} </Content> </Outer> ) } export function Link({ children, labeler, }: LabelingServiceProps & Pick<LinkProps, 'children'>) { const {_} = useLingui() return ( <InternalLink to={{ screen: 'Profile', params: { name: labeler.creator.handle, }, }} label={_( msg`View the labeling service provided by @${labeler.creator.handle}`, )}> {children} </InternalLink> ) } // TODO not finished yet export function DefaultSkeleton() { return ( <View> <Text>Loading</Text> </View> ) } export function Loader({ did, loading: LoadingComponent = DefaultSkeleton, error: ErrorComponent, component: Component, }: { did: string loading?: React.ComponentType<{}> error?: React.ComponentType<{error: string}> component: React.ComponentType<{ labeler: AppBskyLabelerDefs.LabelerViewDetailed }> }) { const {isLoading, data, error} = useLabelerInfoQuery({did}) return isLoading ? ( LoadingComponent ? ( <LoadingComponent /> ) : null ) : error || !data ? ( ErrorComponent ? ( <ErrorComponent error={error?.message || 'Unknown error'} /> ) : null ) : ( <Component labeler={data} /> ) }