mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 22:17:03 +05:30
feat(common): add support for unread comments to UI
This commit is contained in:
parent
579a2ffe2e
commit
91c3d0f9a6
2 changed files with 22 additions and 3 deletions
|
@ -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
|
* Use of this source code is governed by an MIT-style
|
||||||
* license that can be found in the LICENSE file or at
|
* license that can be found in the LICENSE file or at
|
||||||
* https://opensource.org/licenses/MIT.
|
* https://opensource.org/licenses/MIT.
|
||||||
|
@ -31,8 +31,11 @@ import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalUriHandler
|
import androidx.compose.ui.platform.LocalUriHandler
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
|
import androidx.compose.ui.text.SpanStyle
|
||||||
import androidx.compose.ui.text.buildAnnotatedString
|
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.style.TextOverflow
|
||||||
|
import androidx.compose.ui.text.withStyle
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import dev.msfjarvis.claw.common.posts.PostActions
|
import dev.msfjarvis.claw.common.posts.PostActions
|
||||||
import dev.msfjarvis.claw.common.posts.PostTitle
|
import dev.msfjarvis.claw.common.posts.PostTitle
|
||||||
|
@ -157,6 +160,7 @@ internal fun CommentEntry(
|
||||||
buildCommenterString(
|
buildCommenterString(
|
||||||
commenterName = comment.user.username,
|
commenterName = comment.user.username,
|
||||||
score = comment.score,
|
score = comment.score,
|
||||||
|
isUnread = commentNode.isUnread,
|
||||||
createdAt = comment.createdAt,
|
createdAt = comment.createdAt,
|
||||||
updatedAt = comment.updatedAt,
|
updatedAt = comment.updatedAt,
|
||||||
),
|
),
|
||||||
|
@ -181,6 +185,7 @@ internal fun CommentEntry(
|
||||||
fun buildCommenterString(
|
fun buildCommenterString(
|
||||||
commenterName: String,
|
commenterName: String,
|
||||||
score: Int,
|
score: Int,
|
||||||
|
isUnread: Boolean,
|
||||||
createdAt: TemporalAccessor,
|
createdAt: TemporalAccessor,
|
||||||
updatedAt: TemporalAccessor,
|
updatedAt: TemporalAccessor,
|
||||||
): AnnotatedString {
|
): AnnotatedString {
|
||||||
|
@ -219,5 +224,17 @@ fun buildCommenterString(
|
||||||
append(updatedRelative.toString())
|
append(updatedRelative.toString())
|
||||||
append(')')
|
append(')')
|
||||||
}
|
}
|
||||||
|
if (isUnread) {
|
||||||
|
append(' ')
|
||||||
|
withStyle(
|
||||||
|
style =
|
||||||
|
SpanStyle(
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = MaterialTheme.colorScheme.error,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
append("(unread)")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2022 Harsh Shandilya.
|
* Copyright © 2022-2023 Harsh Shandilya.
|
||||||
* Use of this source code is governed by an MIT-style
|
* Use of this source code is governed by an MIT-style
|
||||||
* license that can be found in the LICENSE file or at
|
* license that can be found in the LICENSE file or at
|
||||||
* https://opensource.org/licenses/MIT.
|
* https://opensource.org/licenses/MIT.
|
||||||
|
@ -8,13 +8,15 @@ package dev.msfjarvis.claw.common.comments
|
||||||
|
|
||||||
import androidx.compose.foundation.lazy.LazyListScope
|
import androidx.compose.foundation.lazy.LazyListScope
|
||||||
import androidx.compose.material3.Divider
|
import androidx.compose.material3.Divider
|
||||||
|
import dev.msfjarvis.claw.database.local.PostComments
|
||||||
import dev.msfjarvis.claw.model.Comment
|
import dev.msfjarvis.claw.model.Comment
|
||||||
|
|
||||||
internal data class CommentNode(
|
internal data class CommentNode(
|
||||||
val comment: Comment,
|
val comment: Comment,
|
||||||
var parent: CommentNode? = null,
|
var parent: CommentNode? = null,
|
||||||
val children: MutableList<CommentNode> = mutableListOf(),
|
val children: MutableList<CommentNode> = mutableListOf(),
|
||||||
var isExpanded: Boolean = true
|
val isUnread: Boolean = false,
|
||||||
|
var isExpanded: Boolean = true,
|
||||||
) {
|
) {
|
||||||
fun addChild(child: CommentNode) {
|
fun addChild(child: CommentNode) {
|
||||||
if (comment.indentLevel + 1 == child.comment.indentLevel) {
|
if (comment.indentLevel + 1 == child.comment.indentLevel) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue