fetch profiles for initial state

This commit is contained in:
Hailey
2024-06-09 16:54:01 -07:00
parent 0b01041069
commit b0bfdf5bf0
3 changed files with 19 additions and 18 deletions
+4 -2
View File
@@ -103,9 +103,11 @@ function reducer(state: State, action: Action): State {
// TODO supply the initial state to this component
export function Provider({
starterPack,
profiles,
children,
}: {
starterPack?: AppBskyGraphDefs.StarterPackView
profiles?: AppBskyActorDefs.ProfileViewBasic[]
children: React.ReactNode
}) {
const createInitialState = (): State => {
@@ -115,8 +117,8 @@ export function Provider({
currentStep: 'Details',
name: starterPack.record.name,
description: starterPack.record.description,
profiles: starterPack.listItemsSample?.map(item => item.subject) || [],
feeds: starterPack.feeds || [],
profiles: profiles ?? [],
feeds: starterPack.feeds ?? [],
processing: false,
}
}
+11 -13
View File
@@ -1,7 +1,7 @@
import React from 'react'
import {Keyboard, TouchableOpacity, View} from 'react-native'
import {KeyboardAwareScrollView} from 'react-native-keyboard-controller'
import {AppBskyActorDefs, AppBskyGraphDefs, AtUri} from '@atproto/api'
import {AppBskyActorDefs, AtUri} from '@atproto/api'
import {GeneratorView} from '@atproto/api/dist/client/types/app/bsky/feed/defs'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {msg, Plural, Trans} from '@lingui/macro'
@@ -13,6 +13,7 @@ import {HITSLOP_10} from 'lib/constants'
import {CommonNavigatorParams, NavigationProp} from 'lib/routes/types'
import {enforceLen} from 'lib/strings/helpers'
import {isAndroid, isNative, isWeb} from 'platform/detection'
import {useListMembersQuery} from 'state/queries/list-members'
import {useProfileQuery} from 'state/queries/profile'
import {useResolveDidQuery} from 'state/queries/resolve-uri'
import {useStarterPackQuery} from 'state/queries/useStarterPackQuery'
@@ -50,29 +51,26 @@ export function Wizard({
const {
data: starterPack,
isLoading: isLoadingStarterPack,
isError: isErrorStarterPAck,
isError: isErrorStarterPack,
} = useStarterPackQuery({did, rkey})
if (name && rkey && !starterPack) {
const listUri = starterPack?.list?.uri
const {data} = useListMembersQuery(listUri)
const profiles = data?.pages.flatMap(p => p.items.map(i => i.subject))
if (name && rkey && !starterPack && (!listUri || (listUri && !profiles))) {
return (
<ListMaybePlaceholder
isLoading={isLoadingDid || isLoadingStarterPack}
isError={isErrorDid || isErrorStarterPAck}
isError={isErrorDid || isErrorStarterPack}
errorMessage={_(msg`Could not find that starter pack`)}
/>
)
}
return <WizardReady starterPack={starterPack} />
}
function WizardReady({
starterPack,
}: {
starterPack?: AppBskyGraphDefs.StarterPackView
}) {
return (
<Provider starterPack={starterPack}>
<Provider starterPack={starterPack} profiles={profiles}>
<WizardInner />
</Provider>
)
+4 -3
View File
@@ -15,7 +15,7 @@ type RQPageParam = string | undefined
const RQKEY_ROOT = 'list-members'
export const RQKEY = (uri: string) => [RQKEY_ROOT, uri]
export function useListMembersQuery(uri: string, limit: number = PAGE_SIZE) {
export function useListMembersQuery(uri?: string, limit: number = PAGE_SIZE) {
const agent = useAgent()
return useInfiniteQuery<
AppBskyGraphGetList.OutputSchema,
@@ -25,10 +25,10 @@ export function useListMembersQuery(uri: string, limit: number = PAGE_SIZE) {
RQPageParam
>({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(uri),
queryKey: RQKEY(uri ?? ''),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await agent.app.bsky.graph.getList({
list: uri,
list: uri!,
limit,
cursor: pageParam,
})
@@ -36,6 +36,7 @@ export function useListMembersQuery(uri: string, limit: number = PAGE_SIZE) {
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
enabled: Boolean(uri),
})
}