mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 02:57:04 +05:30
fix(common): restore support for collapsing child comments
Fixes: 86400c352b
("feat(comments): remember comment collapsed state")
This commit is contained in:
parent
43b6f9411e
commit
6c012f93ce
1 changed files with 15 additions and 7 deletions
|
@ -47,14 +47,22 @@ internal class CommentsHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateListNode(shortId: String, isExpanded: Boolean) {
|
fun updateListNode(shortId: String, isExpanded: Boolean) {
|
||||||
|
fun updateNode(node: CommentNode): CommentNode {
|
||||||
|
if (node.comment.shortId == shortId) {
|
||||||
|
return node.copy(isExpanded = isExpanded)
|
||||||
|
}
|
||||||
|
val updatedChildren = node.children.map { updateNode(it) }.toMutableList()
|
||||||
|
return node.copy(children = updatedChildren)
|
||||||
|
}
|
||||||
|
|
||||||
val listNode = _listItems.value.toMutableList()
|
val listNode = _listItems.value.toMutableList()
|
||||||
val index = listNode.indexOfFirst { it.comment.shortId == shortId }
|
for (i in listNode.indices) {
|
||||||
|
val node = listNode[i]
|
||||||
if (index != -1) {
|
if (node.comment.shortId == shortId || node.children.any { it.comment.shortId == shortId }) {
|
||||||
val commentNode = listNode[index].copy(isExpanded = isExpanded)
|
listNode[i] = updateNode(node)
|
||||||
listNode[index] = commentNode
|
|
||||||
|
|
||||||
_listItems.value = listNode.toList()
|
_listItems.value = listNode.toList()
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue