pass starter pack in for editing
This commit is contained in:
@@ -43,9 +43,8 @@ export type CommonNavigatorParams = {
|
|||||||
StarterPack: {name: string; rkey: string}
|
StarterPack: {name: string; rkey: string}
|
||||||
StarterPackLanding: {name: string; rkey: string}
|
StarterPackLanding: {name: string; rkey: string}
|
||||||
StarterPackWizard: {
|
StarterPackWizard: {
|
||||||
mode: 'Create' | 'Edit'
|
name?: string
|
||||||
id?: string
|
rkey?: string
|
||||||
initialStep?: 'Details' | 'Profiles' | 'Feeds'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,9 +106,8 @@ export type AllNavigatorParams = CommonNavigatorParams & {
|
|||||||
StarterPack: {name: string; rkey: string}
|
StarterPack: {name: string; rkey: string}
|
||||||
StarterPackLanding: {name: string; rkey: string}
|
StarterPackLanding: {name: string; rkey: string}
|
||||||
StarterPackWizard: {
|
StarterPackWizard: {
|
||||||
mode: 'Create' | 'Edit'
|
name?: string
|
||||||
id?: string
|
rkey?: string
|
||||||
initialStep?: 'Details' | 'Profiles' | 'Feeds'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {AppBskyActorDefs} from '@atproto/api'
|
import {
|
||||||
|
AppBskyActorDefs,
|
||||||
|
AppBskyGraphDefs,
|
||||||
|
AppBskyGraphStarterpack,
|
||||||
|
} 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'
|
||||||
|
|
||||||
const steps = ['Details', 'Profiles', 'Feeds'] as const
|
const steps = ['Details', 'Profiles', 'Feeds'] as const
|
||||||
@@ -22,7 +26,6 @@ interface State {
|
|||||||
currentStep: Step
|
currentStep: Step
|
||||||
name?: string
|
name?: string
|
||||||
description?: string
|
description?: string
|
||||||
avatar?: string
|
|
||||||
profiles: AppBskyActorDefs.ProfileViewBasic[]
|
profiles: AppBskyActorDefs.ProfileViewBasic[]
|
||||||
feeds: GeneratorView[]
|
feeds: GeneratorView[]
|
||||||
processing: boolean
|
processing: boolean
|
||||||
@@ -99,29 +102,35 @@ 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({
|
||||||
initialState,
|
starterPack,
|
||||||
initialStep = 'Details',
|
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
initialState?: any // TODO update this type
|
starterPack?: AppBskyGraphDefs.StarterPackView
|
||||||
initialStep?: Step
|
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
}) {
|
}) {
|
||||||
const [state, dispatch] = React.useReducer(
|
const createInitialState = (): State => {
|
||||||
reducer,
|
if (starterPack && AppBskyGraphStarterpack.isRecord(starterPack.record)) {
|
||||||
initialState
|
return {
|
||||||
? {
|
canNext: false,
|
||||||
...initialState,
|
currentStep: 'Details',
|
||||||
step: initialStep,
|
name: starterPack.record.name,
|
||||||
}
|
description: starterPack.record.description,
|
||||||
: {
|
profiles: starterPack.listItemsSample?.map(item => item.subject) || [],
|
||||||
canNext: false,
|
feeds: starterPack.feeds || [],
|
||||||
currentStep: initialStep,
|
processing: false,
|
||||||
profiles: [],
|
}
|
||||||
feeds: [],
|
}
|
||||||
processing: false,
|
|
||||||
},
|
return {
|
||||||
)
|
canNext: false,
|
||||||
|
currentStep: 'Details',
|
||||||
|
profiles: [],
|
||||||
|
feeds: [],
|
||||||
|
processing: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [state, dispatch] = React.useReducer(reducer, createInitialState())
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StateContext.Provider value={[state, dispatch]}>
|
<StateContext.Provider value={[state, dispatch]}>
|
||||||
|
|||||||
@@ -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, AtUri} from '@atproto/api'
|
import {AppBskyActorDefs, AppBskyGraphDefs, 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'
|
||||||
@@ -14,6 +14,8 @@ 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 {useProfileQuery} from 'state/queries/profile'
|
import {useProfileQuery} from 'state/queries/profile'
|
||||||
|
import {useResolveDidQuery} from 'state/queries/resolve-uri'
|
||||||
|
import {useStarterPackQuery} from 'state/queries/useStarterPackQuery'
|
||||||
import {useAgent, useSession} from 'state/session'
|
import {useAgent, useSession} from 'state/session'
|
||||||
import {useSetMinimalShellMode} from 'state/shell'
|
import {useSetMinimalShellMode} from 'state/shell'
|
||||||
import {UserAvatar} from 'view/com/util/UserAvatar'
|
import {UserAvatar} from 'view/com/util/UserAvatar'
|
||||||
@@ -25,6 +27,7 @@ import {StepProfiles} from '#/screens/StarterPack/Wizard/StepProfiles'
|
|||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {Button, ButtonText} from '#/components/Button'
|
import {Button, ButtonText} from '#/components/Button'
|
||||||
import {useDialogControl} from '#/components/Dialog'
|
import {useDialogControl} from '#/components/Dialog'
|
||||||
|
import {ListMaybePlaceholder} from '#/components/Lists'
|
||||||
import {Loader} from '#/components/Loader'
|
import {Loader} from '#/components/Loader'
|
||||||
import {WizardEditListDialog} from '#/components/StarterPack/Wizard/WizardEditListDialog'
|
import {WizardEditListDialog} from '#/components/StarterPack/Wizard/WizardEditListDialog'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
@@ -34,41 +37,42 @@ export function Wizard({
|
|||||||
route,
|
route,
|
||||||
}: NativeStackScreenProps<CommonNavigatorParams, 'StarterPackWizard'>) {
|
}: NativeStackScreenProps<CommonNavigatorParams, 'StarterPackWizard'>) {
|
||||||
const params = route.params
|
const params = route.params
|
||||||
const {mode, initialStep, id} = params ?? {}
|
const {name, rkey} = params ?? {}
|
||||||
|
|
||||||
|
const {_} = useLingui()
|
||||||
|
|
||||||
// TODO load query here
|
// TODO load query here
|
||||||
const starterPack = {}
|
const {
|
||||||
|
data: did,
|
||||||
|
isLoading: isLoadingDid,
|
||||||
|
isError: isErrorDid,
|
||||||
|
} = useResolveDidQuery(name)
|
||||||
|
const {
|
||||||
|
data: starterPack,
|
||||||
|
isLoading: isLoadingStarterPack,
|
||||||
|
isError: isErrorStarterPAck,
|
||||||
|
} = useStarterPackQuery({did, rkey})
|
||||||
|
|
||||||
// TODO use this to wait for loading the starterpack for editing
|
if (name && rkey && !starterPack) {
|
||||||
if (mode === 'Edit' && false) {
|
return (
|
||||||
// Await here
|
<ListMaybePlaceholder
|
||||||
return
|
isLoading={isLoadingDid || isLoadingStarterPack}
|
||||||
|
isError={isErrorDid || isErrorStarterPAck}
|
||||||
|
errorMessage={_(msg`Could not find that starter pack`)}
|
||||||
|
/>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return <WizardReady starterPack={starterPack} />
|
||||||
<WizardReady
|
|
||||||
mode={mode}
|
|
||||||
id={id}
|
|
||||||
initialStep={initialStep}
|
|
||||||
starterPack={starterPack}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function WizardReady({
|
function WizardReady({
|
||||||
mode,
|
|
||||||
initialStep,
|
|
||||||
starterPack,
|
starterPack,
|
||||||
}: {
|
}: {
|
||||||
mode: 'Create' | 'Edit'
|
starterPack?: AppBskyGraphDefs.StarterPackView
|
||||||
id?: string
|
|
||||||
initialStep?: 'Details' | 'Profiles' | 'Feeds'
|
|
||||||
starterPack?: any
|
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<Provider
|
<Provider starterPack={starterPack}>
|
||||||
initialState={mode === 'Edit' ? starterPack : undefined}
|
|
||||||
initialStep={initialStep}>
|
|
||||||
<WizardInner />
|
<WizardInner />
|
||||||
</Provider>
|
</Provider>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,13 @@ import {useAgent, useSession} from 'state/session'
|
|||||||
|
|
||||||
const RQKEY_ROOT = 'starter-pack'
|
const RQKEY_ROOT = 'starter-pack'
|
||||||
|
|
||||||
export function useStarterPackQuery({did, rkey}: {did?: string; rkey: string}) {
|
export function useStarterPackQuery({
|
||||||
|
did,
|
||||||
|
rkey,
|
||||||
|
}: {
|
||||||
|
did?: string
|
||||||
|
rkey?: string
|
||||||
|
}) {
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
const uri = `at://${did}/app.bsky.graph.starterpack/${rkey}`
|
const uri = `at://${did}/app.bsky.graph.starterpack/${rkey}`
|
||||||
|
|
||||||
@@ -18,7 +24,7 @@ export function useStarterPackQuery({did, rkey}: {did?: string; rkey: string}) {
|
|||||||
})
|
})
|
||||||
return res.data.starterPack
|
return res.data.starterPack
|
||||||
},
|
},
|
||||||
enabled: Boolean(did),
|
enabled: Boolean(did) && Boolean(rkey),
|
||||||
staleTime: STALE.MINUTES.FIVE,
|
staleTime: STALE.MINUTES.FIVE,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user