import React from 'react' import {View} from 'react-native' import {Image} from 'expo-image' import {AppBskyGraphStarterpack, AtUri} from '@atproto/api' import {msg, Plural, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useQueryClient} from '@tanstack/react-query' import {sanitizeHandle} from '#/lib/strings/handles' import {getStarterPackOgCard} from '#/lib/strings/starter-pack' import {precacheResolvedUri} from '#/state/queries/resolve-uri' import {precacheStarterPack} from '#/state/queries/starter-packs' import {useSession} from '#/state/session' import {atoms as a, useTheme} from '#/alf' import {StarterPack as StarterPackIcon} from '#/components/icons/StarterPack' import { Link as BaseLink, type LinkProps as BaseLinkProps, } from '#/components/Link' import {Text} from '#/components/Typography' import * as bsky from '#/types/bsky' export function Default({ starterPack, }: { starterPack?: bsky.starterPack.AnyStarterPackView }) { if (!starterPack) return null return ( ) } export function Notification({ starterPack, }: { starterPack?: bsky.starterPack.AnyStarterPackView }) { if (!starterPack) return null return ( ) } export function Card({ starterPack, noIcon, noDescription, }: { starterPack: bsky.starterPack.AnyStarterPackView noIcon?: boolean noDescription?: boolean }) { const {record, creator, joinedAllTimeCount} = starterPack const {_} = useLingui() const t = useTheme() const {currentAccount} = useSession() if ( !bsky.dangerousIsType( record, AppBskyGraphStarterpack.isRecord, ) ) { return null } return ( {!noIcon ? : null} {record.name} {creator?.did === currentAccount?.did ? _(msg`Starter pack by you`) : _(msg`Starter pack by ${sanitizeHandle(creator.handle, '@')}`)} {!noDescription && record.description ? ( {record.description} ) : null} {!!joinedAllTimeCount && joinedAllTimeCount >= 50 && ( joined! )} ) } export function useStarterPackLink({ view, }: { view: bsky.starterPack.AnyStarterPackView }) { const {_} = useLingui() const qc = useQueryClient() const {rkey, handleOrDid} = React.useMemo(() => { const rkey = new AtUri(view.uri).rkey const {creator} = view return {rkey, handleOrDid: creator.handle || creator.did} }, [view]) const precache = () => { precacheResolvedUri(qc, view.creator.handle, view.creator.did) precacheStarterPack(qc, view) } return { to: `/starter-pack/${handleOrDid}/${rkey}`, label: AppBskyGraphStarterpack.isRecord(view.record) ? _(msg`Navigate to ${view.record.name}`) : _(msg`Navigate to starter pack`), precache, } } export function Link({ starterPack, children, }: { starterPack: bsky.starterPack.AnyStarterPackView onPress?: () => void children: BaseLinkProps['children'] }) { const {_} = useLingui() const queryClient = useQueryClient() const {record} = starterPack const {rkey, handleOrDid} = React.useMemo(() => { const rkey = new AtUri(starterPack.uri).rkey const {creator} = starterPack return {rkey, handleOrDid: creator.handle || creator.did} }, [starterPack]) if (!AppBskyGraphStarterpack.isRecord(record)) { return null } return ( { precacheResolvedUri( queryClient, starterPack.creator.handle, starterPack.creator.did, ) precacheStarterPack(queryClient, starterPack) }} style={[a.flex_col, a.align_start]}> {children} ) } export function Embed({ starterPack, }: { starterPack: bsky.starterPack.AnyStarterPackView }) { const t = useTheme() const imageUri = getStarterPackOgCard(starterPack) return ( ) }