mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 19:57:04 +05:30
refactor(common): pass HTMLConverter
down as a parameter
This commit is contained in:
parent
02416a3606
commit
535c8a5808
5 changed files with 18 additions and 18 deletions
|
@ -49,9 +49,9 @@ import java.time.temporal.TemporalAccessor
|
|||
fun CommentsHeader(
|
||||
postDetails: ExtendedPostDetails,
|
||||
postActions: PostActions,
|
||||
htmlConverter: HTMLConverter,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val htmlConverter = LocalHTMLConverter.current
|
||||
val uriHandler = LocalUriHandler.current
|
||||
|
||||
Surface(color = MaterialTheme.colorScheme.background, modifier = modifier) {
|
||||
|
@ -133,10 +133,10 @@ fun PostLink(
|
|||
@Composable
|
||||
fun CommentEntry(
|
||||
comment: Comment,
|
||||
htmlConverter: HTMLConverter,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
var expanded by remember(comment) { mutableStateOf(true) }
|
||||
val htmlConverter = LocalHTMLConverter.current
|
||||
val uriHandler = LocalUriHandler.current
|
||||
Box(
|
||||
modifier =
|
||||
|
|
|
@ -30,11 +30,18 @@ import dev.msfjarvis.claw.model.ExtendedPostDetails
|
|||
private fun CommentsPageInternal(
|
||||
details: ExtendedPostDetails,
|
||||
postActions: PostActions,
|
||||
htmlConverter: HTMLConverter,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Surface(color = MaterialTheme.colorScheme.surfaceVariant) {
|
||||
LazyColumn(modifier = modifier, contentPadding = PaddingValues(bottom = 24.dp)) {
|
||||
item { CommentsHeader(postDetails = details, postActions = postActions) }
|
||||
item {
|
||||
CommentsHeader(
|
||||
postDetails = details,
|
||||
postActions = postActions,
|
||||
htmlConverter = htmlConverter,
|
||||
)
|
||||
}
|
||||
|
||||
if (details.comments.isNotEmpty()) {
|
||||
item {
|
||||
|
@ -49,7 +56,7 @@ private fun CommentsPageInternal(
|
|||
if (index != 0) {
|
||||
Divider()
|
||||
}
|
||||
CommentEntry(item)
|
||||
CommentEntry(comment = item, htmlConverter = htmlConverter)
|
||||
}
|
||||
} else {
|
||||
item {
|
||||
|
@ -72,6 +79,7 @@ fun CommentsPage(
|
|||
postId: String,
|
||||
getDetails: suspend (String) -> ExtendedPostDetails,
|
||||
postActions: PostActions,
|
||||
htmlConverter: HTMLConverter,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val postDetails by
|
||||
|
@ -86,9 +94,10 @@ fun CommentsPage(
|
|||
when (postDetails) {
|
||||
is Success<*> -> {
|
||||
CommentsPageInternal(
|
||||
(postDetails as Success<ExtendedPostDetails>).data,
|
||||
postActions,
|
||||
modifier.fillMaxSize(),
|
||||
details = (postDetails as Success<ExtendedPostDetails>).data,
|
||||
postActions = postActions,
|
||||
htmlConverter = htmlConverter,
|
||||
modifier = modifier.fillMaxSize(),
|
||||
)
|
||||
}
|
||||
is Error -> {
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package dev.msfjarvis.claw.common.comments
|
||||
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
|
||||
/** Defines a contract to convert strings of HTML to Markdown. */
|
||||
fun interface HTMLConverter {
|
||||
fun convertHTMLToMarkdown(html: String): String
|
||||
}
|
||||
|
||||
val LocalHTMLConverter = staticCompositionLocalOf<HTMLConverter> { error("To be provided") }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue