feat(common): add support for unread comments to UI

This commit is contained in:
Harsh Shandilya 2023-01-12 00:59:31 +05:30
parent 579a2ffe2e
commit 91c3d0f9a6
No known key found for this signature in database
2 changed files with 22 additions and 3 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright © 2021-2022 Harsh Shandilya.
* Copyright © 2021-2023 Harsh Shandilya.
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
@ -31,8 +31,11 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import dev.msfjarvis.claw.common.posts.PostActions
import dev.msfjarvis.claw.common.posts.PostTitle
@ -157,6 +160,7 @@ internal fun CommentEntry(
buildCommenterString(
commenterName = comment.user.username,
score = comment.score,
isUnread = commentNode.isUnread,
createdAt = comment.createdAt,
updatedAt = comment.updatedAt,
),
@ -181,6 +185,7 @@ internal fun CommentEntry(
fun buildCommenterString(
commenterName: String,
score: Int,
isUnread: Boolean,
createdAt: TemporalAccessor,
updatedAt: TemporalAccessor,
): AnnotatedString {
@ -219,5 +224,17 @@ fun buildCommenterString(
append(updatedRelative.toString())
append(')')
}
if (isUnread) {
append(' ')
withStyle(
style =
SpanStyle(
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.error,
)
) {
append("(unread)")
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright © 2022 Harsh Shandilya.
* Copyright © 2022-2023 Harsh Shandilya.
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
@ -8,13 +8,15 @@ package dev.msfjarvis.claw.common.comments
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.material3.Divider
import dev.msfjarvis.claw.database.local.PostComments
import dev.msfjarvis.claw.model.Comment
internal data class CommentNode(
val comment: Comment,
var parent: CommentNode? = null,
val children: MutableList<CommentNode> = mutableListOf(),
var isExpanded: Boolean = true
val isUnread: Boolean = false,
var isExpanded: Boolean = true,
) {
fun addChild(child: CommentNode) {
if (comment.indentLevel + 1 == child.comment.indentLevel) {