fix(posts): improve title rendering

This commit is contained in:
Diego Beraldin 2023-09-10 22:44:23 +02:00
parent 1b8d8828e6
commit c083627c2f
6 changed files with 50 additions and 9 deletions

View File

@ -65,7 +65,7 @@ fun PostCard(
) {
PostCardTitle(
modifier = Modifier.padding(top = Spacing.s),
post = post
text = post.title
)
PostCardSubtitle(
community = post.community,

View File

@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.github.diegoberaldin.raccoonforlemmy.core.markdown.compose.Markdown
import com.github.diegoberaldin.raccoonforlemmy.core.markdown.model.markdownColor
import com.github.diegoberaldin.raccoonforlemmy.core.markdown.model.markdownTypography
@Composable
fun PostCardBody(
@ -15,10 +16,20 @@ fun PostCardBody(
Markdown(
modifier = modifier,
content = text,
typography = markdownTypography(
h1 = MaterialTheme.typography.displayLarge,
h2 = MaterialTheme.typography.displayMedium,
h3 = MaterialTheme.typography.displaySmall,
h4 = MaterialTheme.typography.headlineMedium,
h5 = MaterialTheme.typography.headlineSmall,
h6 = MaterialTheme.typography.titleLarge,
text = MaterialTheme.typography.bodyMedium,
paragraph = MaterialTheme.typography.bodyMedium,
),
colors = markdownColor(
text = MaterialTheme.colorScheme.onSurfaceVariant,
backgroundCode = MaterialTheme.colorScheme.surfaceVariant,
)
),
)
}
}

View File

@ -4,17 +4,25 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.github.diegoberaldin.raccoonforlemmy.core.markdown.compose.Markdown
import com.github.diegoberaldin.raccoonforlemmy.core.markdown.model.markdownColor
import com.github.diegoberaldin.raccoonforlemmy.core.markdown.model.markdownTypography
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PostModel
@Composable
fun PostCardTitle(
post: PostModel,
text: String,
modifier: Modifier = Modifier,
) {
Text(
Markdown(
modifier = modifier,
text = post.title,
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant,
content = text,
typography = markdownTypography(
text = MaterialTheme.typography.displaySmall,
),
colors = markdownColor(
text = MaterialTheme.colorScheme.onSurfaceVariant,
backgroundCode = MaterialTheme.colorScheme.surfaceVariant,
),
)
}

View File

@ -232,7 +232,9 @@ class PostDetailScreen(
horizontal = Spacing.s,
),
) {
PostCardTitle(post)
PostCardTitle(
text = post.title
)
PostCardSubtitle(
community = post.community,
creator = post.creator?.copy(avatar = null),

View File

@ -7,6 +7,8 @@ data class PostModel(
val score: Int = 0,
val comments: Int = 0,
val thumbnailUrl: String? = null,
val url: String? = null,
val embedVideoUrl: String? = null,
val community: CommunityModel? = null,
val creator: UserModel? = null,
val saved: Boolean = false,

View File

@ -85,12 +85,14 @@ internal fun PostView.toModel() = PostModel(
score = counts.score,
comments = counts.comments,
thumbnailUrl = post.thumbnailUrl.orEmpty(),
url = post.url,
community = community.toModel(),
creator = creator.toModel(),
saved = saved,
myVote = myVote ?: 0,
publishDate = post.published,
nsfw = post.nsfw,
embedVideoUrl = post.embedVideoUrl
)
internal fun CommentView.toModel() = CommentModel(
@ -125,7 +127,16 @@ internal fun PersonMentionView.toModel() = PersonMentionModel(
id = post.id,
title = post.name,
text = post.body.orEmpty(),
score = counts.score,
thumbnailUrl = post.thumbnailUrl.orEmpty(),
url = post.url,
community = community.toModel(),
creator = creator.toModel(),
saved = saved,
myVote = myVote ?: 0,
publishDate = post.published,
nsfw = post.nsfw,
embedVideoUrl = post.embedVideoUrl
),
comment = CommentModel(
id = comment.id,
@ -147,9 +158,16 @@ internal fun CommentReplyView.toModel() = PersonMentionModel(
id = post.id,
title = post.name,
text = post.body.orEmpty(),
creator = UserModel(id = post.creatorId),
score = counts.score,
thumbnailUrl = post.thumbnailUrl.orEmpty(),
url = post.url,
community = community.toModel(),
creator = creator.toModel(),
saved = saved,
myVote = myVote ?: 0,
publishDate = post.published,
nsfw = post.nsfw,
embedVideoUrl = post.embedVideoUrl
),
comment = CommentModel(
id = comment.id,