mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 23:27:04 +05:30
chore(deps): update dependency com.facebook:ktfmt to v0.47
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
050007ff1b
commit
a187752659
33 changed files with 118 additions and 290 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright © 2021-2023 Harsh Shandilya.
|
||||
* Copyright © 2021-2024 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
|
@ -60,9 +60,7 @@ internal fun CommentsHeader(
|
|||
) {
|
||||
val uriHandler = LocalUriHandler.current
|
||||
val linkMetadata by
|
||||
produceState(
|
||||
initialValue = LinkMetadata(postDetails.url, null),
|
||||
) {
|
||||
produceState(initialValue = LinkMetadata(postDetails.url, null)) {
|
||||
runSuspendCatching { postActions.getLinkMetadata(postDetails.url) }
|
||||
.onSuccess { metadata -> value = metadata }
|
||||
}
|
||||
|
@ -105,10 +103,7 @@ internal fun CommentsHeader(
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun PostLink(
|
||||
linkMetadata: LinkMetadata,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
private fun PostLink(linkMetadata: LinkMetadata, modifier: Modifier = Modifier) {
|
||||
Box(
|
||||
modifier.background(
|
||||
color = MaterialTheme.colorScheme.secondary,
|
||||
|
@ -155,7 +150,7 @@ internal fun CommentEntry(
|
|||
end = CommentEntryPadding,
|
||||
top = CommentEntryPadding,
|
||||
bottom = CommentEntryPadding,
|
||||
),
|
||||
)
|
||||
) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Submitter(
|
||||
|
@ -175,7 +170,7 @@ internal fun CommentEntry(
|
|||
if (commentNode.isExpanded) {
|
||||
ThemedRichText(
|
||||
text = htmlConverter.convertHTMLToMarkdown(comment.comment),
|
||||
modifier = Modifier.padding(top = 8.dp)
|
||||
modifier = Modifier.padding(top = 8.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -228,11 +223,7 @@ fun buildCommenterString(
|
|||
if (isUnread) {
|
||||
append(' ')
|
||||
withStyle(
|
||||
style =
|
||||
SpanStyle(
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
)
|
||||
style = SpanStyle(fontWeight = FontWeight.Bold, color = MaterialTheme.colorScheme.error)
|
||||
) {
|
||||
append("(unread)")
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright © 2022-2023 Harsh Shandilya.
|
||||
* Copyright © 2022-2024 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
|
@ -17,7 +17,7 @@ internal data class CommentNode(
|
|||
val children: MutableList<CommentNode> = mutableListOf(),
|
||||
val isUnread: Boolean = false,
|
||||
var isExpanded: Boolean = true,
|
||||
var indentLevel: Int
|
||||
var indentLevel: Int,
|
||||
) {
|
||||
fun addChild(child: CommentNode) {
|
||||
if (comment.shortId == child.comment.parentComment) {
|
||||
|
@ -32,7 +32,7 @@ internal data class CommentNode(
|
|||
|
||||
internal fun createListNode(
|
||||
comments: List<Comment>,
|
||||
commentState: PostComments?
|
||||
commentState: PostComments?,
|
||||
): MutableList<CommentNode> {
|
||||
val commentNodes = mutableListOf<CommentNode>()
|
||||
val isUnread = { id: String -> commentState?.commentIds?.contains(id) == false }
|
||||
|
@ -43,7 +43,7 @@ internal fun createListNode(
|
|||
CommentNode(
|
||||
comment = comments[i],
|
||||
isUnread = isUnread(comments[i].shortId),
|
||||
indentLevel = 1
|
||||
indentLevel = 1,
|
||||
)
|
||||
)
|
||||
} else {
|
||||
|
@ -52,7 +52,7 @@ internal fun createListNode(
|
|||
CommentNode(
|
||||
comment = comments[i],
|
||||
isUnread = isUnread(comments[i].shortId),
|
||||
indentLevel = it.indentLevel + 1
|
||||
indentLevel = it.indentLevel + 1,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -86,11 +86,7 @@ internal fun LazyListScope.nodes(
|
|||
toggleExpanded: (CommentNode) -> Unit,
|
||||
) {
|
||||
nodes.forEach { node ->
|
||||
node(
|
||||
node = node,
|
||||
htmlConverter = htmlConverter,
|
||||
toggleExpanded = toggleExpanded,
|
||||
)
|
||||
node(node = node, htmlConverter = htmlConverter, toggleExpanded = toggleExpanded)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,18 +100,10 @@ private fun LazyListScope.node(
|
|||
return
|
||||
}
|
||||
item {
|
||||
CommentEntry(
|
||||
commentNode = node,
|
||||
htmlConverter = htmlConverter,
|
||||
toggleExpanded = toggleExpanded,
|
||||
)
|
||||
CommentEntry(commentNode = node, htmlConverter = htmlConverter, toggleExpanded = toggleExpanded)
|
||||
HorizontalDivider()
|
||||
}
|
||||
if (node.children.isNotEmpty()) {
|
||||
nodes(
|
||||
node.children,
|
||||
htmlConverter = htmlConverter,
|
||||
toggleExpanded = toggleExpanded,
|
||||
)
|
||||
nodes(node.children, htmlConverter = htmlConverter, toggleExpanded = toggleExpanded)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright © 2021-2023 Harsh Shandilya.
|
||||
* Copyright © 2021-2024 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
|
@ -73,17 +73,13 @@ fun LobstersCard(
|
|||
.fillMaxWidth()
|
||||
.clickable { postActions.viewPost(post.shortId, post.url, post.commentsUrl) }
|
||||
.background(MaterialTheme.colorScheme.background)
|
||||
.padding(start = 16.dp, top = 16.dp, end = 4.dp, bottom = 16.dp),
|
||||
.padding(start = 16.dp, top = 16.dp, end = 4.dp, bottom = 16.dp)
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
PostDetails(
|
||||
modifier = Modifier.weight(1f),
|
||||
post = post,
|
||||
isRead = isRead,
|
||||
)
|
||||
PostDetails(modifier = Modifier.weight(1f), post = post, isRead = isRead)
|
||||
Column(
|
||||
modifier = Modifier.wrapContentHeight(),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
|
@ -126,11 +122,7 @@ fun PostDetails(post: SavedPost, isRead: Boolean, modifier: Modifier = Modifier)
|
|||
}
|
||||
|
||||
@Composable
|
||||
internal fun PostTitle(
|
||||
title: String,
|
||||
isRead: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
internal fun PostTitle(title: String, isRead: Boolean, modifier: Modifier = Modifier) {
|
||||
Text(
|
||||
text = title,
|
||||
modifier = modifier,
|
||||
|
@ -169,10 +161,7 @@ internal fun Submitter(
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun SaveButton(
|
||||
isSaved: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
private fun SaveButton(isSaved: Boolean, modifier: Modifier = Modifier) {
|
||||
Crossfade(targetState = isSaved, label = "save-button") { saved ->
|
||||
Box(modifier = modifier.padding(12.dp)) {
|
||||
Icon(
|
||||
|
@ -186,10 +175,7 @@ private fun SaveButton(
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun CommentsButton(
|
||||
commentCount: Int?,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
private fun CommentsButton(commentCount: Int?, modifier: Modifier = Modifier) {
|
||||
BadgedBox(
|
||||
modifier = modifier.padding(12.dp),
|
||||
badge = {
|
||||
|
@ -219,10 +205,7 @@ private fun CommentsButton(
|
|||
|
||||
@Composable
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
internal fun TagRow(
|
||||
tags: ImmutableList<String>,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
internal fun TagRow(tags: ImmutableList<String>, modifier: Modifier = Modifier) {
|
||||
FlowRow(
|
||||
modifier = modifier,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
|
@ -233,10 +216,7 @@ internal fun TagRow(
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun TagText(
|
||||
tag: String,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
private fun TagText(tag: String, modifier: Modifier = Modifier) {
|
||||
Text(
|
||||
text = tag,
|
||||
modifier =
|
||||
|
|
|
@ -23,10 +23,7 @@ import dev.msfjarvis.claw.common.theme.LobstersTheme
|
|||
import dev.msfjarvis.claw.common.ui.preview.ThemePreviews
|
||||
|
||||
@Composable
|
||||
internal fun ThemedRichText(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
internal fun ThemedRichText(text: String, modifier: Modifier = Modifier) {
|
||||
val linkStyle =
|
||||
SpanStyle(
|
||||
background = MaterialTheme.colorScheme.surfaceVariant,
|
||||
|
@ -39,10 +36,7 @@ internal fun ThemedRichText(
|
|||
LocalTextStyle provides MaterialTheme.typography.bodyLarge,
|
||||
LocalContentColor provides MaterialTheme.colorScheme.onBackground,
|
||||
) {
|
||||
RichText(
|
||||
modifier = modifier,
|
||||
style = RichTextStyle.Default.copy(stringStyle = stringStyle),
|
||||
) {
|
||||
RichText(modifier = modifier, style = RichTextStyle.Default.copy(stringStyle = stringStyle)) {
|
||||
Markdown(text)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright © 2022-2023 Harsh Shandilya.
|
||||
* Copyright © 2022-2024 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
|
@ -29,11 +29,7 @@ import dev.msfjarvis.claw.common.ui.preview.ThemePreviews
|
|||
import io.github.aakira.napier.Napier
|
||||
|
||||
@Composable
|
||||
fun NetworkError(
|
||||
label: String,
|
||||
error: Throwable,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
fun NetworkError(label: String, error: Throwable, modifier: Modifier = Modifier) {
|
||||
LaunchedEffect(true) { Napier.e(error, "NetworkError") { "Failed to load posts" } }
|
||||
var showDialog by remember { mutableStateOf(false) }
|
||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp), modifier = modifier) {
|
||||
|
@ -60,15 +56,10 @@ fun NetworkError(
|
|||
Modifier.clickable {
|
||||
clipboard.setText(AnnotatedString(error.stackTraceToString()))
|
||||
showDialog = false
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
text = "${error.message}",
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
)
|
||||
}
|
||||
text = { Text(text = "${error.message}", style = MaterialTheme.typography.bodyLarge) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright © 2023 Harsh Shandilya.
|
||||
* Copyright © 2023-2024 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
|
@ -45,7 +45,7 @@ fun PasswordField(
|
|||
if (isPasswordVisible) rememberVectorPainter(Icons.Filled.VisibilityOff)
|
||||
else rememberVectorPainter(Icons.Filled.Visibility),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.clickable { isPasswordVisible = !isPasswordVisible }
|
||||
modifier = Modifier.clickable { isPasswordVisible = !isPasswordVisible },
|
||||
)
|
||||
},
|
||||
modifier = modifier,
|
||||
|
@ -57,10 +57,6 @@ fun PasswordField(
|
|||
private fun PasswordFieldPreview() {
|
||||
LobstersTheme {
|
||||
var value by remember { mutableStateOf("") }
|
||||
PasswordField(
|
||||
value = value,
|
||||
label = "Password",
|
||||
onValueChange = { value = it },
|
||||
)
|
||||
PasswordField(value = value, label = "Password", onValueChange = { value = it })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright © 2023 Harsh Shandilya.
|
||||
* Copyright © 2023-2024 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
|
@ -59,10 +59,7 @@ fun SearchBar(
|
|||
},
|
||||
keyboardActions = KeyboardActions(onSearch = { onSearch(value) }),
|
||||
keyboardOptions =
|
||||
KeyboardOptions(
|
||||
keyboardType = KeyboardType.Text,
|
||||
imeAction = ImeAction.Search,
|
||||
),
|
||||
KeyboardOptions(keyboardType = KeyboardType.Text, imeAction = ImeAction.Search),
|
||||
singleLine = true,
|
||||
modifier = modifier.focusable().focusRequester(focusRequester),
|
||||
)
|
||||
|
@ -81,7 +78,7 @@ fun SearchBarPreview() {
|
|||
value = value,
|
||||
onValueChange = { value = it },
|
||||
onSearch = {},
|
||||
modifier = Modifier.align(Alignment.TopCenter).fillMaxWidth()
|
||||
modifier = Modifier.align(Alignment.TopCenter).fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,7 @@ import dev.msfjarvis.claw.common.ui.preview.ThemePreviews
|
|||
import dev.msfjarvis.claw.common.ui.surfaceColorAtNavigationBarElevation
|
||||
|
||||
@Composable
|
||||
fun MonthHeader(
|
||||
label: String,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
fun MonthHeader(label: String, modifier: Modifier = Modifier) {
|
||||
Box(
|
||||
modifier
|
||||
.fillMaxWidth()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright © 2022-2023 Harsh Shandilya.
|
||||
* Copyright © 2022-2024 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
|
@ -50,12 +50,8 @@ fun UserProfile(
|
|||
.fold(
|
||||
success = { profile -> value = Success(profile) },
|
||||
failure = {
|
||||
value =
|
||||
Error(
|
||||
error = it,
|
||||
description = "Failed to load profile for $username",
|
||||
)
|
||||
}
|
||||
value = Error(error = it, description = "Failed to load profile for $username")
|
||||
},
|
||||
)
|
||||
}
|
||||
when (user) {
|
||||
|
@ -81,10 +77,7 @@ fun UserProfile(
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun UserProfileInternal(
|
||||
user: User,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
private fun UserProfileInternal(user: User, modifier: Modifier = Modifier) {
|
||||
Surface(modifier = modifier) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
|
@ -97,17 +90,10 @@ private fun UserProfileInternal(
|
|||
contentDescription = "Avatar of ${user.username}",
|
||||
modifier = Modifier.requiredSize(120.dp).clip(CircleShape),
|
||||
)
|
||||
Text(
|
||||
text = user.username,
|
||||
style = MaterialTheme.typography.displaySmall,
|
||||
)
|
||||
ThemedRichText(
|
||||
text = user.about,
|
||||
)
|
||||
Text(text = user.username, style = MaterialTheme.typography.displaySmall)
|
||||
ThemedRichText(text = user.about)
|
||||
user.invitedBy?.let { invitedBy ->
|
||||
ThemedRichText(
|
||||
text = "Invited by [${invitedBy}](https://lobste.rs/u/${user.invitedBy})",
|
||||
)
|
||||
ThemedRichText(text = "Invited by [${invitedBy}](https://lobste.rs/u/${user.invitedBy})")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue