Add AnyStarterPackView and related, implement in first usage

This commit is contained in:
Eric Bailey
2025-01-07 11:57:52 -06:00
parent 54a5d56447
commit 4a1695b798
4 changed files with 39 additions and 9 deletions
+13 -7
View File
@@ -1,7 +1,7 @@
import React from 'react'
import {View} from 'react-native'
import {Image} from 'expo-image'
import {AppBskyGraphDefs, AppBskyGraphStarterpack, AtUri} from '@atproto/api'
import {AppBskyGraphStarterpack, AtUri} from '@atproto/api'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useQueryClient} from '@tanstack/react-query'
@@ -15,11 +15,12 @@ import {atoms as a, useTheme} from '#/alf'
import {StarterPack} from '#/components/icons/StarterPack'
import {Link as BaseLink, LinkProps as BaseLinkProps} from '#/components/Link'
import {Text} from '#/components/Typography'
import * as atp from '#/types/atproto'
export function Default({
starterPack,
}: {
starterPack?: AppBskyGraphDefs.StarterPackViewBasic
starterPack?: atp.starterPack.AnyStarterPackView
}) {
if (!starterPack) return null
return (
@@ -32,7 +33,7 @@ export function Default({
export function Notification({
starterPack,
}: {
starterPack?: AppBskyGraphDefs.StarterPackViewBasic
starterPack?: atp.starterPack.AnyStarterPackView
}) {
if (!starterPack) return null
return (
@@ -47,7 +48,7 @@ export function Card({
noIcon,
noDescription,
}: {
starterPack: AppBskyGraphDefs.StarterPackViewBasic
starterPack: atp.starterPack.AnyStarterPackView
noIcon?: boolean
noDescription?: boolean
}) {
@@ -57,7 +58,12 @@ export function Card({
const t = useTheme()
const {currentAccount} = useSession()
if (!AppBskyGraphStarterpack.isRecord(record)) {
if (
!atp.dangerousIsType<AppBskyGraphStarterpack.Record>(
record,
AppBskyGraphStarterpack.isRecord,
)
) {
return null
}
@@ -100,7 +106,7 @@ export function Link({
starterPack,
children,
}: {
starterPack: AppBskyGraphDefs.StarterPackViewBasic
starterPack: atp.starterPack.AnyStarterPackView
onPress?: () => void
children: BaseLinkProps['children']
}) {
@@ -139,7 +145,7 @@ export function Link({
export function Embed({
starterPack,
}: {
starterPack: AppBskyGraphDefs.StarterPackViewBasic
starterPack: atp.starterPack.AnyStarterPackView
}) {
const t = useTheme()
const imageUri = getStarterPackOgCard(starterPack)
+4 -2
View File
@@ -1,4 +1,6 @@
import {AppBskyGraphDefs, AtUri} from '@atproto/api'
import {AtUri} from '@atproto/api'
import * as atp from '#/types/atproto'
export function createStarterPackLinkFromAndroidReferrer(
referrerQueryString: string,
@@ -79,7 +81,7 @@ export function httpStarterPackUriToAtUri(httpUri?: string): string | null {
}
export function getStarterPackOgCard(
didOrStarterPack: AppBskyGraphDefs.StarterPackView | string,
didOrStarterPack: atp.starterPack.AnyStarterPackView | string,
rkey?: string,
) {
if (typeof didOrStarterPack === 'string') {
+1
View File
@@ -1,4 +1,5 @@
export * as profile from '#/types/atproto/profile'
export * as starterPack from '#/types/atproto/starterPack'
/**
* Use sparingly, and only when you know it's safe to do so.
+21
View File
@@ -0,0 +1,21 @@
import {AppBskyGraphDefs} from '@atproto/api'
export {
/**
* Renamed to clarify source of this util, but directly aliases the original.
* {@link AppBskyGraphDefs.isStarterPackViewBasic}
*/
isStarterPackViewBasic as isBasicView,
/**
* Renamed to clarify source of this util, but directly aliases the original.
* {@link AppBskyGraphDefs.isStarterPackView}
*/
isStarterPackView as isView,
} from '@atproto/api/dist/client/types/app/bsky/graph/defs'
/**
* Matches any starter pack view exported by our SDK
*/
export type AnyStarterPackView =
| AppBskyGraphDefs.StarterPackViewBasic
| AppBskyGraphDefs.StarterPackView