Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200import {useMemo} from 'react'import {View} from 'react-native'import {Image} from 'expo-image'import {AtUri} from '@atproto/syntax'import {Plural, Trans, useLingui} from '@lingui/react/macro'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 {StarterPackMultiPathLarge as StarterPackIcon} from '#/components/icons/StarterPack'import { Link as BaseLink, type LinkProps as BaseLinkProps,} from '#/components/Link'import {Text} from '#/components/Typography'import {app} from '#/lexicons'import * as bsky from '#/types/bsky'
export function Default({ starterPack,}: { starterPack?: bsky.starterPack.AnyStarterPackView}) { if (!starterPack) return null return ( <Link starterPack={starterPack}> <Card starterPack={starterPack} /> </Link> )}
export function Notification({ starterPack,}: { starterPack?: bsky.starterPack.AnyStarterPackView}) { if (!starterPack) return null return ( <Link starterPack={starterPack}> <Card starterPack={starterPack} noIcon={true} noDescription={true} /> </Link> )}
export function Card({ starterPack, noIcon, noDescription,}: { starterPack: bsky.starterPack.AnyStarterPackView noIcon?: boolean noDescription?: boolean}) { const {record, creator, joinedAllTimeCount} = starterPack
const {t: l} = useLingui() const t = useTheme() const {currentAccount} = useSession() const isOwnStarterPack = creator?.did === currentAccount?.did
if (!bsky.isType(app.bsky.graph.starterpack, record)) { return null }
return ( <View style={[a.w_full, a.gap_md]}> <View style={[a.flex_row, a.gap_sm, a.w_full]}> {!noIcon ? <StarterPackIcon width={40} gradient="sky" /> : null} <View style={[a.flex_1]}> <Text emoji style={[a.text_md, a.font_semi_bold, a.leading_snug]} numberOfLines={2}> {record.name} </Text> <Text emoji style={[a.leading_snug, t.atoms.text_contrast_medium]} numberOfLines={1}> {isOwnStarterPack ? l`Starter Pack by you` : l`Starter Pack by ${sanitizeHandle(creator.handle, '@')}`} </Text> </View> </View> {!noDescription && record.description ? ( <Text emoji numberOfLines={3} style={[a.leading_snug]}> {record.description} </Text> ) : null} {!!joinedAllTimeCount && joinedAllTimeCount >= 50 && ( <Text style={[a.font_semi_bold, t.atoms.text_contrast_medium]}> <Trans comment="Number of users (always at least 50) who have joined Bluesky using a specific Starter Pack"> <Plural value={joinedAllTimeCount} other="# users have" /> joined! </Trans> </Text> )} </View> )}
export function useStarterPackLink({ view,}: { view: bsky.starterPack.AnyStarterPackView}) { const {t: l} = useLingui() const qc = useQueryClient() const {rkey, handleOrDid} = 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: bsky.isType(app.bsky.graph.starterpack, view.record) ? l`Navigate to ${view.record.name}` : l`Navigate to Starter Pack`, precache, }}
export function Link({ starterPack, children,}: { starterPack: bsky.starterPack.AnyStarterPackView onPress?: () => void children: BaseLinkProps['children']}) { const {t: l} = useLingui() const queryClient = useQueryClient() const {record} = starterPack const {rkey, handleOrDid} = useMemo(() => { const rkey = new AtUri(starterPack.uri).rkey const {creator} = starterPack return {rkey, handleOrDid: creator.handle || creator.did} }, [starterPack])
if (!bsky.isType(app.bsky.graph.starterpack, record)) { return null }
return ( <BaseLink to={`/starter-pack/${handleOrDid}/${rkey}`} label={l`Navigate to ${record.name}`} onPress={() => { precacheResolvedUri( queryClient, starterPack.creator.handle, starterPack.creator.did, ) precacheStarterPack(queryClient, starterPack) }} style={[a.flex_col, a.align_start]}> {children} </BaseLink> )}
export function Embed({ starterPack,}: { starterPack: bsky.starterPack.AnyStarterPackView}) { const t = useTheme() const imageUri = getStarterPackOgCard(starterPack)
return ( <View style={[ a.border, a.rounded_sm, a.overflow_hidden, t.atoms.border_contrast_low, ]}> <Link starterPack={starterPack}> <Image source={imageUri} style={[a.w_full, a.aspect_card]} accessibilityIgnoresInvertColors={true} /> <View style={[a.px_sm, a.py_md]}> <Card starterPack={starterPack} /> </View> </Link> </View> )}