Skip to content

Commit

Permalink
render user bio as markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 1, 2024
1 parent 7f9d851 commit 17c78f3
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 39 deletions.
3 changes: 1 addition & 2 deletions anilist/src/commonMain/graphql/ViewerMutation.graphql
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
mutation ViewerMutation(
$adult: Boolean,
$color: String,
$html: Boolean,
$title: UserTitleLanguage,
$char: UserStaffNameLanguage
) {
UpdateUser(displayAdultContent: $adult, profileColor: $color, titleLanguage: $title, staffNameLanguage: $char) {
id,
name,
about(asHtml: $html),
about(asHtml: false),
avatar {
medium,
large
Expand Down
4 changes: 2 additions & 2 deletions anilist/src/commonMain/graphql/ViewerQuery.graphql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
query ViewerQuery($html: Boolean) {
query ViewerQuery {
Viewer {
id,
name,
about(asHtml: $html),
about(asHtml: false),
avatar {
medium,
large
Expand Down
1 change: 1 addition & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ kotlin {
implementation(libs.kasechange)

implementation(libs.kache)
implementation(libs.markdown.renderer)

implementation("dev.datlag.sheets-compose-dialogs:rating:2.0.0-SNAPSHOT")
implementation("dev.datlag.sheets-compose-dialogs:option:2.0.0-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ data object StateSaver {
_popularNextState
) { t1, t2, t3, t4 ->
t1.isLoadingOrWaiting && t2.isLoadingOrWaiting && t3.isLoadingOrWaiting && t4.isLoadingOrWaiting
}.distinctUntilChanged()
}.flowOn(ioDispatcher()).distinctUntilChanged()

fun updateAiring(state: AiringTodayStateMachine.State) = _airingState.updateAndGet {
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import dev.datlag.aniflow.common.toSettings
import dev.datlag.aniflow.model.safeFirstOrNull
import dev.datlag.aniflow.settings.Settings
import dev.datlag.tooling.async.suspendCatching
import dev.datlag.tooling.compose.ioDispatcher
import dev.datlag.tooling.compose.withIOContext
import dev.datlag.tooling.compose.withMainContext
import kotlinx.coroutines.flow.*
Expand All @@ -37,10 +38,8 @@ class UserHelper(

private val changedUser: MutableStateFlow<User?> = MutableStateFlow(null)
private val userQuery = client.query(
ViewerQuery(
html = Optional.present(true)
)
).toFlow()
ViewerQuery()
).toFlow().flowOn(ioDispatcher())
private val defaultUser = isLoggedIn.transform { loggedIn ->
if (loggedIn) {
emitAll(
Expand All @@ -51,14 +50,14 @@ class UserHelper(
} else {
emit(null)
}
}
}.flowOn(ioDispatcher())
private val latestUser = defaultUser.transform { default ->
emit(default)
emitAll(changedUser.filterNotNull().map { changed ->
changedUser.update { null }
changed
})
}
}.flowOn(ioDispatcher())

val user = latestUser.transform { user ->
emit(
Expand All @@ -71,15 +70,14 @@ class UserHelper(
)
}
)
}
}.flowOn(ioDispatcher())

suspend fun updateAdultSetting(value: Boolean) {
appSettings.setAdultContent(value)
changedUser.emit(
client.mutation(
ViewerMutation(
adult = Optional.present(value),
html = Optional.present(true)
adult = Optional.present(value)
)
).execute().data?.UpdateUser?.let(::User)
)
Expand All @@ -92,8 +90,7 @@ class UserHelper(
changedUser.emit(
client.mutation(
ViewerMutation(
color = Optional.present(value.label),
html = Optional.present(true)
color = Optional.present(value.label)
)
).execute().data?.UpdateUser?.let(::User)
)
Expand All @@ -107,8 +104,7 @@ class UserHelper(
changedUser.emit(
client.mutation(
ViewerMutation(
title = Optional.presentIfNotNull(value.toMutation()),
html = Optional.present(true)
title = Optional.presentIfNotNull(value.toMutation())
)
).execute().data?.UpdateUser?.let(::User)
)
Expand All @@ -122,8 +118,7 @@ class UserHelper(
changedUser.emit(
client.mutation(
ViewerMutation(
char = Optional.presentIfNotNull(value.toMutation()),
html = Optional.present(true)
char = Optional.presentIfNotNull(value.toMutation())
)
).execute().data?.UpdateUser?.let(::User)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class RootComponent(
}

fun onLogin(accessToken: String, expiresIn: Int?) {
launchDefault {
launchIO {
userHelper.saveLogin(accessToken, expiresIn)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HomeScreenComponent(
) : HomeComponent, ComponentContext by componentContext {

private val appSettings by di.instance<Settings.PlatformAppSettings>()
override val titleLanguage: Flow<SettingsTitle?> = appSettings.titleLanguage
override val titleLanguage: Flow<SettingsTitle?> = appSettings.titleLanguage.flowOn(ioDispatcher())

private val airingTodayStateMachine by di.instance<AiringTodayStateMachine>()
override val airingState: Flow<AiringTodayStateMachine.State> = airingTodayStateMachine.state.map {
Expand Down Expand Up @@ -88,7 +88,7 @@ class HomeScreenComponent(
}

override fun trace(channel: ByteArray) {
launchDefault {
launchIO {
traceStateMachine.dispatch(TraceStateMachine.Action.Load(channel))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.maxkeppeler.sheets.option.models.DisplayMode
import com.maxkeppeler.sheets.option.models.Option
import com.maxkeppeler.sheets.option.models.OptionConfig
import com.maxkeppeler.sheets.option.models.OptionSelection
import com.mikepenz.markdown.m3.Markdown
import dev.chrisbanes.haze.haze
import dev.datlag.aniflow.LocalHaze
import dev.datlag.aniflow.LocalPaddingValues
Expand Down Expand Up @@ -91,9 +92,9 @@ fun SettingsScreen(component: SettingsComponent) {
fontWeight = FontWeight.Bold
)
u.description?.let {
Text(
modifier = Modifier.padding(bottom = 8.dp),
text = it.htmlToAnnotatedString()
Markdown(
modifier = Modifier.padding(bottom = 16.dp),
content = it
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class SettingsScreenComponent(
private val appSettings by di.instance<Settings.PlatformAppSettings>()
private val userHelper by di.instance<UserHelper>()

override val user: Flow<User?> = userHelper.user
override val adultContent: Flow<Boolean> = appSettings.adultContent
override val selectedColor: Flow<SettingsColor?> = appSettings.color
override val selectedTitleLanguage: Flow<SettingsTitle?> = appSettings.titleLanguage
override val selectedCharLanguage: Flow<SettingsChar?> = appSettings.charLanguage
override val user: Flow<User?> = userHelper.user.flowOn(ioDispatcher())
override val adultContent: Flow<Boolean> = appSettings.adultContent.flowOn(ioDispatcher())
override val selectedColor: Flow<SettingsColor?> = appSettings.color.flowOn(ioDispatcher())
override val selectedTitleLanguage: Flow<SettingsTitle?> = appSettings.titleLanguage.flowOn(ioDispatcher())
override val selectedCharLanguage: Flow<SettingsChar?> = appSettings.charLanguage.flowOn(ioDispatcher())

@Composable
override fun render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class MediumScreenComponent(
private val appSettings by di.instance<Settings.PlatformAppSettings>()
private val userHelper by di.instance<UserHelper>()

override val titleLanguage: Flow<SettingsTitle?> = appSettings.titleLanguage
override val charLanguage: Flow<CharLanguage?> = appSettings.charLanguage
override val titleLanguage: Flow<SettingsTitle?> = appSettings.titleLanguage.flowOn(ioDispatcher())
override val charLanguage: Flow<CharLanguage?> = appSettings.charLanguage.flowOn(ioDispatcher())

private val mediumStateMachine = MediumStateMachine(
client = aniListClient,
Expand Down Expand Up @@ -229,7 +229,7 @@ class MediumScreenComponent(
}

override fun rate(onLoggedIn: () -> Unit) {
launchDefault {
launchIO {
val currentRating = rating.safeFirstOrNull() ?: initialMedium.entry?.score?.toInt() ?: -1
if (currentRating <= -1) {
requestMediaListEntry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CharacterDialogComponent(
)

private val appSettings by di.instance<Settings.PlatformAppSettings>()
override val charLanguage: Flow<CharLanguage?> = appSettings.charLanguage
override val charLanguage: Flow<CharLanguage?> = appSettings.charLanguage.flowOn(ioDispatcher())

override val state = characterStateMachine.state.flowOn(
context = ioDispatcher()
Expand Down Expand Up @@ -101,7 +101,7 @@ class CharacterDialogComponent(
}

override fun retry() {
launchDefault {
launchIO {
characterStateMachine.dispatch(CharacterStateMachine.Action.Retry)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import dev.datlag.tooling.async.scopeCatching
import dev.datlag.tooling.async.suspendCatching
import dev.datlag.tooling.compose.ioDispatcher
import dev.datlag.tooling.compose.launchDefault
import dev.datlag.tooling.compose.launchIO
import dev.datlag.tooling.compose.withIOContext
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -73,7 +74,7 @@ data object SchemeTheme {
return
}

scope.launchDefault {
scope.launchIO {
executor.enqueue {
state.updateFrom(input)
}
Expand All @@ -90,7 +91,7 @@ data object SchemeTheme {
return
}

scope.launchDefault {
scope.launchIO {
executor.enqueue {
val state = get(key) ?: return@enqueue
state.updateFrom(input)
Expand Down Expand Up @@ -119,7 +120,8 @@ fun rememberSchemeThemeDominantColorState(
defaultColor = defaultColor,
defaultOnColor = defaultOnColor,
builder = builder,
isSwatchValid = isSwatchValid
isSwatchValid = isSwatchValid,
coroutineContext = ioDispatcher()
)
val state by produceState(fallbackState, key) {
value = withIOContext {
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ kotlin = "1.9.23"
ksp = "1.9.23-1.0.20"
ktor = "2.3.10"
ktorfit = "1.13.0"
markdown-renderer = "0.16.0"
moko-resources = "0.24.0-beta-2"
multidex = "2.0.1"
napier = "2.7.1"
Expand Down Expand Up @@ -95,6 +96,7 @@ ktor-js = { group = "io.ktor", name = "ktor-client-js", version.ref = "ktor" }
ktor-darwin = { group = "io.ktor", name = "ktor-client-darwin", version.ref = "ktor" }
ktor-content-negotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktor" }
ktor-serialization-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktor" }
markdown-renderer = { group = "com.mikepenz", name = "multiplatform-markdown-renderer-m3", version.ref = "markdown-renderer" }
moko-resources-compose = { group = "dev.icerock.moko", name = "resources-compose", version.ref = "moko-resources" }
moko-resources-generator = { group = "dev.icerock.moko", name = "resources-generator", version.ref = "moko-resources" }
multidex = { group = "androidx.multidex", name = "multidex", version.ref = "multidex" }
Expand Down

0 comments on commit 17c78f3

Please sign in to comment.