Skip to content

Latest commit

 

History

History
136 lines (118 loc) · 5.78 KB

File metadata and controls

136 lines (118 loc) · 5.78 KB

Create Family from Settings - Implementation Summary

Overview

Implemented a feature that allows users without a family (or "Just Me" users) to create a family from the Settings screen. When they tap "Create Family", they go through the family onboarding flow and return to the Settings screen after completion.

Changes Made

1. AppNavigationCoordinator.swift

  • Added: isCreatingFamilyFromSettings flag to track if the family creation flow was initiated from Settings
  • Purpose: This flag helps the app know where to return the user after completing the family creation flow
// Track if family creation was initiated from Settings
var isCreatingFamilyFromSettings: Bool = false

2. SettingsSheet.swift

  • Modified: The Create Family / Manage Family button logic
  • Key Logic: Checks if family exists AND has other members
    • if let family = familyStore.family, !family.otherMembers.isEmpty
    • This ensures "Just Me" users (who have a family but no other members) see "Create Family"
  • Behavior:
    • When family has other members → Shows "Manage Family" and navigates to ManageFamilyView
    • When no family OR "Just Me" family → Shows "Create Family" and:
      1. Sets coordinator.isCreatingFamilyFromSettings = true
      2. Navigates to .letsMeetYourIngrediFam canvas
      3. Dismisses the Settings sheet
if let family = familyStore.family, !family.otherMembers.isEmpty {
    // Family with other members -> Manage Family
    NavigationLink { ManageFamilyView() } label: { ... }
} else {
    // No family OR "Just Me" -> Create Family
    Button {
        coordinator.isCreatingFamilyFromSettings = true
        coordinator.showCanvas(.letsMeetYourIngrediFam)
        dismiss()
    } label: { ... }
}

3. PersistentBottomSheet.swift

  • Added: AppState environment to access the activeSheet property
  • Modified: The .meetYourProfile case completion handler
  • Behavior: Checks the isCreatingFamilyFromSettings flag and:
    • If true:
      1. Resets the flag
      2. Navigates to .home
      3. Waits 0.3 seconds for home to load
      4. Automatically reopens the Settings sheet (appState.activeSheet = .settings)
    • If false: Normal flow - navigates to .home
case .meetYourProfile:
    MeetYourProfileView {
        if coordinator.isCreatingFamilyFromSettings {
            coordinator.isCreatingFamilyFromSettings = false
            coordinator.showCanvas(.home)
            Task { @MainActor in
                try? await Task.sleep(nanoseconds: 300_000_000)
                appState.activeSheet = .settings
            }
        } else {
            coordinator.showCanvas(.home)
        }
    }

User Flow

"Just Me" Users (Family with no other members):

  1. User opens Settings
  2. Sees "Create Family" button (even though they have a family, it's just them)
  3. Taps "Create Family"
  4. Goes through family creation flow
  5. Settings automatically reopens showing "Manage Family" ✨

Users with No Family:

  1. User opens Settings
  2. Sees "Create Family" button
  3. Taps "Create Family"
  4. Goes to "Let's meet your IngrediFam!" screen
  5. Sees "Your Family Overview" with their profile
  6. Adds family members
  7. Goes through dietary preferences
  8. Completes onboarding questions
  9. Sees AI chat and summary
  10. Returns to Home screen briefly
  11. Settings automatically reopens showing "Manage Family" instead of "Create Family" ✨

Users with Family (has other members):

  1. User opens Settings
  2. Sees "Manage Family" button
  3. Taps it → Goes to ManageFamilyView (unchanged)

Technical Details

Why Check otherMembers.isEmpty?

  • When a user chooses "Just Me" during onboarding, the backend creates a family with only one member (themselves)
  • familyStore.family != nil would be true for these users
  • But they should still see "Create Family" to add more members
  • Solution: Check !family.otherMembers.isEmpty to distinguish between:
    • Just Me users: family.otherMembers.isEmpty == true → Show "Create Family"
    • Family users: family.otherMembers.isEmpty == false → Show "Manage Family"

Why This Approach?

  • Minimal Changes: Reuses existing onboarding flow components
  • Clean Separation: Uses a flag to track the source without modifying the entire flow
  • Maintainable: Easy to understand and modify in the future
  • Handles Edge Cases: Properly distinguishes between "Just Me" and actual families

Key Components Used

  • LetsMeetYourIngrediFamView: Shows "Your Family Overview" with the user's profile
  • MeetYourIngrediFam: Shows "Let's meet your IngrediFam!" intro screen
  • WhatsYourName: Allows user to enter their name
  • AddMoreMembers: Allows adding family members
  • DietaryPreferencesSheet: Dietary preferences selection
  • MainCanvasView: Dynamic onboarding questions
  • IngrediBotView: AI chat and summary
  • MeetYourProfileView: Final profile review before completion

Testing Checklist

  • "Just Me" user sees "Create Family" → Goes to family creation flow
  • User with no family sees "Create Family" → Goes to family creation flow
  • User completes family creation → Settings automatically reopens
  • Settings shows "Manage Family" after adding members
  • User with existing family (other members) sees "Manage Family" → Goes to ManageFamilyView
  • Flag is properly reset after completion
  • Normal onboarding flow (not from Settings) still works correctly

Notes

  • The implementation leverages the existing family onboarding flow
  • All UI components were already implemented - just needed proper navigation wiring
  • The flag approach ensures clean separation between Settings-initiated and normal onboarding flows
  • Critical Fix: Checking otherMembers.isEmpty ensures "Just Me" users can create a family