mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 18:47:03 +05:30
fix(comments): calculate and expose indentLevel from CommentNode
This commit is contained in:
parent
9dcf26b5a4
commit
db393d4534
2 changed files with 21 additions and 7 deletions
|
@ -149,7 +149,7 @@ internal fun CommentEntry(
|
|||
.clickable { toggleExpanded(commentNode) }
|
||||
.background(MaterialTheme.colorScheme.background)
|
||||
.padding(
|
||||
start = CommentEntryPadding * comment.indentLevel,
|
||||
start = CommentEntryPadding * commentNode.indentLevel,
|
||||
end = CommentEntryPadding,
|
||||
top = CommentEntryPadding,
|
||||
bottom = CommentEntryPadding,
|
||||
|
|
|
@ -17,12 +17,14 @@ internal data class CommentNode(
|
|||
val children: MutableList<CommentNode> = mutableListOf(),
|
||||
val isUnread: Boolean = false,
|
||||
var isExpanded: Boolean = true,
|
||||
var indentLevel: Int
|
||||
) {
|
||||
fun addChild(child: CommentNode) {
|
||||
if (comment.indentLevel + 1 == child.comment.indentLevel) {
|
||||
if (comment.shortId == child.comment.parentComment) {
|
||||
children.add(child)
|
||||
child.parent = this
|
||||
} else {
|
||||
child.indentLevel += 1
|
||||
children.last().addChild(child)
|
||||
}
|
||||
}
|
||||
|
@ -36,12 +38,24 @@ internal fun createListNode(
|
|||
val isUnread = { id: String -> commentState?.commentIds?.contains(id) == false }
|
||||
|
||||
for (i in comments.indices) {
|
||||
if (comments[i].indentLevel == 1) {
|
||||
commentNodes.add(CommentNode(comment = comments[i], isUnread = isUnread(comments[i].shortId)))
|
||||
if (comments[i].parentComment == null) {
|
||||
commentNodes.add(
|
||||
CommentNode(
|
||||
comment = comments[i],
|
||||
isUnread = isUnread(comments[i].shortId),
|
||||
indentLevel = 1
|
||||
)
|
||||
)
|
||||
} else {
|
||||
commentNodes
|
||||
.last()
|
||||
.addChild(CommentNode(comment = comments[i], isUnread = isUnread(comments[i].shortId)))
|
||||
commentNodes.last().let {
|
||||
it.addChild(
|
||||
CommentNode(
|
||||
comment = comments[i],
|
||||
isUnread = isUnread(comments[i].shortId),
|
||||
indentLevel = it.indentLevel + 1
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue