From 39d899b249eb6853240d921828e752fc9989320e Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Thu, 21 May 2026 11:48:21 +0700 Subject: [PATCH] add loading state to home screen --- .../kotlin/su/reya/coop/screens/HomeScreen.kt | 11 ++++++++++- .../commonMain/kotlin/su/reya/coop/NostrViewModel.kt | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/HomeScreen.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/HomeScreen.kt index e7bc625..89116fb 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/HomeScreen.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/HomeScreen.kt @@ -24,6 +24,7 @@ import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.ListItem import androidx.compose.material3.ListItemDefaults +import androidx.compose.material3.LoadingIndicator import androidx.compose.material3.MaterialShapes import androidx.compose.material3.MaterialTheme import androidx.compose.material3.ModalBottomSheet @@ -93,6 +94,7 @@ fun HomeScreen( val userProfile by currentUserProfile.collectAsState(initial = null) val chatRooms by viewModel.chatRooms.collectAsState(initial = emptyList()) + val isPartialProcessedGiftWrap by viewModel.isPartialProcessedGiftWrap.collectAsState(initial = false) val scope = rememberCoroutineScope() val sheetState = rememberModalBottomSheetState() @@ -212,7 +214,14 @@ fun HomeScreen( ) } ) { - if (chatRooms.isEmpty()) { + if (!isPartialProcessedGiftWrap && chatRooms.isEmpty()) { + Box( + modifier = Modifier.fillMaxSize(), + contentAlignment = Alignment.Center + ) { + LoadingIndicator() + } + } else if (chatRooms.isEmpty()) { Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center diff --git a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt index 0cbb0be..60a31fc 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt @@ -48,6 +48,9 @@ class NostrViewModel( private val _contactList = MutableStateFlow>(emptySet()) val contactList = _contactList.asStateFlow() + private val _isPartialProcessedGiftWrap = MutableStateFlow(false) + val isPartialProcessedGiftWrap = _isPartialProcessedGiftWrap.asStateFlow() + private val _newEvents = MutableSharedFlow(extraBufferCapacity = 100) val newEvents = _newEvents.asSharedFlow() @@ -99,6 +102,10 @@ class NostrViewModel( }, onSubscriptionClose = { getChatRooms() + + if (!_isPartialProcessedGiftWrap.value) { + _isPartialProcessedGiftWrap.value = true + } }, onNewMessage = { event -> viewModelScope.launch {