From 535c8a580897014a8d3ea2df81d469ad3dbc1724 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 3 Oct 2022 12:15:44 +0530 Subject: [PATCH] refactor(common): pass `HTMLConverter` down as a parameter --- .../msfjarvis/claw/android/ui/LobstersApp.kt | 8 ++------ .../claw/common/comments/CommentEntry.kt | 4 ++-- .../claw/common/comments/Comments.kt | 19 ++++++++++++++----- .../claw/common/comments/HTMLConverter.kt | 4 ---- detekt-baselines/common.xml | 1 - 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt index 49f75028..5a42c800 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt +++ b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt @@ -38,7 +38,6 @@ import dev.msfjarvis.claw.android.viewmodel.ClawViewModel import dev.msfjarvis.claw.api.LobstersApi import dev.msfjarvis.claw.common.comments.CommentsPage 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.theme.LobstersTheme import dev.msfjarvis.claw.common.ui.decorations.ClawAppBar @@ -75,11 +74,7 @@ fun LobstersApp( LobstersTheme( dynamicColor = true, - providedValues = - arrayOf( - LocalUriHandler provides urlLauncher, - LocalHTMLConverter provides htmlConverter, - ), + providedValues = arrayOf(LocalUriHandler provides urlLauncher), ) { val currentUiMode = LocalConfiguration.current.uiMode val systemBarsColor = MaterialTheme.colorScheme.surfaceColorAtNavigationBarElevation() @@ -211,6 +206,7 @@ fun LobstersApp( postId = postId, getDetails = viewModel::getPostComments, postActions = postActions, + htmlConverter = htmlConverter, ) } composable( diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt index ddad691d..bce70fab 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt @@ -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 = diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt index a0186401..25495dc0 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt @@ -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).data, - postActions, - modifier.fillMaxSize(), + details = (postDetails as Success).data, + postActions = postActions, + htmlConverter = htmlConverter, + modifier = modifier.fillMaxSize(), ) } is Error -> { diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/HTMLConverter.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/HTMLConverter.kt index e1b5ceb5..b0eb0792 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/HTMLConverter.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/HTMLConverter.kt @@ -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 { error("To be provided") } diff --git a/detekt-baselines/common.xml b/detekt-baselines/common.xml index 510c3a53..e257e2f3 100644 --- a/detekt-baselines/common.xml +++ b/detekt-baselines/common.xml @@ -2,7 +2,6 @@ - CompositionLocalAllowlist:HTMLConverter.kt$LocalHTMLConverter MagicNumber:CommentEntry.kt$16 MagicNumber:LobstersCard.kt$50 MagicNumber:LobstersCard.kt$8