parameterize the initial profile for starter pack profile select wizard screen
This commit is contained in:
@@ -7,7 +7,6 @@ import {
|
||||
import {msg, plural} from '@lingui/macro'
|
||||
|
||||
import {STARTER_PACK_MAX_SIZE} from '#/lib/constants'
|
||||
import {useSession} from '#/state/session'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
@@ -37,6 +36,7 @@ interface State {
|
||||
processing: boolean
|
||||
error?: string
|
||||
transitionDirection: 'Backward' | 'Forward'
|
||||
targetDid?: string
|
||||
}
|
||||
|
||||
type TStateContext = [State, (action: Action) => void]
|
||||
@@ -118,15 +118,17 @@ function reducer(state: State, action: Action): State {
|
||||
export function Provider({
|
||||
starterPack,
|
||||
listItems,
|
||||
targetProfile,
|
||||
children,
|
||||
}: {
|
||||
starterPack?: AppBskyGraphDefs.StarterPackView
|
||||
listItems?: AppBskyGraphDefs.ListItemView[]
|
||||
targetProfile: bsky.profile.AnyProfileView
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const {currentAccount} = useSession()
|
||||
|
||||
const createInitialState = (): State => {
|
||||
const targetDid = targetProfile?.did
|
||||
|
||||
if (
|
||||
starterPack &&
|
||||
bsky.validate(starterPack.record, AppBskyGraphStarterpack.validateRecord)
|
||||
@@ -136,23 +138,22 @@ export function Provider({
|
||||
currentStep: 'Details',
|
||||
name: starterPack.record.name,
|
||||
description: starterPack.record.description,
|
||||
profiles:
|
||||
listItems
|
||||
?.map(i => i.subject)
|
||||
.filter(p => p.did !== currentAccount?.did) ?? [],
|
||||
profiles: listItems?.map(i => i.subject) ?? [],
|
||||
feeds: starterPack.feeds ?? [],
|
||||
processing: false,
|
||||
transitionDirection: 'Forward',
|
||||
targetDid,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
canNext: true,
|
||||
currentStep: 'Details',
|
||||
profiles: [],
|
||||
profiles: [targetProfile],
|
||||
feeds: [],
|
||||
processing: false,
|
||||
transitionDirection: 'Forward',
|
||||
targetDid,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,11 +72,15 @@ export function Wizard({
|
||||
const params = route.params ?? {}
|
||||
const rkey = 'rkey' in params ? params.rkey : undefined
|
||||
const fromDialog = 'fromDialog' in params ? params.fromDialog : false
|
||||
const targetDid = 'targetDid' in params ? params.targetDid : undefined
|
||||
const {currentAccount} = useSession()
|
||||
const moderationOpts = useModerationOpts()
|
||||
|
||||
const {_} = useLingui()
|
||||
|
||||
// Use targetDid if provided (from dialog), otherwise use current account
|
||||
const profileDid = targetDid || currentAccount!.did
|
||||
|
||||
const {
|
||||
data: starterPack,
|
||||
isLoading: isLoadingStarterPack,
|
||||
@@ -94,7 +98,7 @@ export function Wizard({
|
||||
data: profile,
|
||||
isLoading: isLoadingProfile,
|
||||
isError: isErrorProfile,
|
||||
} = useProfileQuery({did: currentAccount?.did})
|
||||
} = useProfileQuery({did: profileDid})
|
||||
|
||||
const isEdit = Boolean(rkey)
|
||||
const isReady =
|
||||
@@ -130,7 +134,10 @@ export function Wizard({
|
||||
<Layout.Screen
|
||||
testID="starterPackWizardScreen"
|
||||
style={web([{minHeight: 0}, a.flex_1])}>
|
||||
<Provider starterPack={starterPack} listItems={listItems}>
|
||||
<Provider
|
||||
starterPack={starterPack}
|
||||
listItems={listItems}
|
||||
targetProfile={profile}>
|
||||
<WizardInner
|
||||
currentStarterPack={starterPack}
|
||||
currentListItems={listItems}
|
||||
@@ -228,7 +235,7 @@ function WizardInner({
|
||||
} else {
|
||||
// Original behavior for other entry points
|
||||
navigation.replace('StarterPack', {
|
||||
name: currentAccount!.handle,
|
||||
name: profile!.handle,
|
||||
rkey,
|
||||
new: true,
|
||||
})
|
||||
@@ -245,7 +252,7 @@ function WizardInner({
|
||||
navigation.goBack()
|
||||
} else {
|
||||
navigation.replace('StarterPack', {
|
||||
name: currentAccount!.handle,
|
||||
name: profile!.handle,
|
||||
rkey: parsed!.rkey,
|
||||
})
|
||||
}
|
||||
@@ -281,6 +288,7 @@ function WizardInner({
|
||||
currentListItems: currentListItems,
|
||||
})
|
||||
} else {
|
||||
console.log('Creating new starter pack: ', state.profiles)
|
||||
createStarterPack({
|
||||
name: state.name?.trim() || getDefaultName(),
|
||||
description: state.description?.trim(),
|
||||
@@ -306,10 +314,7 @@ function WizardInner({
|
||||
)
|
||||
}
|
||||
|
||||
const items =
|
||||
state.currentStep === 'Profiles'
|
||||
? [profile, ...state.profiles]
|
||||
: state.feeds
|
||||
const items = state.currentStep === 'Profiles' ? state.profiles : state.feeds
|
||||
|
||||
const isEditEnabled =
|
||||
(state.currentStep === 'Profiles' && items.length > 1) ||
|
||||
@@ -413,20 +418,15 @@ function Container({children}: {children: React.ReactNode}) {
|
||||
function Footer({
|
||||
onNext,
|
||||
nextBtnText,
|
||||
profile,
|
||||
}: {
|
||||
onNext: () => void
|
||||
nextBtnText: string
|
||||
profile: AppBskyActorDefs.ProfileViewDetailed
|
||||
}) {
|
||||
const t = useTheme()
|
||||
const [state] = useWizardState()
|
||||
const {bottom: bottomInset} = useSafeAreaInsets()
|
||||
|
||||
const items =
|
||||
state.currentStep === 'Profiles'
|
||||
? [profile, ...state.profiles]
|
||||
: state.feeds
|
||||
const {currentAccount} = useSession()
|
||||
const items = state.currentStep === 'Profiles' ? state.profiles : state.feeds
|
||||
|
||||
const minimumItems = state.currentStep === 'Profiles' ? 8 : 0
|
||||
|
||||
@@ -493,12 +493,23 @@ function Footer({
|
||||
{
|
||||
items.length < 2 ? (
|
||||
<Trans>
|
||||
It's just you right now! Add more people to your starter pack
|
||||
by searching above.
|
||||
It's just{' '}
|
||||
<Text style={[a.font_bold, textStyles]} emoji>
|
||||
{currentAccount?.did === items[0].did
|
||||
? 'you'
|
||||
: getName(items[0])}{' '}
|
||||
</Text>
|
||||
right now! Add more people to your starter pack by searching
|
||||
above.
|
||||
</Trans>
|
||||
) : items.length === 2 ? (
|
||||
<Trans>
|
||||
<Text style={[a.font_bold, textStyles]}>You</Text> and
|
||||
<Text style={[a.font_bold, textStyles]}>
|
||||
{currentAccount?.did === items[0].did
|
||||
? 'you'
|
||||
: getName(items[0])}
|
||||
</Text>{' '}
|
||||
and
|
||||
<Text> </Text>
|
||||
<Text style={[a.font_bold, textStyles]} emoji>
|
||||
{getName(items[1] /* [0] is self, skip it */)}{' '}
|
||||
|
||||
Reference in New Issue
Block a user