Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comment scrolling bug. Fixes #231 #235

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.AlertDialog
import androidx.compose.material.Divider
Expand Down Expand Up @@ -409,19 +410,20 @@ fun CommentNodesPreview() {
val tree = buildCommentsTree(comments, SortType.Hot)
CommentNodes(
nodes = tree,
moderators = listOf(),
onCommunityClick = {},
onUpvoteClick = {},
onDownvoteClick = {},
onReplyClick = {},
onSaveClick = {},
onMarkAsReadClick = {},
onEditCommentClick = {},
onDeleteCommentClick = {},
onMarkAsReadClick = {},
onReportClick = {},
onPersonClick = {},
onCommunityClick = {},
onBlockCreatorClick = {},
onPostClick = {},
onReportClick = {},
onReplyClick = {},
onSaveClick = {},
onUpvoteClick = {},
onBlockCreatorClick = {}
moderators = listOf(),
listState = rememberLazyListState()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jerboa.ui.components.comment

import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
Expand All @@ -12,6 +13,7 @@ import com.jerboa.db.Account
@Composable
fun CommentNodes(
nodes: List<CommentNodeData>,
listState: LazyListState,
onUpvoteClick: (commentView: CommentView) -> Unit,
onDownvoteClick: (commentView: CommentView) -> Unit,
onReplyClick: (commentView: CommentView) -> Unit,
Expand All @@ -32,7 +34,7 @@ fun CommentNodes(
// Holds the un-expanded comment ids
val unExpandedComments = remember { mutableStateListOf<Int>() }

LazyColumn {
LazyColumn(state = listState) {
commentNodeItems(
nodes = nodes,
isExpanded = { commentId -> !unExpandedComments.contains(commentId) },
Expand Down
51 changes: 26 additions & 25 deletions app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ fun InboxTabs(
) {
CommentNodes(
nodes = nodes,
listState = listState,
onUpvoteClick = { commentView ->
account?.also { acct ->
inboxViewModel.likeComment(
Expand All @@ -266,22 +267,6 @@ fun InboxTabs(
)
navController.navigate("commentReply")
},
onEditCommentClick = { commentView ->
commentEditViewModel.initialize(commentView)
navController.navigate("commentEdit")
},
onDeleteCommentClick = { commentView ->
account?.also { acct ->
inboxViewModel.deleteComment(
commentView = commentView,
account = acct,
ctx = ctx
)
}
},
onReportClick = { commentView ->
navController.navigate("commentReport/${commentView.comment.id}")
},
onSaveClick = { commentView ->
account?.also { acct ->
inboxViewModel.saveComment(
Expand All @@ -291,38 +276,54 @@ fun InboxTabs(
)
}
},
onBlockCreatorClick = {
onMarkAsReadClick = { commentView ->
account?.also { acct ->
inboxViewModel.blockCreator(
creator = it,
inboxViewModel.markReplyAsRead(
commentView = commentView,
account = acct,
ctx = ctx
)
homeViewModel.updateUnreads(commentView)
}
},
onMarkAsReadClick = { commentView ->
onEditCommentClick = { commentView ->
commentEditViewModel.initialize(commentView)
navController.navigate("commentEdit")
},
onDeleteCommentClick = { commentView ->
account?.also { acct ->
inboxViewModel.markReplyAsRead(
inboxViewModel.deleteComment(
commentView = commentView,
account = acct,
ctx = ctx
)
homeViewModel.updateUnreads(commentView)
}
},
onReportClick = { commentView ->
navController.navigate("commentReport/${commentView.comment.id}")
},
onPersonClick = { personId ->
navController.navigate(route = "profile/$personId")
},
onCommunityClick = { community ->
navController.navigate(route = "community/${community.id}")
},
onBlockCreatorClick = {
account?.also { acct ->
inboxViewModel.blockCreator(
creator = it,
account = acct,
ctx = ctx
)
}
},
onPostClick = { postId ->
navController.navigate(route = "post/$postId")
},
showPostAndCommunityContext = true,
showRead = true,
account = account,
moderators = listOf()
moderators = listOf(),
showPostAndCommunityContext = true,
showRead = true
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ fun UserTabs(
) {
CommentNodes(
nodes = nodes,
listState = listState,
onMarkAsReadClick = {},
onUpvoteClick = { commentView ->
account?.also { acct ->
Expand Down