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 7a99c020..40ac652f 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 @@ -49,6 +49,15 @@ fun toggleAllExpanded(commentNode: CommentNode): CommentNode { return commentNode } +fun findTopMostParent(node: CommentNode): CommentNode { + val parent = node.parent + return if (parent != null) { + findTopMostParent(parent) + } else { + node + } +} + fun LazyListScope.nodes( nodes: List, htmlConverter: HTMLConverter, 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 389fdd37..72284d69 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,12 +63,13 @@ private fun CommentsPageInternal( nodes = commentNodes, htmlConverter = htmlConverter, toggleExpanded = { node -> - // TODO(anunaym14): make this search recursive + val newNode = toggleAllExpanded(node) + val parent = findTopMostParent(newNode) val index = - commentNodes.indexOf(commentNodes.find { it.comment.url == node.comment.url }) + commentNodes.indexOf(commentNodes.find { it.comment.url == parent.comment.url }) if (index != -1) { commentNodes.removeAt(index) - commentNodes.add(index, toggleAllExpanded(node)) + commentNodes.add(index, parent) } }, )