comments: Update isExpanded based on the parent node being toggled (Fixes #352)

This commit is contained in:
Anunay Maheshwari 2022-12-13 10:56:28 +05:30
parent 0f595f7b02
commit 4066a86ad6
2 changed files with 4 additions and 4 deletions

View file

@ -40,11 +40,11 @@ internal fun createListNode(comments: List<Comment>): MutableList<CommentNode> {
return commentNodes return commentNodes
} }
internal fun toggleAllExpanded(commentNode: CommentNode): CommentNode { internal fun updateAllExpanded(commentNode: CommentNode, expanded: Boolean): CommentNode {
commentNode.isExpanded = !commentNode.isExpanded commentNode.isExpanded = expanded
if (commentNode.children.isNotEmpty()) { if (commentNode.children.isNotEmpty()) {
commentNode.children.forEach { toggleAllExpanded(it) } commentNode.children.forEach { updateAllExpanded(it, expanded) }
} }
return commentNode return commentNode
} }

View file

@ -63,7 +63,7 @@ private fun CommentsPageInternal(
nodes = commentNodes, nodes = commentNodes,
htmlConverter = htmlConverter, htmlConverter = htmlConverter,
toggleExpanded = { node -> toggleExpanded = { node ->
val newNode = toggleAllExpanded(node) val newNode = updateAllExpanded(node, !node.isExpanded)
val parent = findTopMostParent(newNode) val parent = findTopMostParent(newNode)
val index = val index =
commentNodes.indexOf(commentNodes.find { it.comment.url == parent.comment.url }) commentNodes.indexOf(commentNodes.find { it.comment.url == parent.comment.url })