Skip to content

Commit

Permalink
Better more comments button. Fixes #292 (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines authored Feb 4, 2023
1 parent 775777c commit 4a39a4e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
56 changes: 49 additions & 7 deletions app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.compose.material3.Divider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -250,19 +251,19 @@ fun LazyListScope.commentNodeItem(
downvotes = downvotes,
account = account
)
if (showMoreChildren) {
ShowMoreChildren(
commentView = commentView,
onFetchChildrenClick = onFetchChildrenClick
)
}
}
}
}
}
}
}

if (showMoreChildren) {
item {
ShowMoreChildrenNode(node.depth, commentView, onFetchChildrenClick)
}
}

if (isExpanded(commentId)) {
node.children?.also { nodes ->
commentNodeItems(
Expand Down Expand Up @@ -292,6 +293,47 @@ fun LazyListScope.commentNodeItem(
}
}

@Composable
private fun ShowMoreChildrenNode(
depth: Int,
commentView: CommentView,
onFetchChildrenClick: (commentView: CommentView) -> Unit
) {
val newDepth = depth + 1

val offset = calculateCommentOffset(newDepth, 4) // The ones with a border on
val offset2 = if (newDepth == 0) {
LARGE_PADDING
} else {
XXL_PADDING
}

val backgroundColor = MaterialTheme.colorScheme.background
val borderColor = calculateBorderColor(backgroundColor, newDepth)
val border = Border(SMALL_PADDING, borderColor)

Column(
modifier = Modifier
.padding(
start = offset
)
) {
Divider()
Column(
modifier = Modifier.border(start = border)
) {
Column(
modifier = Modifier.padding(start = offset2, end = LARGE_PADDING)
) {
ShowMoreChildren(
commentView = commentView,
onFetchChildrenClick = onFetchChildrenClick
)
}
}
}
}

@Composable
fun PostAndCommunityContextHeader(
post: Post,
Expand Down Expand Up @@ -567,7 +609,7 @@ fun ShowMoreChildren(
commentView: CommentView,
onFetchChildrenClick: (commentView: CommentView) -> Unit
) {
OutlinedButton(
TextButton(
content = {
Text("${commentView.counts.child_count} more replies")
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.jerboa.ui.components.community.blockCommunityRoutine
import com.jerboa.ui.components.person.blockPersonRoutine
import kotlinx.coroutines.launch

const val COMMENTS_DEPTH_MAX = 10
const val COMMENTS_DEPTH_MAX = 6

typealias PostId = Int
typealias CommentId = Int
Expand Down Expand Up @@ -154,7 +154,11 @@ class PostViewModel : ViewModel() {
)
)

comments.addAll(commentsOut.comments)
// Remove the first comment, since it is a parent
val newComments = commentsOut.comments.toMutableList()
newComments.removeAt(0)

comments.addAll(newComments)
commentTree.clear()
commentTree.addAll(buildCommentsTree(comments, isCommentView()))
} catch (e: Exception) {
Expand Down

0 comments on commit 4a39a4e

Please sign in to comment.