mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 21:07:04 +05:30
refactor: make PostComments non-nullable
This commit is contained in:
parent
c50790e4f9
commit
39e3d783cd
4 changed files with 14 additions and 9 deletions
|
@ -38,10 +38,10 @@ internal data class CommentNode(
|
|||
|
||||
internal fun createListNode(
|
||||
comments: List<Comment>,
|
||||
commentState: PostComments?,
|
||||
commentState: PostComments,
|
||||
): MutableList<CommentNode> {
|
||||
val commentNodes = mutableListOf<CommentNode>()
|
||||
val isUnread = { id: String -> commentState?.commentIds?.contains(id) == false }
|
||||
val isUnread = { id: String -> !commentState.commentIds.contains(id) }
|
||||
|
||||
for (i in comments.indices) {
|
||||
if (comments[i].parentComment == null) {
|
||||
|
|
|
@ -32,7 +32,7 @@ fun CommentsPage(
|
|||
postId: String,
|
||||
postActions: PostActions,
|
||||
htmlConverter: HTMLConverter,
|
||||
getSeenComments: suspend (String) -> PostComments?,
|
||||
getSeenComments: suspend (String) -> PostComments,
|
||||
markSeenComments: (String, List<Comment>) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
openUserProfile: (String) -> Unit,
|
||||
|
@ -46,7 +46,9 @@ fun CommentsPage(
|
|||
)
|
||||
}
|
||||
val commentState by
|
||||
produceState<PostComments?>(initialValue = null) { value = getSeenComments(postId) }
|
||||
produceState(initialValue = PostComments(postId, emptyList())) {
|
||||
value = getSeenComments(postId)
|
||||
}
|
||||
|
||||
when (postDetails) {
|
||||
is Success<*> -> {
|
||||
|
|
|
@ -49,7 +49,7 @@ internal fun CommentsPageInternal(
|
|||
details: UIPost,
|
||||
postActions: PostActions,
|
||||
htmlConverter: HTMLConverter,
|
||||
commentState: PostComments?,
|
||||
commentState: PostComments,
|
||||
markSeenComments: (String, List<Comment>) -> Unit,
|
||||
openUserProfile: (String) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
|
@ -57,8 +57,8 @@ internal fun CommentsPageInternal(
|
|||
val context = LocalContext.current
|
||||
val commentNodes = createListNode(details.comments, commentState)
|
||||
LaunchedEffect(key1 = commentNodes) {
|
||||
if (details.comments.isNotEmpty() && !commentState?.commentIds.isNullOrEmpty()) {
|
||||
val unreadCount = details.comments.size - (commentState?.commentIds?.size ?: 0)
|
||||
if (details.comments.isNotEmpty() && commentState.commentIds.isNotEmpty()) {
|
||||
val unreadCount = details.comments.size - commentState.commentIds.size
|
||||
if (unreadCount > 0) {
|
||||
val text = "$unreadCount unread comments"
|
||||
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue