mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 11:47:04 +05:30
all: move Markdown rendering to common module
This commit is contained in:
parent
36618690e3
commit
b3588e97e7
6 changed files with 13 additions and 14 deletions
|
@ -23,7 +23,6 @@ dependencies {
|
|||
implementation(libs.androidx.lifecycle.compose)
|
||||
implementation(libs.androidx.navigation.compose)
|
||||
implementation(libs.androidx.paging.compose)
|
||||
implementation(libs.multiplatform.markdown.android)
|
||||
implementation(libs.copydown)
|
||||
implementation(libs.dagger.hilt.android)
|
||||
implementation(libs.sqldelight.extensions.coroutines)
|
||||
|
|
|
@ -28,7 +28,6 @@ import com.google.accompanist.insets.ProvideWindowInsets
|
|||
import com.google.accompanist.insets.navigationBarsPadding
|
||||
import com.google.accompanist.insets.statusBarsPadding
|
||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
import com.mikepenz.markdown.Markdown
|
||||
import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
|
||||
import dev.msfjarvis.claw.common.comments.CommentsPage
|
||||
import dev.msfjarvis.claw.common.posts.PostActions
|
||||
|
@ -127,10 +126,7 @@ fun LobstersApp(
|
|||
CommentsPage(
|
||||
postId = requireNotNull(backStackEntry.arguments?.getString("postId")),
|
||||
getDetails = viewModel::getPostComments,
|
||||
renderMarkdown = { source, modifier ->
|
||||
val markdown = copydown.convert(source)
|
||||
Markdown(markdown, modifier = modifier)
|
||||
},
|
||||
htmlToMarkdown = { source -> copydown.convert(source) },
|
||||
paddingValues = paddingValues,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ kotlin {
|
|||
api(compose.material)
|
||||
api(projects.database)
|
||||
api(projects.model)
|
||||
implementation(libs.multiplatform.markdown)
|
||||
}
|
||||
}
|
||||
sourceSets["androidMain"].apply {
|
||||
|
|
|
@ -17,6 +17,7 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.mikepenz.markdown.Markdown
|
||||
import dev.msfjarvis.claw.common.posts.PostDetails
|
||||
import dev.msfjarvis.claw.common.posts.SubmitterName
|
||||
import dev.msfjarvis.claw.common.posts.toDbModel
|
||||
|
@ -26,6 +27,7 @@ import dev.msfjarvis.claw.model.LobstersPostDetails
|
|||
@Composable
|
||||
fun CommentsHeader(
|
||||
postDetails: LobstersPostDetails,
|
||||
htmlToMarkdown: (html: String) -> String,
|
||||
) {
|
||||
Surface {
|
||||
Column(
|
||||
|
@ -35,6 +37,7 @@ fun CommentsHeader(
|
|||
PostDetails(
|
||||
post = postDetails.toDbModel(),
|
||||
)
|
||||
Markdown(htmlToMarkdown(postDetails.description))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +45,7 @@ fun CommentsHeader(
|
|||
@Composable
|
||||
fun CommentEntry(
|
||||
comment: Comment,
|
||||
renderMarkdown: @Composable (comment: String, modifier: Modifier) -> Unit,
|
||||
htmlToMarkdown: (html: String) -> String,
|
||||
) {
|
||||
val indentLevel = comment.indentLevel.toInt() - 1
|
||||
|
||||
|
@ -55,7 +58,7 @@ fun CommentEntry(
|
|||
avatarUrl = "https://lobste.rs/${comment.user.avatarUrl}",
|
||||
contentDescription = "Submitted by ${comment.user.username}",
|
||||
)
|
||||
renderMarkdown(comment.comment, Modifier.padding(top = 8.dp))
|
||||
Markdown(htmlToMarkdown(comment.comment), Modifier.padding(top = 8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,15 +28,15 @@ import dev.msfjarvis.lobsters.ui.comments.NetworkState
|
|||
@Composable
|
||||
private fun CommentsPageInternal(
|
||||
details: LobstersPostDetails,
|
||||
renderMarkdown: @Composable (comment: String, modifier: Modifier) -> Unit,
|
||||
htmlToMarkdown: (html: String) -> String,
|
||||
bottomPadding: Dp,
|
||||
) {
|
||||
LazyColumn(Modifier.padding(bottom = bottomPadding)) {
|
||||
item { CommentsHeader(postDetails = details) }
|
||||
item { CommentsHeader(postDetails = details, htmlToMarkdown = htmlToMarkdown) }
|
||||
|
||||
item { Spacer(modifier = Modifier.height(8.dp)) }
|
||||
|
||||
items(details.comments) { item -> CommentEntry(item, renderMarkdown) }
|
||||
items(details.comments) { item -> CommentEntry(item, htmlToMarkdown) }
|
||||
|
||||
item { Divider(color = Color.Gray.copy(0.4f)) }
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ private fun CommentsPageInternal(
|
|||
fun CommentsPage(
|
||||
postId: String,
|
||||
getDetails: suspend (String) -> LobstersPostDetails,
|
||||
renderMarkdown: @Composable (comment: String, modifier: Modifier) -> Unit,
|
||||
htmlToMarkdown: (html: String) -> String,
|
||||
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,
|
||||
renderMarkdown,
|
||||
htmlToMarkdown,
|
||||
paddingValues.calculateBottomPadding(),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ dagger-hilt-android = { module = "com.google.dagger:hilt-android", version.ref =
|
|||
dagger-hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hilt" }
|
||||
dagger-hilt-core = { module = "com.google.dagger:hilt-core", version.ref = "hilt" }
|
||||
|
||||
multiplatform-markdown-android = "com.mikepenz:multiplatform-markdown-renderer-android:0.1.0"
|
||||
multiplatform-markdown = "com.mikepenz:multiplatform-markdown-renderer:0.1.0"
|
||||
copydown = "io.github.furstenheim:copy_down:1.0"
|
||||
|
||||
multiplatform-paging = "io.github.kuuuurt:multiplatform-paging:0.4.5"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue