From 65c03c635c181c9345659a36bf2407d9977a34b7 Mon Sep 17 00:00:00 2001 From: N7-X <62263986+N7-X@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:23:14 -0400 Subject: [PATCH] enhancement: retain comment expanded state when loading more or refreshing (#1012) --- .../raccoonforlemmy/unit/postdetail/PostDetailViewModel.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unit/postdetail/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/postdetail/PostDetailViewModel.kt b/unit/postdetail/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/postdetail/PostDetailViewModel.kt index 4dde47d81..eec2dfd90 100644 --- a/unit/postdetail/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/postdetail/PostDetailViewModel.kt +++ b/unit/postdetail/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/postdetail/PostDetailViewModel.kt @@ -479,7 +479,9 @@ class PostDetailViewModel( .populateLoadMoreComments() .map { it.copy( - expanded = autoExpandComments, + // retain comment expand state if refreshing or loading more + expanded = currentState.comments.firstOrNull() { comment -> comment.id == it.id }?.expanded + ?: autoExpandComments, // only first level are visible and can be expanded visible = autoExpandComments || it.depth == 0, )