mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 21:07:04 +05:30
refactor: simplify argument passing
This commit is contained in:
parent
79aba9a187
commit
ccfcd48438
5 changed files with 17 additions and 12 deletions
|
@ -49,7 +49,6 @@ import java.time.temporal.TemporalAccessor
|
|||
@Composable
|
||||
fun CommentsHeader(
|
||||
postDetails: LobstersPostDetails,
|
||||
getLinkMetadata: suspend (String) -> LinkMetadata,
|
||||
postActions: PostActions,
|
||||
htmlConverter: HTMLConverter,
|
||||
modifier: Modifier = Modifier,
|
||||
|
@ -59,7 +58,7 @@ fun CommentsHeader(
|
|||
produceState(
|
||||
initialValue = LinkMetadata(postDetails.url, null, null),
|
||||
) {
|
||||
value = getLinkMetadata(postDetails.url)
|
||||
value = postActions.getLinkMetadata(postDetails.url)
|
||||
}
|
||||
|
||||
Surface(color = MaterialTheme.colorScheme.background, modifier = modifier) {
|
||||
|
|
|
@ -24,13 +24,11 @@ import dev.msfjarvis.claw.common.NetworkState.Success
|
|||
import dev.msfjarvis.claw.common.posts.PostActions
|
||||
import dev.msfjarvis.claw.common.ui.NetworkError
|
||||
import dev.msfjarvis.claw.common.ui.ProgressBar
|
||||
import dev.msfjarvis.claw.model.LinkMetadata
|
||||
import dev.msfjarvis.claw.model.LobstersPostDetails
|
||||
|
||||
@Composable
|
||||
private fun CommentsPageInternal(
|
||||
details: LobstersPostDetails,
|
||||
getLinkMetadata: suspend (String) -> LinkMetadata,
|
||||
postActions: PostActions,
|
||||
htmlConverter: HTMLConverter,
|
||||
modifier: Modifier = Modifier,
|
||||
|
@ -40,7 +38,6 @@ private fun CommentsPageInternal(
|
|||
item {
|
||||
CommentsHeader(
|
||||
postDetails = details,
|
||||
getLinkMetadata = getLinkMetadata,
|
||||
postActions = postActions,
|
||||
htmlConverter = htmlConverter,
|
||||
)
|
||||
|
@ -76,19 +73,17 @@ private fun CommentsPageInternal(
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST", "LongParameterList")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Composable
|
||||
fun CommentsPage(
|
||||
postId: String,
|
||||
getDetails: suspend (String) -> LobstersPostDetails,
|
||||
getLinkMetadata: suspend (String) -> LinkMetadata,
|
||||
postActions: PostActions,
|
||||
htmlConverter: HTMLConverter,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val postDetails by
|
||||
produceState<NetworkState>(Loading) {
|
||||
runCatching { getDetails(postId) }
|
||||
runCatching { postActions.getComments(postId) }
|
||||
.fold(
|
||||
onSuccess = { details -> value = Success(details) },
|
||||
onFailure = { value = Error(error = it, description = "Failed to load comments") }
|
||||
|
@ -99,7 +94,6 @@ fun CommentsPage(
|
|||
is Success<*> -> {
|
||||
CommentsPageInternal(
|
||||
details = (postDetails as Success<LobstersPostDetails>).data,
|
||||
getLinkMetadata = getLinkMetadata,
|
||||
postActions = postActions,
|
||||
htmlConverter = htmlConverter,
|
||||
modifier = modifier.fillMaxSize(),
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package dev.msfjarvis.claw.common.posts
|
||||
|
||||
import dev.msfjarvis.claw.database.local.SavedPost
|
||||
import dev.msfjarvis.claw.model.LinkMetadata
|
||||
import dev.msfjarvis.claw.model.LobstersPostDetails
|
||||
|
||||
interface PostActions {
|
||||
fun viewPost(postUrl: String, commentsUrl: String)
|
||||
fun viewComments(postId: String)
|
||||
fun viewCommentsPage(commentsUrl: String)
|
||||
fun toggleSave(post: SavedPost)
|
||||
suspend fun getComments(postId: String): LobstersPostDetails
|
||||
suspend fun getLinkMetadata(url: String): LinkMetadata
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue