From 1a6cd8505aa16fa5b9d4540b790b579e54ef4b9f Mon Sep 17 00:00:00 2001 From: DatLag Date: Mon, 13 May 2024 20:08:09 +0200 Subject: [PATCH] update on login --- .../dev/datlag/aniflow/anilist/CharacterRepository.kt | 10 +++++++--- .../dev/datlag/aniflow/anilist/MediumRepository.kt | 10 +++++++--- build.gradle.kts | 6 ++++++ .../kotlin/dev/datlag/aniflow/module/NetworkModule.kt | 4 +++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/CharacterRepository.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/CharacterRepository.kt index 930c190..39c6a7f 100644 --- a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/CharacterRepository.kt +++ b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/CharacterRepository.kt @@ -7,12 +7,16 @@ import kotlinx.coroutines.flow.* class CharacterRepository( private val client: ApolloClient, - private val fallbackClient: ApolloClient + private val fallbackClient: ApolloClient, + private val isLoggedIn: Flow ) { private val id = MutableStateFlow(null) - private val query = id.filterNotNull().map { - Query(it) + private val query = combine( + id.filterNotNull(), + isLoggedIn.distinctUntilChanged() + ) { t1, _ -> + Query(t1) } private val fallbackQuery = query.transform { return@transform emitAll(fallbackClient.query(it.toGraphQL()).toFlow()) diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/MediumRepository.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/MediumRepository.kt index 042f38a..61973a7 100644 --- a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/MediumRepository.kt +++ b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/MediumRepository.kt @@ -8,12 +8,16 @@ import kotlinx.coroutines.flow.* class MediumRepository( private val client: ApolloClient, - private val fallbackClient: ApolloClient + private val fallbackClient: ApolloClient, + private val isLoggedIn: Flow ) { private val id = MutableStateFlow(null) - private val query = id.filterNotNull().map { - Query(it) + private val query = combine( + id.filterNotNull(), + isLoggedIn.distinctUntilChanged() + ) { t1, _ -> + Query(t1) } private val fallbackQuery = query.transform { return@transform emitAll(fallbackClient.query(it.toGraphQL()).toFlow()) diff --git a/build.gradle.kts b/build.gradle.kts index 7879c11..af8d57f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,6 +52,12 @@ allprojects { tasks.withType().configureEach { kotlinOptions.jvmTarget = CompileOptions.jvmTarget + compilerOptions { + freeCompilerArgs.addAll( + "-P", + "plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true" + ) + } } plugins.withType { yarn.yarnLockAutoReplace = true diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/module/NetworkModule.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/module/NetworkModule.kt index 9746c24..f3b9cf5 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/module/NetworkModule.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/module/NetworkModule.kt @@ -167,12 +167,14 @@ data object NetworkModule { CharacterRepository( client = instance(Constants.AniList.APOLLO_CLIENT).newBuilder().fetchPolicy(FetchPolicy.NetworkFirst).build(), fallbackClient = instance(Constants.AniList.FALLBACK_APOLLO_CLIENT).newBuilder().fetchPolicy(FetchPolicy.NetworkFirst).build(), + isLoggedIn = instance().isLoggedIn ) } bindSingleton { MediumRepository( client = instance(Constants.AniList.APOLLO_CLIENT).newBuilder().fetchPolicy(FetchPolicy.NetworkFirst).build(), - fallbackClient = instance(Constants.AniList.FALLBACK_APOLLO_CLIENT).newBuilder().fetchPolicy(FetchPolicy.NetworkFirst).build() + fallbackClient = instance(Constants.AniList.FALLBACK_APOLLO_CLIENT).newBuilder().fetchPolicy(FetchPolicy.NetworkFirst).build(), + isLoggedIn = instance().isLoggedIn ) } bindSingleton {