mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 17:37:05 +05:30
common: delegate comment parsing to platforms
This commit is contained in:
parent
b0c3af7883
commit
5749b98b23
5 changed files with 28 additions and 14 deletions
|
@ -4,16 +4,14 @@ import androidx.compose.foundation.background
|
|||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
import androidx.compose.material.Divider
|
||||
import androidx.compose.material.Surface
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
@ -43,15 +41,15 @@ fun CommentsHeader(
|
|||
@Composable
|
||||
fun CommentEntry(
|
||||
comment: Comment,
|
||||
parseHtml: (String) -> String,
|
||||
renderMarkdown: @Composable (comment: String, modifier: Modifier) -> Unit,
|
||||
) {
|
||||
val indentLevel = comment.indentLevel.toInt() - 1
|
||||
val startPadding = ((10 * indentLevel) + 16).dp
|
||||
val text = parseHtml(comment.comment)
|
||||
|
||||
Divider(color = Color.Gray.copy(0.4f))
|
||||
Row(modifier = Modifier.height(IntrinsicSize.Min)) {
|
||||
CommentTreeColors(indentLevel = indentLevel)
|
||||
Row(modifier = Modifier.wrapContentHeight()) {
|
||||
// Don't work without IntrinsicSize, which we cannot use with the Android markdown implementation
|
||||
// CommentTreeColors(indentLevel = indentLevel)
|
||||
Column(
|
||||
modifier = Modifier.padding(start = startPadding, end = 8.dp, top = 4.dp, bottom = 4.dp)
|
||||
) {
|
||||
|
@ -60,7 +58,7 @@ fun CommentEntry(
|
|||
avatarUrl = "https://lobste.rs/${comment.user.avatarUrl}",
|
||||
contentDescription = "Submitted by ${comment.user.username}",
|
||||
)
|
||||
Text(text = text, modifier = Modifier.padding(top = 8.dp))
|
||||
renderMarkdown(comment.comment, Modifier.padding(top = 8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import dev.msfjarvis.lobsters.ui.comments.NetworkState
|
|||
@Composable
|
||||
private fun CommentsPageInternal(
|
||||
details: LobstersPostDetails,
|
||||
parseHtml: (String) -> String,
|
||||
renderMarkdown: @Composable (comment: String, modifier: Modifier) -> Unit,
|
||||
bottomPadding: Dp,
|
||||
) {
|
||||
LazyColumn(Modifier.padding(bottom = bottomPadding)) {
|
||||
|
@ -36,7 +36,7 @@ private fun CommentsPageInternal(
|
|||
|
||||
item { Spacer(modifier = Modifier.height(8.dp)) }
|
||||
|
||||
items(details.comments) { item -> CommentEntry(item, parseHtml) }
|
||||
items(details.comments) { item -> CommentEntry(item, renderMarkdown) }
|
||||
|
||||
item { Divider(color = Color.Gray.copy(0.4f)) }
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ private fun CommentsPageInternal(
|
|||
fun CommentsPage(
|
||||
postId: String,
|
||||
getDetails: suspend (String) -> LobstersPostDetails,
|
||||
parseHtml: (String) -> String,
|
||||
renderMarkdown: @Composable (comment: String, modifier: Modifier) -> Unit,
|
||||
paddingValues: PaddingValues,
|
||||
) {
|
||||
var postDetails: NetworkState by remember { mutableStateOf(NetworkState.Loading) }
|
||||
|
@ -58,7 +58,7 @@ fun CommentsPage(
|
|||
is NetworkState.Success<*> -> {
|
||||
CommentsPageInternal(
|
||||
(postDetails as NetworkState.Success<LobstersPostDetails>).data,
|
||||
parseHtml,
|
||||
renderMarkdown,
|
||||
paddingValues.calculateBottomPadding(),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue