diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/navigation/AuxNavHost.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/navigation/AuxNavHost.kt index 8fb12fa4..bd123936 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/navigation/AuxNavHost.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/navigation/AuxNavHost.kt @@ -44,7 +44,6 @@ fun AuxNavHost( navController: NavHostController ) { val lifecycleOwner = LocalLifecycleOwner.current - val scope = rememberCoroutineScope() val databaseManager = DatabaseManager(auxGlobal) @@ -85,7 +84,9 @@ fun AuxNavHost( } is NavigationUIState.UnsignedProfile -> { navController.navigate( - route = UnsignedProfileRoute + route = UnsignedProfileRoute( + state.unsignedNostrEvent.id + ) ) { popUpTo(0) } diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NavigationViewModel.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NavigationViewModel.kt index 29a98703..04ab2298 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NavigationViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NavigationViewModel.kt @@ -40,6 +40,8 @@ class NavigationViewModel( } } + private val logger = Logger.withTag(TAG) + private val _navigationUIState = MutableStateFlow( initialNavigationUIState ) @@ -49,42 +51,46 @@ class NavigationViewModel( observeProfile() } - private val logger = Logger.withTag(TAG) private fun observeProfile() { + logger.i("observeProfile") viewModelScope.launch { delay(2_100) // Looking busy... _navigationUIState.getAndUpdate { NavigationUIState.Landing } + + logger.i("Navigation UI State is Landing") + val publicKey = SeedManager.activePublicKey().toHexKey() + logger.i("Observing: $publicKey") nostrRepository.observeProfile( - publicKey = SeedManager.activePublicKey().toHexKey() - ).map { localProfile -> + publicKey = publicKey + ).collect { localProfile -> + logger.i("Local Profile: $localProfile") _navigationUIState.getAndUpdate { if (localProfile == null) { + logger.i("We need to be on the landing screen so user creates account") NavigationUIState.Landing } else if (localProfile.profile != null) { + logger.i("We have a profile: ${localProfile.profile}") NavigationUIState.ProfileLoaded( profile = localProfile.profile ) } else if (localProfile.nostrEvent != null) { + logger.i("Nostr event with the profile needs to be announced") NavigationUIState.UnannouncedProfile( nostrEvent = localProfile.nostrEvent ) } else { + logger.i("We have an unsigned profile: ${localProfile.unsignedNostrEvent}") NavigationUIState.UnsignedProfile( unsignedNostrEvent = localProfile.unsignedNostrEvent ) } } - }.catch { e -> - logger.e("Error observing profile:", e) - _navigationUIState.getAndUpdate { - NavigationUIState.Error - } - }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), NavigationUIState.Landing) + } } }