Skip to content

Commit

Permalink
fix user settings not changing
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 10, 2024
1 parent 358722e commit 9f9f2e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import coil3.svg.SvgDecoder
import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.http.HttpRequest
import com.apollographql.apollo3.api.http.HttpResponse
import com.apollographql.apollo3.cache.normalized.FetchPolicy
import com.apollographql.apollo3.cache.normalized.api.MemoryCacheFactory
import com.apollographql.apollo3.cache.normalized.api.NormalizedCacheFactory
import com.apollographql.apollo3.cache.normalized.fetchPolicy
import com.apollographql.apollo3.cache.normalized.normalizedCache
import com.apollographql.apollo3.network.http.HttpInterceptor
import com.apollographql.apollo3.network.http.HttpInterceptorChain
Expand Down Expand Up @@ -87,13 +89,15 @@ data object NetworkModule {
}
})
.normalizedCache(instance(Constants.AniList.CACHE_FACTORY))
.fetchPolicy(FetchPolicy.CacheAndNetwork)
.build()
}
bindSingleton<ApolloClient>(Constants.AniList.FALLBACK_APOLLO_CLIENT) {
ApolloClient.Builder()
.dispatcher(ioDispatcher())
.serverUrl(Constants.AniList.SERVER_URL)
.normalizedCache(instance(Constants.AniList.CACHE_FACTORY))
.fetchPolicy(FetchPolicy.CacheAndNetwork)
.build()
}
bindSingleton<UserHelper> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.platform.UriHandler
import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.Optional
import com.apollographql.apollo3.cache.normalized.FetchPolicy
import com.apollographql.apollo3.cache.normalized.fetchPolicy
import dev.datlag.aniflow.anilist.ViewerMutation
import dev.datlag.aniflow.anilist.ViewerQuery
import dev.datlag.aniflow.anilist.model.User
Expand All @@ -19,6 +21,7 @@ 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 io.github.aakira.napier.Napier
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.*
Expand All @@ -44,7 +47,7 @@ class UserHelper(
private val updatableUser = isLoggedIn.transform { loggedIn ->
if (loggedIn) {
emitAll(
client.query(ViewerQuery()).toFlow().map {
client.query(ViewerQuery()).fetchPolicy(FetchPolicy.NetworkFirst).toFlow().map {
it.data?.Viewer?.let(::User)
}
)
Expand All @@ -56,17 +59,15 @@ class UserHelper(
initialValue = null
)

val user = updatableUser.transform { user ->
emit(
user?.also {
appSettings.setData(
adultContent = it.displayAdultContent,
color = SettingsColor.fromString(it.profileColor),
titleLanguage = it.titleLanguage.toSettings(),
charLanguage = it.charLanguage.toSettings()
)
}
)
val user = updatableUser.map { user ->
user?.also {
appSettings.setData(
adultContent = it.displayAdultContent,
color = SettingsColor.fromString(it.profileColor),
titleLanguage = it.titleLanguage.toSettings(),
charLanguage = it.charLanguage.toSettings()
)
}
}.flowOn(ioDispatcher())

suspend fun updateAdultSetting(value: Boolean) {
Expand All @@ -76,7 +77,7 @@ class UserHelper(
ViewerMutation(
adult = Optional.present(value)
)
).execute().data?.UpdateUser?.let(::User)
).fetchPolicy(FetchPolicy.NetworkFirst).execute().data?.UpdateUser?.let(::User)
)
}

Expand All @@ -89,7 +90,7 @@ class UserHelper(
ViewerMutation(
color = Optional.present(value.label)
)
).execute().data?.UpdateUser?.let(::User)
).fetchPolicy(FetchPolicy.NetworkFirst).execute().data?.UpdateUser?.let(::User)
)
}
}
Expand All @@ -103,7 +104,7 @@ class UserHelper(
ViewerMutation(
title = Optional.presentIfNotNull(value.toMutation())
)
).execute().data?.UpdateUser?.let(::User)
).fetchPolicy(FetchPolicy.NetworkFirst).execute().data?.UpdateUser?.let(::User)
)
}
}
Expand All @@ -117,7 +118,7 @@ class UserHelper(
ViewerMutation(
char = Optional.presentIfNotNull(value.toMutation())
)
).execute().data?.UpdateUser?.let(::User)
).fetchPolicy(FetchPolicy.NetworkFirst).execute().data?.UpdateUser?.let(::User)
)
}
}
Expand Down

0 comments on commit 9f9f2e6

Please sign in to comment.