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 // TODO supply the initial state to this component
export function Provider({ export function Provider({
starterPack, starterPack,
profiles,
children, children,
}: { }: {
starterPack?: AppBskyGraphDefs.StarterPackView starterPack?: AppBskyGraphDefs.StarterPackView
profiles?: AppBskyActorDefs.ProfileViewBasic[]
children: React.ReactNode children: React.ReactNode
}) { }) {
const createInitialState = (): State => { const createInitialState = (): State => {
@@ -115,8 +117,8 @@ export function Provider({
currentStep: 'Details', currentStep: 'Details',
name: starterPack.record.name, name: starterPack.record.name,
description: starterPack.record.description, description: starterPack.record.description,
profiles: starterPack.listItemsSample?.map(item => item.subject) || [], profiles: profiles ?? [],
feeds: starterPack.feeds || [], feeds: starterPack.feeds ?? [],
processing: false, processing: false,
} }
} }
+11 -13
View File
@@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import {Keyboard, TouchableOpacity, View} from 'react-native' import {Keyboard, TouchableOpacity, View} from 'react-native'
import {KeyboardAwareScrollView} from 'react-native-keyboard-controller' 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 {GeneratorView} from '@atproto/api/dist/client/types/app/bsky/feed/defs'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {msg, Plural, Trans} from '@lingui/macro' 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 {CommonNavigatorParams, NavigationProp} from 'lib/routes/types'
import {enforceLen} from 'lib/strings/helpers' import {enforceLen} from 'lib/strings/helpers'
import {isAndroid, isNative, isWeb} from 'platform/detection' import {isAndroid, isNative, isWeb} from 'platform/detection'
import {useListMembersQuery} from 'state/queries/list-members'
import {useProfileQuery} from 'state/queries/profile' import {useProfileQuery} from 'state/queries/profile'
import {useResolveDidQuery} from 'state/queries/resolve-uri' import {useResolveDidQuery} from 'state/queries/resolve-uri'
import {useStarterPackQuery} from 'state/queries/useStarterPackQuery' import {useStarterPackQuery} from 'state/queries/useStarterPackQuery'
@@ -50,29 +51,26 @@ export function Wizard({
const { const {
data: starterPack, data: starterPack,
isLoading: isLoadingStarterPack, isLoading: isLoadingStarterPack,
isError: isErrorStarterPAck, isError: isErrorStarterPack,
} = useStarterPackQuery({did, rkey}) } = 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 ( return (
<ListMaybePlaceholder <ListMaybePlaceholder
isLoading={isLoadingDid || isLoadingStarterPack} isLoading={isLoadingDid || isLoadingStarterPack}
isError={isErrorDid || isErrorStarterPAck} isError={isErrorDid || isErrorStarterPack}
errorMessage={_(msg`Could not find that starter pack`)} errorMessage={_(msg`Could not find that starter pack`)}
/> />
) )
} }
return <WizardReady starterPack={starterPack} />
}
function WizardReady({
starterPack,
}: {
starterPack?: AppBskyGraphDefs.StarterPackView
}) {
return ( return (
<Provider starterPack={starterPack}> <Provider starterPack={starterPack} profiles={profiles}>
<WizardInner /> <WizardInner />
</Provider> </Provider>
) )
+4 -3
View File
@@ -15,7 +15,7 @@ type RQPageParam = string | undefined
const RQKEY_ROOT = 'list-members' const RQKEY_ROOT = 'list-members'
export const RQKEY = (uri: string) => [RQKEY_ROOT, uri] 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() const agent = useAgent()
return useInfiniteQuery< return useInfiniteQuery<
AppBskyGraphGetList.OutputSchema, AppBskyGraphGetList.OutputSchema,
@@ -25,10 +25,10 @@ export function useListMembersQuery(uri: string, limit: number = PAGE_SIZE) {
RQPageParam RQPageParam
>({ >({
staleTime: STALE.MINUTES.ONE, staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(uri), queryKey: RQKEY(uri ?? ''),
async queryFn({pageParam}: {pageParam: RQPageParam}) { async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await agent.app.bsky.graph.getList({ const res = await agent.app.bsky.graph.getList({
list: uri, list: uri!,
limit, limit,
cursor: pageParam, cursor: pageParam,
}) })
@@ -36,6 +36,7 @@ export function useListMembersQuery(uri: string, limit: number = PAGE_SIZE) {
}, },
initialPageParam: undefined, initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor, getNextPageParam: lastPage => lastPage.cursor,
enabled: Boolean(uri),
}) })
} }