about summary refs log tree commit diff
path: root/src/components
diff options
context:
space:
mode:
authorChenyu Huang <itschenyu@gmail.com>2025-08-08 16:10:35 -0700
committerChenyu Huang <itschenyu@gmail.com>2025-08-19 15:28:37 -0700
commitf42b5831bb831e3b9f925730477a27e01d2b33f4 (patch)
treef0df61f8c22f91f7474646bea84023cef92be01f /src/components
parent7182cd3d5e157d7ad80f2e5c4a458730c46939a0 (diff)
downloadvoidsky-f42b5831bb831e3b9f925730477a27e01d2b33f4.tar.zst
parameterize the initial profile for starter pack profile select wizard screen
Diffstat (limited to 'src/components')
-rw-r--r--src/components/StarterPack/Wizard/WizardEditListDialog.tsx6
-rw-r--r--src/components/StarterPack/Wizard/WizardListCard.tsx11
-rw-r--r--src/components/dialogs/StarterPackDialog.tsx112
3 files changed, 59 insertions, 70 deletions
diff --git a/src/components/StarterPack/Wizard/WizardEditListDialog.tsx b/src/components/StarterPack/Wizard/WizardEditListDialog.tsx
index 731323f7f..7c3d1a40a 100644
--- a/src/components/StarterPack/Wizard/WizardEditListDialog.tsx
+++ b/src/components/StarterPack/Wizard/WizardEditListDialog.tsx
@@ -48,7 +48,6 @@ export function WizardEditListDialog({
 }) {
   const {_} = useLingui()
   const t = useTheme()
-  const {currentAccount} = useSession()
   const initialNumToRender = useInitialNumToRender()
 
   const listRef = useRef<ListMethods>(null)
@@ -56,10 +55,7 @@ export function WizardEditListDialog({
   const getData = () => {
     if (state.currentStep === 'Feeds') return state.feeds
 
-    return [
-      profile,
-      ...state.profiles.filter(p => p.did !== currentAccount?.did),
-    ]
+    return [profile, ...state.profiles.filter(p => p.did !== profile.did)]
   }
 
   const renderItem = ({item}: ListRenderItemInfo<any>) =>
diff --git a/src/components/StarterPack/Wizard/WizardListCard.tsx b/src/components/StarterPack/Wizard/WizardListCard.tsx
index fbaa185a9..09c265d78 100644
--- a/src/components/StarterPack/Wizard/WizardListCard.tsx
+++ b/src/components/StarterPack/Wizard/WizardListCard.tsx
@@ -131,10 +131,13 @@ export function WizardProfileCard({
 }) {
   const {currentAccount} = useSession()
 
-  const isMe = profile.did === currentAccount?.did
-  const included = isMe || state.profiles.some(p => p.did === profile.did)
+  // Determine the "main" profile for this starter pack - either targetDid or current account
+  const targetProfileDid = state.targetDid || currentAccount?.did
+  const isTarget = profile.did === targetProfileDid
+  const included = isTarget || state.profiles.some(p => p.did === profile.did)
   const disabled =
-    isMe || (!included && state.profiles.length >= STARTER_PACK_MAX_SIZE - 1)
+    isTarget ||
+    (!included && state.profiles.length >= STARTER_PACK_MAX_SIZE - 1)
   const moderationUi = moderateProfile(profile, moderationOpts).ui('avatar')
   const displayName = profile.displayName
     ? sanitizeDisplayName(profile.displayName)
@@ -144,7 +147,7 @@ export function WizardProfileCard({
     if (disabled) return
 
     Keyboard.dismiss()
-    if (profile.did === currentAccount?.did) return
+    if (profile.did === targetProfileDid) return
 
     if (!included) {
       dispatch({type: 'AddProfile', profile})
diff --git a/src/components/dialogs/StarterPackDialog.tsx b/src/components/dialogs/StarterPackDialog.tsx
index efd157723..0570859c4 100644
--- a/src/components/dialogs/StarterPackDialog.tsx
+++ b/src/components/dialogs/StarterPackDialog.tsx
@@ -12,7 +12,7 @@ import {useQueryClient} from '@tanstack/react-query'
 import {useRequireEmailVerification} from '#/lib/hooks/useRequireEmailVerification'
 import {type NavigationProp} from '#/lib/routes/types'
 import {
-  RQKEY_WITH_MEMBERSHIP,
+  invalidateActorStarterPacksWithMembershipQuery,
   useActorStarterPacksWithMembershipsQuery,
 } from '#/state/queries/actor-starter-packs'
 import {
@@ -35,7 +35,6 @@ import {TimesLarge_Stroke2_Corner0_Rounded} from '../icons/Times'
 type StarterPackWithMembership =
   AppBskyGraphGetStarterPacksWithMembership.StarterPackWithMembership
 
-// Simple module-level state for dialog coordination
 let dialogCallbacks: {
   onSuccess?: () => void
 } = {}
@@ -48,14 +47,12 @@ export function notifyDialogSuccess() {
 
 export type StarterPackDialogProps = {
   control: Dialog.DialogControlProps
-  accountDid: string
   targetDid: string
   enabled?: boolean
 }
 
 export function StarterPackDialog({
   control,
-  accountDid: _accountDid,
   targetDid,
   enabled,
 }: StarterPackDialogProps) {
@@ -73,8 +70,11 @@ export function StarterPackDialog({
 
   const navToWizard = React.useCallback(() => {
     control.close()
-    navigation.navigate('StarterPackWizard', {fromDialog: true})
-  }, [navigation, control])
+    navigation.navigate('StarterPackWizard', {
+      fromDialog: true,
+      targetDid: targetDid,
+    })
+  }, [navigation, control, targetDid])
 
   const wrappedNavToWizard = requireEmailVerification(navToWizard, {
     instructions: [
@@ -85,7 +85,6 @@ export function StarterPackDialog({
   })
 
   const onClose = React.useCallback(() => {
-    // setCurrentView('initial')
     control.close()
   }, [control])
 
@@ -252,69 +251,60 @@ function StarterPackItem({
   const {_} = useLingui()
   const t = useTheme()
   const queryClient = useQueryClient()
-  const [isUpdating, setIsUpdating] = React.useState(false)
 
   const starterPack = starterPackWithMembership.starterPack
   const isInPack = !!starterPackWithMembership.listItem
-  console.log('StarterPackItem render. 111', {
-    starterPackWithMembership: starterPackWithMembership.listItem?.subject,
-  })
 
-  console.log('StarterPackItem render', {
-    starterPackWithMembership,
-  })
+  const {mutate: addMembership, isPending: isAddingPending} =
+    useListMembershipAddMutation({
+      onSuccess: () => {
+        Toast.show(_(msg`Added to starter pack`))
+        invalidateActorStarterPacksWithMembershipQuery({
+          queryClient,
+          did: targetDid,
+        })
+      },
+      onError: () => {
+        Toast.show(_(msg`Failed to add to starter pack`), 'xmark')
+      },
+    })
+
+  const {mutate: removeMembership, isPending: isRemovingPending} =
+    useListMembershipRemoveMutation({
+      onSuccess: () => {
+        Toast.show(_(msg`Removed from starter pack`))
+        invalidateActorStarterPacksWithMembershipQuery({
+          queryClient,
+          did: targetDid,
+        })
+      },
+      onError: () => {
+        Toast.show(_(msg`Failed to remove from starter pack`), 'xmark')
+      },
+    })
 
-  const {mutateAsync: addMembership} = useListMembershipAddMutation({
-    onSuccess: () => {
-      Toast.show(_(msg`Added to starter pack`))
-    },
-    onError: () => {
-      Toast.show(_(msg`Failed to add to starter pack`), 'xmark')
-    },
-  })
+  const isMutating = isAddingPending || isRemovingPending
 
-  const {mutateAsync: removeMembership} = useListMembershipRemoveMutation({
-    onSuccess: () => {
-      Toast.show(_(msg`Removed from starter pack`))
-    },
-    onError: () => {
-      Toast.show(_(msg`Failed to remove from starter pack`), 'xmark')
-    },
-  })
-
-  const handleToggleMembership = async () => {
-    if (!starterPack.list?.uri || isUpdating) return
+  const handleToggleMembership = () => {
+    if (!starterPack.list?.uri || isMutating) return
 
     const listUri = starterPack.list.uri
-    setIsUpdating(true)
 
-    try {
-      if (!isInPack) {
-        await addMembership({
-          listUri: listUri,
-          actorDid: targetDid,
-        })
-      } else {
-        if (!starterPackWithMembership.listItem?.uri) {
-          console.error('Cannot remove: missing membership URI')
-          return
-        }
-        await removeMembership({
-          listUri: listUri,
-          actorDid: targetDid,
-          membershipUri: starterPackWithMembership.listItem.uri,
-        })
+    if (!isInPack) {
+      addMembership({
+        listUri: listUri,
+        actorDid: targetDid,
+      })
+    } else {
+      if (!starterPackWithMembership.listItem?.uri) {
+        console.error('Cannot remove: missing membership URI')
+        return
       }
-
-      await Promise.all([
-        queryClient.invalidateQueries({
-          queryKey: RQKEY_WITH_MEMBERSHIP(targetDid),
-        }),
-      ])
-    } catch (error) {
-      console.error('Failed to toggle membership:', error)
-    } finally {
-      setIsUpdating(false)
+      removeMembership({
+        listUri: listUri,
+        actorDid: targetDid,
+        membershipUri: starterPackWithMembership.listItem.uri,
+      })
     }
   }
 
@@ -377,7 +367,7 @@ function StarterPackItem({
         label={isInPack ? _(msg`Remove`) : _(msg`Add`)}
         color={isInPack ? 'secondary' : 'primary'}
         size="tiny"
-        disabled={isUpdating}
+        disabled={isMutating}
         onPress={handleToggleMembership}>
         <ButtonText>
           {isInPack ? <Trans>Remove</Trans> : <Trans>Add</Trans>}