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 replies icon appears in profile #533 #726

Merged
merged 4 commits into from
Jun 20, 2023
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 @@ -190,9 +190,12 @@ fun LazyListScope.commentNodeItem(
onReplyClick: (commentView: CommentView) -> Unit,
onSaveClick: (commentView: CommentView) -> Unit,
onMarkAsReadClick: (commentView: CommentView) -> Unit,
onCommentClick: (commentView: CommentView) -> Unit,
onEditCommentClick: (commentView: CommentView) -> Unit,
onDeleteCommentClick: (commentView: CommentView) -> Unit,
onPersonClick: (personId: Int) -> Unit,
onHeaderClick: (commentView: CommentView) -> Unit,
onHeaderLongClick: (commentView: CommentView) -> Unit,
onCommunityClick: (community: Community) -> Unit,
onPostClick: (postId: Int) -> Unit,
onReportClick: (commentView: CommentView) -> Unit,
Expand Down Expand Up @@ -273,10 +276,10 @@ fun LazyListScope.commentNodeItem(
myVote = instantScores.value.myVote,
isModerator = isModerator(commentView.creator, moderators),
onClick = {
toggleExpanded(commentId)
onHeaderClick(commentView)
LufyCZ marked this conversation as resolved.
Show resolved Hide resolved
},
onLongClick = {
toggleActionBar(commentId)
onHeaderLongClick(commentView)
},
collapsedCommentsCount = node.commentView.counts.child_count,
isExpanded = isExpanded(commentId),
Expand All @@ -291,9 +294,7 @@ fun LazyListScope.commentNodeItem(
CommentBody(
comment = commentView.comment,
viewSource = viewSource,
onClick = {
toggleExpanded(commentId)
},
onClick = { onCommentClick(commentView) },
onLongClick = {
toggleActionBar(commentId)
},
Expand Down Expand Up @@ -371,9 +372,12 @@ fun LazyListScope.commentNodeItem(
onDownvoteClick = onDownvoteClick,
onSaveClick = onSaveClick,
onMarkAsReadClick = onMarkAsReadClick,
onCommentClick = onCommentClick,
onEditCommentClick = onEditCommentClick,
onDeleteCommentClick = onDeleteCommentClick,
onPersonClick = onPersonClick,
onHeaderClick = onHeaderClick,
onHeaderLongClick = onHeaderLongClick,
onCommunityClick = onCommunityClick,
onPostClick = onPostClick,
showPostAndCommunityContext = showPostAndCommunityContext,
Expand Down Expand Up @@ -620,25 +624,31 @@ fun CommentNodesPreview() {
CommentNodes(
nodes = tree,
isFlat = false,
isExpanded = { _ -> true },
toggleExpanded = {},
toggleActionBar = {},
onUpvoteClick = {},
onDownvoteClick = {},
onReplyClick = {},
onFetchChildrenClick = {},
onSaveClick = {},
onMarkAsReadClick = {},
onCommentClick = {},
onEditCommentClick = {},
onDeleteCommentClick = {},
onReportClick = {},
onCommentLinkClick = {},
onPersonClick = {},
onHeaderClick = {},
onHeaderLongClick = {},
onCommunityClick = {},
onBlockCreatorClick = {},
onPostClick = {},
moderators = listOf(),
listState = rememberLazyListState(),
isCollapsedByParent = false,
showCollapsedCommentContent = false,
showActionBarByDefault = true,
showActionBar = { _ -> true },
enableDownVotes = true,
showAvatar = true,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ 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
import com.jerboa.CommentNodeData
import com.jerboa.datatypes.types.CommentView
import com.jerboa.datatypes.types.Community
Expand All @@ -17,18 +15,24 @@ import com.jerboa.db.Account
fun CommentNodes(
nodes: List<CommentNodeData>,
isFlat: Boolean,
isExpanded: (commentId: Int) -> Boolean,
listState: LazyListState,
toggleExpanded: (commentId: Int) -> Unit,
toggleActionBar: (commentId: Int) -> Unit,
onUpvoteClick: (commentView: CommentView) -> Unit,
onDownvoteClick: (commentView: CommentView) -> Unit,
onReplyClick: (commentView: CommentView) -> Unit,
onSaveClick: (commentView: CommentView) -> Unit,
onMarkAsReadClick: (commentView: CommentView) -> Unit,
onCommentClick: (commentView: CommentView) -> Unit,
onEditCommentClick: (commentView: CommentView) -> Unit,
onDeleteCommentClick: (commentView: CommentView) -> Unit,
onReportClick: (commentView: CommentView) -> Unit,
onCommentLinkClick: (commentView: CommentView) -> Unit,
onFetchChildrenClick: (commentView: CommentView) -> Unit,
onPersonClick: (personId: Int) -> Unit,
onHeaderClick: (commentView: CommentView) -> Unit,
onHeaderLongClick: (commentView: CommentView) -> Unit,
onCommunityClick: (community: Community) -> Unit,
onBlockCreatorClick: (creator: Person) -> Unit,
onPostClick: (postId: Int) -> Unit,
Expand All @@ -37,41 +41,28 @@ fun CommentNodes(
showPostAndCommunityContext: Boolean = false,
showCollapsedCommentContent: Boolean,
isCollapsedByParent: Boolean,
showActionBarByDefault: Boolean,
showActionBar: (commentId: Int) -> Boolean,
enableDownVotes: Boolean,
showAvatar: Boolean,
) {
// Holds the un-expanded comment ids
val unExpandedComments = remember { mutableStateListOf<Int>() }
val commentsWithToggledActionBar = remember { mutableStateListOf<Int>() }

LazyColumn(state = listState) {
commentNodeItems(
nodes = nodes,
isFlat = isFlat,
isExpanded = { commentId -> !unExpandedComments.contains(commentId) },
toggleExpanded = { commentId ->
if (unExpandedComments.contains(commentId)) {
unExpandedComments.remove(commentId)
} else {
unExpandedComments.add(commentId)
}
},
toggleActionBar = { commentId ->
if (commentsWithToggledActionBar.contains(commentId)) {
commentsWithToggledActionBar.remove(commentId)
} else {
commentsWithToggledActionBar.add(commentId)
}
},
isExpanded = isExpanded,
toggleExpanded = toggleExpanded,
toggleActionBar = toggleActionBar,
onUpvoteClick = onUpvoteClick,
onDownvoteClick = onDownvoteClick,
onReplyClick = onReplyClick,
onSaveClick = onSaveClick,
account = account,
moderators = moderators,
onMarkAsReadClick = onMarkAsReadClick,
onCommentClick = onCommentClick,
onPersonClick = onPersonClick,
onHeaderClick = onHeaderClick,
onHeaderLongClick = onHeaderLongClick,
onCommunityClick = onCommunityClick,
onPostClick = onPostClick,
onEditCommentClick = onEditCommentClick,
Expand All @@ -83,9 +74,7 @@ fun CommentNodes(
showPostAndCommunityContext = showPostAndCommunityContext,
showCollapsedCommentContent = showCollapsedCommentContent,
isCollapsedByParent = isCollapsedByParent,
showActionBar = { commentId ->
showActionBarByDefault xor commentsWithToggledActionBar.contains(commentId)
},
showActionBar = showActionBar,
enableDownVotes = enableDownVotes,
showAvatar = showAvatar,
)
Expand All @@ -103,12 +92,15 @@ fun LazyListScope.commentNodeItems(
onReplyClick: (commentView: CommentView) -> Unit,
onSaveClick: (commentView: CommentView) -> Unit,
onMarkAsReadClick: (commentView: CommentView) -> Unit,
onCommentClick: (commentView: CommentView) -> Unit,
onEditCommentClick: (commentView: CommentView) -> Unit,
onDeleteCommentClick: (commentView: CommentView) -> Unit,
onReportClick: (commentView: CommentView) -> Unit,
onCommentLinkClick: (commentView: CommentView) -> Unit,
onFetchChildrenClick: (commentView: CommentView) -> Unit,
onPersonClick: (personId: Int) -> Unit,
onHeaderClick: (commentView: CommentView) -> Unit,
onHeaderLongClick: (commentView: CommentView) -> Unit,
onCommunityClick: (community: Community) -> Unit,
onBlockCreatorClick: (creator: Person) -> Unit,
onPostClick: (postId: Int) -> Unit,
Expand All @@ -135,7 +127,10 @@ fun LazyListScope.commentNodeItems(
account = account,
moderators = moderators,
onMarkAsReadClick = onMarkAsReadClick,
onCommentClick = onCommentClick,
onPersonClick = onPersonClick,
onHeaderClick = onHeaderClick,
onHeaderLongClick = onHeaderLongClick,
onCommunityClick = onCommunityClick,
onPostClick = onPostClick,
onEditCommentClick = onEditCommentClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ fun CommentReplyNode(
onSaveClick: (commentReplyView: CommentReplyView) -> Unit,
onMarkAsReadClick: (commentReplyView: CommentReplyView) -> Unit,
onPersonClick: (personId: Int) -> Unit,
onCommentClick: (commentReplyView: CommentReplyView) -> Unit,
onCommunityClick: (community: Community) -> Unit,
onPostClick: (postId: Int) -> Unit,
onReportClick: (commentReplyView: CommentReplyView) -> Unit,
Expand Down Expand Up @@ -350,7 +351,7 @@ fun CommentReplyNode(
CommentBody(
comment = commentReplyView.comment,
viewSource = viewSource,
onClick = {},
onClick = { onCommentClick(commentReplyView) },
onLongClick = {
isActionBarExpanded = !isActionBarExpanded
},
Expand Down
62 changes: 36 additions & 26 deletions app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.navigation.NavController
import com.jerboa.*
import com.jerboa.api.ApiState
import com.jerboa.datatypes.types.BlockPerson
import com.jerboa.datatypes.types.CommentReplyView
import com.jerboa.datatypes.types.CommentSortType
import com.jerboa.datatypes.types.CreateCommentLike
import com.jerboa.datatypes.types.GetPersonMentions
Expand Down Expand Up @@ -276,6 +277,35 @@ fun InboxTabs(
}
},
)

val goToComment = { crv: CommentReplyView ->
// Go to the parent comment or post instead for context
val parent = getCommentParentId(crv.comment)
val route = if (parent != null) {
"comment/$parent"
} else {
"post/${crv.post.id}"
}
navController.navigate(route)
}

val markAsRead = { crv: CommentReplyView ->
account?.also { acct ->
inboxViewModel.markReplyAsRead(
MarkCommentReplyAsRead(
comment_reply_id = crv.comment_reply.id,
read = !crv.comment_reply.read,
auth = acct.jwt,
),
)
siteViewModel.fetchUnreadCounts(
GetUnreadCount(
auth = acct.jwt,
),
)
}
}

Box(modifier = Modifier.pullRefresh(refreshState)) {
PullRefreshIndicator(loading, refreshState, Modifier.align(Alignment.TopCenter))
when (val repliesRes = inboxViewModel.repliesRes) {
Expand Down Expand Up @@ -337,38 +367,18 @@ fun InboxTabs(
)
}
},
onMarkAsReadClick = { cr ->
account?.also { acct ->
inboxViewModel.markReplyAsRead(
MarkCommentReplyAsRead(
comment_reply_id = cr.comment_reply.id,
read = !cr.comment_reply.read,
auth = acct.jwt,
),
)
siteViewModel.fetchUnreadCounts(
GetUnreadCount(
auth = acct.jwt,
),
)
}
},
onMarkAsReadClick = { crv -> markAsRead(crv) },
onReportClick = { cv ->
navController.navigate("commentReport/${cv.comment.id}")
},
onCommentLinkClick = { cv ->
// Go to the parent comment or post instead for context
val parent = getCommentParentId(cv.comment)
val route = if (parent != null) {
"comment/$parent"
} else {
"post/${cv.post.id}"
}
navController.navigate(route)
},
onCommentLinkClick = goToComment,
onPersonClick = { personId ->
navController.navigate(route = "profile/$personId")
},
onCommentClick = { crv ->
goToComment(crv)
markAsRead(crv)
},
onCommunityClick = { community ->
navController.navigate(route = "community/${community.id}")
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,28 @@ fun UserTabs(
}
}

// Holds the un-expanded comment ids
val unExpandedComments = remember { mutableStateListOf<Int>() }
val commentsWithToggledActionBar = remember { mutableStateListOf<Int>() }

var toggleExpanded = { commentId: Int ->
if (unExpandedComments.contains(commentId)) {
unExpandedComments.remove(commentId)
} else {
unExpandedComments.add(commentId)
}
}

var toggleActionBar = { commentId: Int ->
if (commentsWithToggledActionBar.contains(commentId)) {
commentsWithToggledActionBar.remove(commentId)
} else {
commentsWithToggledActionBar.add(commentId)
}
}

val showActionBarByDefault = true

// act when end of list reached
if (endOfListReached) {
LaunchedEffect(Unit) {
Expand All @@ -515,8 +537,14 @@ fun UserTabs(
CommentNodes(
nodes = nodes,
isFlat = true,
isExpanded = { commentId -> !unExpandedComments.contains(commentId) },
listState = listState,
toggleExpanded = { commentId -> toggleExpanded(commentId) },
toggleActionBar = { commentId -> toggleActionBar(commentId) },
onMarkAsReadClick = {},
onCommentClick = { cv ->
navController.navigate("comment/${cv.comment.id}")
},
onUpvoteClick = { cv ->
account?.also { acct ->
personProfileViewModel.likeComment(
Expand Down Expand Up @@ -560,6 +588,8 @@ fun UserTabs(
onPersonClick = { personId ->
navController.navigate(route = "profile/$personId")
},
onHeaderClick = {},
onHeaderLongClick = { commentView -> toggleActionBar(commentView.comment.id) },
onCommunityClick = { community ->
navController.navigate(route = "community/${community.id}")
},
Expand Down Expand Up @@ -603,7 +633,9 @@ fun UserTabs(
showPostAndCommunityContext = true,
showCollapsedCommentContent = true,
isCollapsedByParent = false,
showActionBarByDefault = true,
showActionBar = { commentId ->
showActionBarByDefault xor commentsWithToggledActionBar.contains(commentId)
},
account = account,
moderators = listOf(),
enableDownVotes = enableDownVotes,
Expand Down
Loading