Skip to content

Commit 6c8d456

Browse files
committed
fix(ui): update when stateflow update new value
1 parent dcc7019 commit 6c8d456

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

app/src/main/java/com/chatgptlite/wanted/MainActivity.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ class MainActivity : ComponentActivity() {
8585
) {
8686
Column( modifier = Modifier
8787
.fillMaxSize()) {
88-
AppBar {
89-
90-
}
88+
AppBar (onClickMenu = {
89+
scope.launch {
90+
drawerState.open()
91+
}
92+
})
93+
Divider()
9194
Conversation()
9295
}
9396
}

app/src/main/java/com/chatgptlite/wanted/ui/common/AppRoute.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ fun AppRoute(
2626
// val homeViewModel: HomeViewModel = viewModel(
2727
// factory = HomeViewModel.provideFactory(appContainer.postsRepository)
2828
// )
29-
Conversation (
30-
31-
)
29+
// Conversation (
30+
//
31+
// )
3232
}
3333
}
3434
}

app/src/main/java/com/chatgptlite/wanted/ui/conversations/Conversation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ fun MessageList(
4949
modifier: Modifier = Modifier,
5050
conversationViewModel: ConversationViewModel = hiltViewModel(),
5151
) {
52+
val listState = rememberLazyListState()
5253

5354
val conversationId by conversationViewModel.currentConversationState.collectAsState()
5455
val messagesMap by conversationViewModel.messagesState.collectAsState()
55-
val listState = rememberLazyListState()
5656

5757
val messages: List<MessageModel> =
5858
if (messagesMap[conversationId] == null) listOf() else messagesMap[conversationId]!!

app/src/main/java/com/chatgptlite/wanted/ui/conversations/ConversationViewModel.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("UNCHECKED_CAST")
2+
13
package com.chatgptlite.wanted.ui.conversations
24

35
import androidx.lifecycle.ViewModel
@@ -86,7 +88,7 @@ class ConversationViewModel @Inject constructor(
8688

8789
conversationRepo.newConversation(newConversation)
8890

89-
val conversations = _conversations.value
91+
val conversations = _conversations.value.toMutableList()
9092
conversations.add(0, newConversation)
9193

9294
_conversations.value = conversations
@@ -115,10 +117,10 @@ class ConversationViewModel @Inject constructor(
115117
}
116118

117119
private fun setMessages(messages: MutableList<MessageModel>) {
118-
val messagesMap: HashMap<String, MutableList<MessageModel>> = _messages.value
120+
val messagesMap: HashMap<String, MutableList<MessageModel>> = _messages.value.clone() as HashMap<String, MutableList<MessageModel>>
119121

120122
messagesMap[_currentConversation.value] = messages
121123

122-
_messages.update { messagesMap }
124+
_messages.value = messagesMap
123125
}
124126
}

0 commit comments

Comments
 (0)