mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 00:37:03 +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
|
@ -38,7 +38,6 @@ import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
|
||||||
import dev.msfjarvis.claw.api.LobstersApi
|
import dev.msfjarvis.claw.api.LobstersApi
|
||||||
import dev.msfjarvis.claw.common.comments.CommentsPage
|
import dev.msfjarvis.claw.common.comments.CommentsPage
|
||||||
import dev.msfjarvis.claw.common.comments.HTMLConverter
|
import dev.msfjarvis.claw.common.comments.HTMLConverter
|
||||||
import dev.msfjarvis.claw.common.comments.LocalHTMLConverter
|
|
||||||
import dev.msfjarvis.claw.common.res.ClawIcons
|
import dev.msfjarvis.claw.common.res.ClawIcons
|
||||||
import dev.msfjarvis.claw.common.theme.LobstersTheme
|
import dev.msfjarvis.claw.common.theme.LobstersTheme
|
||||||
import dev.msfjarvis.claw.common.ui.decorations.ClawAppBar
|
import dev.msfjarvis.claw.common.ui.decorations.ClawAppBar
|
||||||
|
@ -75,11 +74,7 @@ fun LobstersApp(
|
||||||
|
|
||||||
LobstersTheme(
|
LobstersTheme(
|
||||||
dynamicColor = true,
|
dynamicColor = true,
|
||||||
providedValues =
|
providedValues = arrayOf(LocalUriHandler provides urlLauncher),
|
||||||
arrayOf(
|
|
||||||
LocalUriHandler provides urlLauncher,
|
|
||||||
LocalHTMLConverter provides htmlConverter,
|
|
||||||
),
|
|
||||||
) {
|
) {
|
||||||
val currentUiMode = LocalConfiguration.current.uiMode
|
val currentUiMode = LocalConfiguration.current.uiMode
|
||||||
val systemBarsColor = MaterialTheme.colorScheme.surfaceColorAtNavigationBarElevation()
|
val systemBarsColor = MaterialTheme.colorScheme.surfaceColorAtNavigationBarElevation()
|
||||||
|
@ -211,6 +206,7 @@ fun LobstersApp(
|
||||||
postId = postId,
|
postId = postId,
|
||||||
getDetails = viewModel::getPostComments,
|
getDetails = viewModel::getPostComments,
|
||||||
postActions = postActions,
|
postActions = postActions,
|
||||||
|
htmlConverter = htmlConverter,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable(
|
composable(
|
||||||
|
|
|
@ -49,9 +49,9 @@ import java.time.temporal.TemporalAccessor
|
||||||
fun CommentsHeader(
|
fun CommentsHeader(
|
||||||
postDetails: ExtendedPostDetails,
|
postDetails: ExtendedPostDetails,
|
||||||
postActions: PostActions,
|
postActions: PostActions,
|
||||||
|
htmlConverter: HTMLConverter,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
val htmlConverter = LocalHTMLConverter.current
|
|
||||||
val uriHandler = LocalUriHandler.current
|
val uriHandler = LocalUriHandler.current
|
||||||
|
|
||||||
Surface(color = MaterialTheme.colorScheme.background, modifier = modifier) {
|
Surface(color = MaterialTheme.colorScheme.background, modifier = modifier) {
|
||||||
|
@ -133,10 +133,10 @@ fun PostLink(
|
||||||
@Composable
|
@Composable
|
||||||
fun CommentEntry(
|
fun CommentEntry(
|
||||||
comment: Comment,
|
comment: Comment,
|
||||||
|
htmlConverter: HTMLConverter,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
var expanded by remember(comment) { mutableStateOf(true) }
|
var expanded by remember(comment) { mutableStateOf(true) }
|
||||||
val htmlConverter = LocalHTMLConverter.current
|
|
||||||
val uriHandler = LocalUriHandler.current
|
val uriHandler = LocalUriHandler.current
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
|
|
|
@ -30,11 +30,18 @@ import dev.msfjarvis.claw.model.ExtendedPostDetails
|
||||||
private fun CommentsPageInternal(
|
private fun CommentsPageInternal(
|
||||||
details: ExtendedPostDetails,
|
details: ExtendedPostDetails,
|
||||||
postActions: PostActions,
|
postActions: PostActions,
|
||||||
|
htmlConverter: HTMLConverter,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
Surface(color = MaterialTheme.colorScheme.surfaceVariant) {
|
Surface(color = MaterialTheme.colorScheme.surfaceVariant) {
|
||||||
LazyColumn(modifier = modifier, contentPadding = PaddingValues(bottom = 24.dp)) {
|
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()) {
|
if (details.comments.isNotEmpty()) {
|
||||||
item {
|
item {
|
||||||
|
@ -49,7 +56,7 @@ private fun CommentsPageInternal(
|
||||||
if (index != 0) {
|
if (index != 0) {
|
||||||
Divider()
|
Divider()
|
||||||
}
|
}
|
||||||
CommentEntry(item)
|
CommentEntry(comment = item, htmlConverter = htmlConverter)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
item {
|
item {
|
||||||
|
@ -72,6 +79,7 @@ fun CommentsPage(
|
||||||
postId: String,
|
postId: String,
|
||||||
getDetails: suspend (String) -> ExtendedPostDetails,
|
getDetails: suspend (String) -> ExtendedPostDetails,
|
||||||
postActions: PostActions,
|
postActions: PostActions,
|
||||||
|
htmlConverter: HTMLConverter,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
val postDetails by
|
val postDetails by
|
||||||
|
@ -86,9 +94,10 @@ fun CommentsPage(
|
||||||
when (postDetails) {
|
when (postDetails) {
|
||||||
is Success<*> -> {
|
is Success<*> -> {
|
||||||
CommentsPageInternal(
|
CommentsPageInternal(
|
||||||
(postDetails as Success<ExtendedPostDetails>).data,
|
details = (postDetails as Success<ExtendedPostDetails>).data,
|
||||||
postActions,
|
postActions = postActions,
|
||||||
modifier.fillMaxSize(),
|
htmlConverter = htmlConverter,
|
||||||
|
modifier = modifier.fillMaxSize(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is Error -> {
|
is Error -> {
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
package dev.msfjarvis.claw.common.comments
|
package dev.msfjarvis.claw.common.comments
|
||||||
|
|
||||||
import androidx.compose.runtime.staticCompositionLocalOf
|
|
||||||
|
|
||||||
/** Defines a contract to convert strings of HTML to Markdown. */
|
/** Defines a contract to convert strings of HTML to Markdown. */
|
||||||
fun interface HTMLConverter {
|
fun interface HTMLConverter {
|
||||||
fun convertHTMLToMarkdown(html: String): String
|
fun convertHTMLToMarkdown(html: String): String
|
||||||
}
|
}
|
||||||
|
|
||||||
val LocalHTMLConverter = staticCompositionLocalOf<HTMLConverter> { error("To be provided") }
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
<SmellBaseline>
|
<SmellBaseline>
|
||||||
<ManuallySuppressedIssues></ManuallySuppressedIssues>
|
<ManuallySuppressedIssues></ManuallySuppressedIssues>
|
||||||
<CurrentIssues>
|
<CurrentIssues>
|
||||||
<ID>CompositionLocalAllowlist:HTMLConverter.kt$LocalHTMLConverter</ID>
|
|
||||||
<ID>MagicNumber:CommentEntry.kt$16</ID>
|
<ID>MagicNumber:CommentEntry.kt$16</ID>
|
||||||
<ID>MagicNumber:LobstersCard.kt$50</ID>
|
<ID>MagicNumber:LobstersCard.kt$50</ID>
|
||||||
<ID>MagicNumber:LobstersCard.kt$8</ID>
|
<ID>MagicNumber:LobstersCard.kt$8</ID>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue