Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Chats not loading on tablet layout #280

Merged
merged 15 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ internal fun ConversationChatListScreen(
val posts: LazyPagingItems<ChatListItem> =
viewModel.chatListUseCase.postPagingData.collectAsLazyPagingItems()

LaunchedEffect(courseId, conversationId) {
chatListState.scrollToItem(0)
}

ConversationChatListScreen(
modifier = modifier,
courseId = courseId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.VerticalDivider
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModelStore
import androidx.lifecycle.ViewModelStoreOwner
import de.tum.informatics.www1.artemis.native_app.core.ui.getWindowSizeClass
import de.tum.informatics.www1.artemis.native_app.core.ui.navigation.DefaultTransition
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.StandalonePostId
Expand All @@ -44,39 +40,17 @@ fun ConversationScreen(
onNavigateToSettings: () -> Unit,
conversationsOverview: @Composable (Modifier) -> Unit
) {
val store = remember { ViewModelStore() }

val owner = remember(store) {
object : ViewModelStoreOwner {
override val viewModelStore: ViewModelStore = store
}
}

DisposableEffect(courseId, conversationId) {
onDispose {
store.clear()
}
}

val viewModel: ConversationViewModel =
koinViewModel(
key = "$courseId|$conversationId",
viewModelStoreOwner = owner
) { parametersOf(courseId, conversationId, threadPostId) }
) { parametersOf(courseId, conversationId, threadPostId) }

LaunchedEffect(threadPostId, viewModel) {
viewModel.updateOpenedThread(threadPostId)
}

var showThread by remember { mutableStateOf(threadPostId != null) }

val onNavigateUp = {
onCloseThread()
showThread = false
}
val onClickViewPost = { clientPostId: StandalonePostId ->
onOpenThread(clientPostId)
showThread = true
val showThread by remember(threadPostId) {
mutableStateOf(threadPostId != null)
}

WindowSizeAwareTwoColumnLayout(
Expand All @@ -101,7 +75,7 @@ fun ConversationScreen(
ConversationThreadScreen(
modifier = Modifier.fillMaxSize(),
viewModel = viewModel,
onNavigateUp = onNavigateUp
onNavigateUp = onCloseThread
)
} else {
ConversationChatListScreen(
Expand All @@ -111,7 +85,7 @@ fun ConversationScreen(
conversationId = conversationId,
onNavigateBack = onCloseConversation,
onNavigateToSettings = onNavigateToSettings,
onClickViewPost = onClickViewPost
onClickViewPost = onOpenThread
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.ui

import androidx.paging.LoadState
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.itemKey

/**
* Abstract layer over the loaded posts state, so we can use both a Pager and a simple list to display posts.
Expand Down Expand Up @@ -72,7 +71,13 @@ sealed interface PostsDataState {
}

fun LazyPagingItems<ChatListItem>.asPostsDataState(): PostsDataState = when {
itemCount == 0 -> PostsDataState.Empty
itemCount == 0 -> {
if (loadState.isIdle) {
PostsDataState.Empty
} else {
PostsDataState.Loading
}
}
loadState.refresh is LoadState.Loading -> PostsDataState.Loading
loadState.refresh is LoadState.Error -> PostsDataState.Error(::retry)
else -> PostsDataState.Loaded.WithLazyPagingItems(
Expand Down
Loading