From b0bfdf5bf0c0d0e04f796dce21f69b68eaafbf3f Mon Sep 17 00:00:00 2001 From: Hailey Date: Sun, 9 Jun 2024 16:54:01 -0700 Subject: [PATCH] fetch profiles for initial state --- src/screens/StarterPack/Wizard/State.tsx | 6 ++++-- src/screens/StarterPack/Wizard/index.tsx | 24 +++++++++++------------- src/state/queries/list-members.ts | 7 ++++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/screens/StarterPack/Wizard/State.tsx b/src/screens/StarterPack/Wizard/State.tsx index 766ab2f547..356c91591a 100644 --- a/src/screens/StarterPack/Wizard/State.tsx +++ b/src/screens/StarterPack/Wizard/State.tsx @@ -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, } } diff --git a/src/screens/StarterPack/Wizard/index.tsx b/src/screens/StarterPack/Wizard/index.tsx index e47d7b8bb5..84c4369d2d 100644 --- a/src/screens/StarterPack/Wizard/index.tsx +++ b/src/screens/StarterPack/Wizard/index.tsx @@ -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 ( ) } - return -} - -function WizardReady({ - starterPack, -}: { - starterPack?: AppBskyGraphDefs.StarterPackView -}) { return ( - + ) diff --git a/src/state/queries/list-members.ts b/src/state/queries/list-members.ts index ec1bd5775b..92792325ef 100644 --- a/src/state/queries/list-members.ts +++ b/src/state/queries/list-members.ts @@ -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), }) }