From 4066a86ad6982d7b987aebdae793e993fe2ed8df Mon Sep 17 00:00:00 2001 From: Anunay Maheshwari Date: Tue, 13 Dec 2022 10:56:28 +0530 Subject: [PATCH] comments: Update isExpanded based on the parent node being toggled (Fixes #352) --- .../dev/msfjarvis/claw/common/comments/CommentNode.kt | 6 +++--- .../kotlin/dev/msfjarvis/claw/common/comments/Comments.kt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentNode.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentNode.kt index 9316de47..244bdb23 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentNode.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentNode.kt @@ -40,11 +40,11 @@ internal fun createListNode(comments: List): MutableList { return commentNodes } -internal fun toggleAllExpanded(commentNode: CommentNode): CommentNode { - commentNode.isExpanded = !commentNode.isExpanded +internal fun updateAllExpanded(commentNode: CommentNode, expanded: Boolean): CommentNode { + commentNode.isExpanded = expanded if (commentNode.children.isNotEmpty()) { - commentNode.children.forEach { toggleAllExpanded(it) } + commentNode.children.forEach { updateAllExpanded(it, expanded) } } return commentNode } diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt index 72284d69..350f3061 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt @@ -63,7 +63,7 @@ private fun CommentsPageInternal( nodes = commentNodes, htmlConverter = htmlConverter, toggleExpanded = { node -> - val newNode = toggleAllExpanded(node) + val newNode = updateAllExpanded(node, !node.isExpanded) val parent = findTopMostParent(newNode) val index = commentNodes.indexOf(commentNodes.find { it.comment.url == parent.comment.url })