Skip to content

Commit

Permalink
display user bio
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Apr 29, 2024
1 parent 15859f2 commit d69d509
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion anilist/src/commonMain/graphql/ViewerMutation.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
mutation ViewerMutation($adult: Boolean, $color: String) {
mutation ViewerMutation($adult: Boolean, $color: String, $html: Boolean) {
UpdateUser(displayAdultContent: $adult, profileColor: $color) {
id,
name,
about(asHtml: $html),
avatar {
medium,
large
Expand Down
3 changes: 2 additions & 1 deletion anilist/src/commonMain/graphql/ViewerQuery.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
query ViewerQuery {
query ViewerQuery($html: Boolean) {
Viewer {
id,
name,
about(asHtml: $html),
avatar {
medium,
large
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.serialization.Serializable
data class User(
val id: Int,
val name: String,
val description: String? = null,
val avatar: Avatar = Avatar(),
val banner: String? = null,
val displayAdultContent: Boolean = false,
Expand All @@ -16,6 +17,7 @@ data class User(
constructor(query: ViewerQuery.Viewer) : this(
id = query.id,
name = query.name,
description = query.about?.ifBlank { null },
avatar = query.avatar.let(::Avatar),
banner = query.bannerImage?.ifBlank { null },
displayAdultContent = query.options?.displayAdultContent ?: false,
Expand All @@ -25,6 +27,7 @@ data class User(
constructor(mutation: ViewerMutation.UpdateUser) : this(
id = mutation.id,
name = mutation.name,
description = mutation.about?.ifBlank { null },
avatar = mutation.avatar.let(::Avatar),
banner = mutation.bannerImage?.ifBlank { null },
displayAdultContent = mutation.options?.displayAdultContent ?: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class UserHelper(
val isLoggedIn: Flow<Boolean> = userSettings.isAniListLoggedIn.distinctUntilChanged()

private val changedUser: MutableStateFlow<User?> = MutableStateFlow(null)
private val userQuery = client.query(ViewerQuery()).toFlow()
private val userQuery = client.query(
ViewerQuery(
html = Optional.present(true)
)
).toFlow()
private val defaultUser = isLoggedIn.transform { loggedIn ->
if (loggedIn) {
emitAll(
Expand Down Expand Up @@ -83,7 +87,8 @@ class UserHelper(
changedUser.emit(
client.mutation(
ViewerMutation(
adult = Optional.present(value)
adult = Optional.present(value),
html = Optional.present(true)
)
).execute().data?.UpdateUser?.let(::User)
)
Expand All @@ -96,7 +101,8 @@ class UserHelper(
changedUser.emit(
client.mutation(
ViewerMutation(
color = Optional.present(value.label)
color = Optional.present(value.label),
html = Optional.present(true)
)
).execute().data?.UpdateUser?.let(::User)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -36,6 +37,7 @@ import dev.chrisbanes.haze.haze
import dev.datlag.aniflow.LocalHaze
import dev.datlag.aniflow.LocalPaddingValues
import dev.datlag.aniflow.SharedRes
import dev.datlag.aniflow.common.htmlToAnnotatedString
import dev.datlag.aniflow.common.plus
import dev.datlag.aniflow.common.toComposeColor
import dev.datlag.aniflow.common.toComposeString
Expand Down Expand Up @@ -85,6 +87,12 @@ fun SettingsScreen(component: SettingsComponent) {
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold
)
u.description?.let {
Text(
modifier = Modifier.padding(bottom = 8.dp),
text = it.htmlToAnnotatedString()
)
}
}
} ?: Text(
modifier = Modifier.padding(bottom = 8.dp),
Expand Down Expand Up @@ -127,7 +135,7 @@ fun SettingsScreen(component: SettingsComponent) {
item {
val selectedColor by component.selectedColor.collectAsStateWithLifecycle(null)
val useCase = rememberUseCaseState()
val colors = AppSettings.Color.all.toList()
val colors = remember { AppSettings.Color.all.toList() }

OptionDialog(
state = useCase,
Expand All @@ -138,6 +146,7 @@ fun SettingsScreen(component: SettingsComponent) {
imageVector = Icons.Filled.Circle,
tint = it.toComposeColor()
),
selected = it == selectedColor,
titleText = stringResource(it.toComposeString())
)
},
Expand Down

0 comments on commit d69d509

Please sign in to comment.