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
}
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
}

View file

@ -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 })