From 429d9e1ae8164061c183d6e1720051b80e18e52f Mon Sep 17 00:00:00 2001 From: DatLag Date: Fri, 3 May 2024 13:55:15 +0200 Subject: [PATCH] change season requests to easier repository --- .../anilist/PopularNextSeasonRepository.kt | 100 ++++++++++++++++++ .../anilist/PopularNextSeasonStateMachine.kt | 83 --------------- .../anilist/PopularSeasonRepository.kt | 87 +++++++++++++++ .../anilist/PopularSeasonStateMachine.kt | 83 --------------- .../dev/datlag/aniflow/anilist/StateSaver.kt | 18 ---- .../aniflow/anilist/state/CommonState.kt | 5 - .../aniflow/anilist/state/SeasonState.kt | 81 +++----------- .../datlag/aniflow/module/NetworkModule.kt | 30 +++--- .../dev/datlag/aniflow/other/StateSaver.kt | 30 +++--- .../screen/initial/home/HomeComponent.kt | 1 + .../initial/home/HomeScreenComponent.kt | 16 ++- .../home/component/PopularSeasonOverview.kt | 19 +--- 12 files changed, 243 insertions(+), 310 deletions(-) create mode 100644 anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularNextSeasonRepository.kt delete mode 100644 anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularNextSeasonStateMachine.kt create mode 100644 anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularSeasonRepository.kt delete mode 100644 anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularSeasonStateMachine.kt delete mode 100644 anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/StateSaver.kt delete mode 100644 anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/CommonState.kt diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularNextSeasonRepository.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularNextSeasonRepository.kt new file mode 100644 index 0000000..dea95f0 --- /dev/null +++ b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularNextSeasonRepository.kt @@ -0,0 +1,100 @@ +package dev.datlag.aniflow.anilist + +import com.apollographql.apollo3.ApolloClient +import com.apollographql.apollo3.api.Optional +import dev.datlag.aniflow.anilist.common.nextSeason +import dev.datlag.aniflow.anilist.state.SeasonState +import dev.datlag.aniflow.anilist.type.MediaSeason +import dev.datlag.aniflow.anilist.type.MediaSort +import dev.datlag.aniflow.anilist.type.MediaType +import kotlinx.coroutines.flow.* +import kotlinx.datetime.Clock + +class PopularNextSeasonRepository( + private val apolloClient: ApolloClient, + private val nsfw: Flow = flowOf(false), +) { + + private val page = MutableStateFlow(0) + private val type = MutableStateFlow(MediaType.ANIME) + private val query = combine(page, type, nsfw.distinctUntilChanged()) { p, t, n -> + val (season, year) = Clock.System.now().nextSeason + + Query( + page = p, + type = t, + nsfw = n, + season = season, + year = year + ) + } + + val popularNextSeason = query.transform { + return@transform emitAll(apolloClient.query(it.toGraphQL()).toFlow()) + }.map { + SeasonState.fromGraphQL(it.data) + } + + fun nextPage() = page.getAndUpdate { + it + 1 + } + + fun previousPage() = page.getAndUpdate { + it - 1 + } + + fun viewAnime() { + type.getAndUpdate { + if (it == MediaType.ANIME) { + it + } else { + page.update { 0 } + MediaType.ANIME + } + } + } + + fun viewManga() { + type.getAndUpdate { + if (it == MediaType.MANGA) { + it + } else { + page.update { 0 } + MediaType.MANGA + } + } + } + + private data class Query( + val page: Int, + val type: MediaType, + val nsfw: Boolean, + val season: MediaSeason, + val year: Int + ) { + fun toGraphQL() = SeasonQuery( + page = Optional.present(page), + perPage = Optional.present(10), + adultContent = if (nsfw) { + Optional.absent() + } else { + Optional.present(nsfw) + }, + type = Optional.present(type), + sort = Optional.present(listOf(MediaSort.POPULARITY_DESC)), + preventGenres = if (nsfw) { + Optional.absent() + } else { + Optional.present(AdultContent.Genre.allTags) + }, + year = Optional.present(year), + season = if (season == MediaSeason.UNKNOWN__) { + Optional.absent() + } else { + Optional.present(season) + }, + statusVersion = Optional.present(2), + html = Optional.present(true) + ) + } +} \ No newline at end of file diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularNextSeasonStateMachine.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularNextSeasonStateMachine.kt deleted file mode 100644 index 8abb576..0000000 --- a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularNextSeasonStateMachine.kt +++ /dev/null @@ -1,83 +0,0 @@ -package dev.datlag.aniflow.anilist - -import com.apollographql.apollo3.ApolloClient -import com.freeletics.flowredux.dsl.FlowReduxStateMachine -import dev.datlag.aniflow.anilist.state.SeasonAction -import dev.datlag.aniflow.anilist.state.SeasonState -import dev.datlag.aniflow.firebase.FirebaseFactory -import dev.datlag.aniflow.model.CatchResult -import dev.datlag.aniflow.model.mapError -import dev.datlag.aniflow.model.safeFirstOrNull -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlin.time.Duration.Companion.seconds - -@OptIn(ExperimentalCoroutinesApi::class) -class PopularNextSeasonStateMachine( - private val client: ApolloClient, - private val fallbackClient: ApolloClient, - private val crashlytics: FirebaseFactory.Crashlytics? -) : FlowReduxStateMachine( - initialState = currentState -) { - - init { - spec { - inState { - onEnterEffect { - currentState = it - } - onEnter { state -> - Cache.getSeason(state.snapshot.query)?.let { - return@onEnter state.override { SeasonState.Success(query, it) } - } - - val response = CatchResult.repeat(times = 2, timeoutDuration = 30.seconds) { - val query = client.query(state.snapshot.query) - - query.execute().data ?: query.toFlow().safeFirstOrNull()?.dataOrThrow() - }.mapError { - val query = fallbackClient.query(state.snapshot.query) - - query.execute().data ?: query.toFlow().safeFirstOrNull()?.data - }.mapSuccess { - SeasonState.Success(state.snapshot.query, it) - } - - state.override { - response.asSuccess { - crashlytics?.log(it) - - SeasonState.Error(query) - } - } - } - } - inState { - onEnterEffect { - Cache.setSeason(it.query, it.data) - currentState = it - } - } - inState { - onEnterEffect { - currentState = it - } - on { _, state -> - state.override { - SeasonState.Loading( - state.snapshot.query - ) - } - } - } - } - } - - companion object { - var currentState: SeasonState - get() = StateSaver.popularNextSeason - set(value) { - StateSaver.popularNextSeason = value - } - } -} \ No newline at end of file diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularSeasonRepository.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularSeasonRepository.kt new file mode 100644 index 0000000..e473da1 --- /dev/null +++ b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularSeasonRepository.kt @@ -0,0 +1,87 @@ +package dev.datlag.aniflow.anilist + +import com.apollographql.apollo3.ApolloClient +import com.apollographql.apollo3.api.Optional +import dev.datlag.aniflow.anilist.state.SeasonState +import dev.datlag.aniflow.anilist.type.MediaSort +import dev.datlag.aniflow.anilist.type.MediaType +import kotlinx.coroutines.flow.* + +class PopularSeasonRepository( + private val apolloClient: ApolloClient, + private val nsfw: Flow = flowOf(false), +) { + + private val page = MutableStateFlow(0) + private val type = MutableStateFlow(MediaType.ANIME) + private val query = combine(page, type, nsfw.distinctUntilChanged()) { p, t, n -> + Query( + page = p, + type = t, + nsfw = n + ) + } + + val popularThisSeason = query.transform { + return@transform emitAll(apolloClient.query(it.toGraphQL()).toFlow()) + }.map { + SeasonState.fromGraphQL(it.data) + } + + fun nextPage() = page.getAndUpdate { + it + 1 + } + + fun previousPage() = page.getAndUpdate { + it - 1 + } + + fun viewAnime() { + type.getAndUpdate { + if (it == MediaType.ANIME) { + it + } else { + page.update { 0 } + MediaType.ANIME + } + } + } + + fun viewManga() { + type.getAndUpdate { + if (it == MediaType.MANGA) { + it + } else { + page.update { 0 } + MediaType.MANGA + } + } + } + + private data class Query( + val page: Int, + val type: MediaType, + val nsfw: Boolean + ) { + fun toGraphQL() = SeasonQuery( + page = Optional.present(page), + perPage = Optional.present(10), + adultContent = if (nsfw) { + Optional.absent() + } else { + Optional.present(nsfw) + }, + type = Optional.present(type), + sort = Optional.present(listOf(MediaSort.POPULARITY_DESC)), + preventGenres = if (nsfw) { + Optional.absent() + } else { + Optional.present(AdultContent.Genre.allTags) + }, + year = Optional.absent(), + season = Optional.absent(), + statusVersion = Optional.present(2), + html = Optional.present(true) + ) + } +} \ No newline at end of file diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularSeasonStateMachine.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularSeasonStateMachine.kt deleted file mode 100644 index 08f0915..0000000 --- a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularSeasonStateMachine.kt +++ /dev/null @@ -1,83 +0,0 @@ -package dev.datlag.aniflow.anilist - -import com.apollographql.apollo3.ApolloClient -import com.freeletics.flowredux.dsl.FlowReduxStateMachine -import dev.datlag.aniflow.anilist.state.SeasonAction -import dev.datlag.aniflow.anilist.state.SeasonState -import dev.datlag.aniflow.firebase.FirebaseFactory -import dev.datlag.aniflow.model.CatchResult -import dev.datlag.aniflow.model.mapError -import dev.datlag.aniflow.model.safeFirstOrNull -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlin.time.Duration.Companion.seconds - -@OptIn(ExperimentalCoroutinesApi::class) -class PopularSeasonStateMachine( - private val client: ApolloClient, - private val fallbackClient: ApolloClient, - private val crashlytics: FirebaseFactory.Crashlytics? -) : FlowReduxStateMachine( - initialState = currentState -) { - - init { - spec { - inState { - onEnterEffect { - currentState = it - } - onEnter { state -> - Cache.getSeason(state.snapshot.query)?.let { - return@onEnter state.override { SeasonState.Success(query, it) } - } - - val response = CatchResult.repeat(times = 2, timeoutDuration = 30.seconds) { - val query = client.query(state.snapshot.query) - - query.execute().data ?: query.toFlow().safeFirstOrNull()?.dataOrThrow() - }.mapError { - val query = fallbackClient.query(state.snapshot.query) - - query.execute().data ?: query.toFlow().safeFirstOrNull()?.data - }.mapSuccess { - SeasonState.Success(state.snapshot.query, it) - } - - state.override { - response.asSuccess { - crashlytics?.log(it) - - SeasonState.Error(query) - } - } - } - } - inState { - onEnterEffect { - Cache.setSeason(it.query, it.data) - currentState = it - } - } - inState { - onEnterEffect { - currentState = it - } - on { _, state -> - state.override { - SeasonState.Loading( - state.snapshot.query - ) - } - } - } - } - } - - companion object { - var currentState: SeasonState - get() = StateSaver.popularSeason - set(value) { - StateSaver.popularSeason = value - } - } -} \ No newline at end of file diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/StateSaver.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/StateSaver.kt deleted file mode 100644 index 66af5d2..0000000 --- a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/StateSaver.kt +++ /dev/null @@ -1,18 +0,0 @@ -package dev.datlag.aniflow.anilist - -import dev.datlag.aniflow.anilist.common.nextSeason -import dev.datlag.aniflow.anilist.state.SeasonState -import kotlinx.datetime.Clock - -internal object StateSaver { - var popularSeason: SeasonState = SeasonState.Loading(page = 0) - var popularNextSeason: SeasonState = run { - val (nextSeason, nextYear) = Clock.System.now().nextSeason - - SeasonState.Loading( - page = 0, - season = nextSeason, - year = nextYear - ) - } -} \ No newline at end of file diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/CommonState.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/CommonState.kt deleted file mode 100644 index 65e6d52..0000000 --- a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/CommonState.kt +++ /dev/null @@ -1,5 +0,0 @@ -package dev.datlag.aniflow.anilist.state - -interface CommonState { - val isLoadingOrWaiting: Boolean -} \ No newline at end of file diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/SeasonState.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/SeasonState.kt index c2ec977..9e588af 100644 --- a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/SeasonState.kt +++ b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/SeasonState.kt @@ -5,80 +5,29 @@ import dev.datlag.aniflow.anilist.AdultContent import dev.datlag.aniflow.anilist.SeasonQuery import dev.datlag.aniflow.anilist.common.season import dev.datlag.aniflow.anilist.common.year +import dev.datlag.aniflow.anilist.model.Medium import dev.datlag.aniflow.anilist.type.MediaSeason import dev.datlag.aniflow.anilist.type.MediaSort import dev.datlag.aniflow.anilist.type.MediaType import kotlinx.datetime.Clock import kotlinx.datetime.Instant -sealed interface SeasonState : CommonState { - - override val isLoadingOrWaiting: Boolean - get() = this is Loading - - data class Loading( - internal val query: SeasonQuery - ) : SeasonState { - constructor( - page: Int, - perPage: Int = 10, - adultContent: Boolean = false, - type: MediaType = MediaType.ANIME, - season: MediaSeason = Clock.System.now().season, - year: Int = Clock.System.now().year - ) : this( - SeasonQuery( - page = Optional.present(page), - perPage = Optional.present(perPage), - adultContent = if (!adultContent) { - Optional.present(adultContent) - } else { - Optional.absent() - }, - type = Optional.present(type), - sort = Optional.present(listOf(MediaSort.POPULARITY_DESC)), - preventGenres = if (!adultContent) { - Optional.present(AdultContent.Genre.allTags) - } else { - Optional.absent() - }, - year = Optional.present(year), - season = if (season == MediaSeason.UNKNOWN__) { - Optional.absent() - } else { - Optional.present(season) - }, - statusVersion = Optional.present(2), - html = Optional.present(true) - ) - ) - - constructor( - page: Int, - perPage: Int = 10, - adultContent: Boolean = false, - type: MediaType = MediaType.ANIME, - now: Instant = Clock.System.now() - ) : this( - page = page, - perPage = perPage, - adultContent = adultContent, - type = type, - season = now.season, - year = now.year - ) - } - +sealed interface SeasonState { data class Success( - internal val query: SeasonQuery, - val data: SeasonQuery.Data + val collection: Collection ) : SeasonState - data class Error( - internal val query: SeasonQuery - ) : SeasonState -} + data object Error : SeasonState + + companion object { + fun fromGraphQL(data: SeasonQuery.Data?): SeasonState { + val mediaList = data?.Page?.mediaFilterNotNull() -sealed interface SeasonAction { - data object Retry : SeasonAction + if (mediaList.isNullOrEmpty()) { + return Error + } + + return Success(mediaList.map { Medium(it) }) + } + } } \ No newline at end of file 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 4578b09..cd26277 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/module/NetworkModule.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/module/NetworkModule.kt @@ -89,20 +89,6 @@ data object NetworkModule { .serverUrl(Constants.AniList.SERVER_URL) .build() } - bindProvider { - PopularSeasonStateMachine( - client = instance(Constants.AniList.APOLLO_CLIENT), - fallbackClient = instance(Constants.AniList.FALLBACK_APOLLO_CLIENT), - crashlytics = nullableFirebaseInstance()?.crashlytics - ) - } - bindProvider { - PopularNextSeasonStateMachine( - client = instance(Constants.AniList.APOLLO_CLIENT), - fallbackClient = instance(Constants.AniList.FALLBACK_APOLLO_CLIENT), - crashlytics = nullableFirebaseInstance()?.crashlytics - ) - } bindSingleton { UserHelper( userSettings = instance(), @@ -144,5 +130,21 @@ data object NetworkModule { nsfw = appSettings.adultContent ) } + bindSingleton { + val appSettings = instance() + + PopularSeasonRepository( + apolloClient = instance(Constants.AniList.APOLLO_CLIENT), + nsfw = appSettings.adultContent + ) + } + bindSingleton { + val appSettings = instance() + + PopularNextSeasonRepository( + apolloClient = instance(Constants.AniList.APOLLO_CLIENT), + nsfw = appSettings.adultContent + ) + } } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/other/StateSaver.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/other/StateSaver.kt index 5d284ee..41a5734 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/other/StateSaver.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/other/StateSaver.kt @@ -44,28 +44,22 @@ data object StateSaver { data object Home { private val airingLoading = MutableStateFlow(true) private val trendingLoading = MutableStateFlow(true) - private val _popularCurrentState = MutableStateFlow(popularCurrentState) - private val _popularNextState = MutableStateFlow(popularNextState) - - val popularCurrentState: SeasonState - get() = PopularSeasonStateMachine.currentState - - val popularNextState: SeasonState - get() = PopularNextSeasonStateMachine.currentState + private val popularCurrentLoading = MutableStateFlow(true) + private val popularNextLoading = MutableStateFlow(true) val currentAllLoading: Boolean get() = airingLoading.value && trendingLoading.value - && _popularCurrentState.value.isLoadingOrWaiting - && _popularNextState.value.isLoadingOrWaiting + && popularCurrentLoading.value + && popularNextLoading.value val isAllLoading = combine( airingLoading, trendingLoading, - _popularCurrentState, - _popularNextState + popularCurrentLoading, + popularNextLoading ) { t1, t2, t3, t4 -> - t1 && t2 && t3.isLoadingOrWaiting && t4.isLoadingOrWaiting + t1 && t2 && t3 && t4 }.flowOn(ioDispatcher()).distinctUntilChanged() fun updateAiring(state: AiringTodayRepository.State): AiringTodayRepository.State { @@ -78,12 +72,14 @@ data object StateSaver { return state } - fun updatePopularCurrent(state: SeasonState) = _popularCurrentState.updateAndGet { - state + fun updatePopularCurrent(state: SeasonState): SeasonState { + popularCurrentLoading.update { false } + return state } - fun updatePopularNext(state: SeasonState) = _popularNextState.updateAndGet { - state + fun updatePopularNext(state: SeasonState): SeasonState { + popularNextLoading.update { false } + return state } } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/HomeComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/HomeComponent.kt index 89944bc..80bff08 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/HomeComponent.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/HomeComponent.kt @@ -3,6 +3,7 @@ package dev.datlag.aniflow.ui.navigation.screen.initial.home import com.arkivanov.decompose.router.slot.ChildSlot import com.arkivanov.decompose.value.Value import dev.datlag.aniflow.anilist.AiringTodayRepository +import dev.datlag.aniflow.anilist.PopularSeasonRepository import dev.datlag.aniflow.anilist.TrendingRepository import dev.datlag.aniflow.anilist.model.Medium import dev.datlag.aniflow.anilist.state.SeasonState diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/HomeScreenComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/HomeScreenComponent.kt index 341d111..271e2cc 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/HomeScreenComponent.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/HomeScreenComponent.kt @@ -46,19 +46,15 @@ class HomeScreenComponent( StateSaver.Home.updateTrending(it) } - private val popularSeasonStateMachine by di.instance() - override val popularSeasonState: Flow = popularSeasonStateMachine.state.map { + private val popularSeasonRepository by di.instance() + override val popularSeasonState: Flow = popularSeasonRepository.popularThisSeason.map { StateSaver.Home.updatePopularCurrent(it) - }.flowOn( - context = ioDispatcher() - ).distinctUntilChanged() + } - private val popularNextSeasonStateMachine by di.instance() - override val popularNextSeasonState: Flow = popularNextSeasonStateMachine.state.map { + private val popularNextSeasonRepository by di.instance() + override val popularNextSeasonState: Flow = popularNextSeasonRepository.popularNextSeason.map { StateSaver.Home.updatePopularNext(it) - }.flowOn( - context = ioDispatcher() - ).distinctUntilChanged() + } private val traceStateMachine by di.instance() override val traceState: Flow = traceStateMachine.state.flowOn( diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/component/PopularSeasonOverview.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/component/PopularSeasonOverview.kt index 72c4ac4..869457e 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/component/PopularSeasonOverview.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/component/PopularSeasonOverview.kt @@ -13,7 +13,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.unit.dp -import dev.datlag.aniflow.anilist.PopularSeasonStateMachine import dev.datlag.aniflow.anilist.SeasonQuery import dev.datlag.aniflow.anilist.TrendingQuery import dev.datlag.aniflow.anilist.model.Medium @@ -34,21 +33,13 @@ fun PopularSeasonOverview( titleLanguage: SettingsTitle?, onClick: (Medium) -> Unit, ) { - val loadingState by state.collectAsStateWithLifecycle( - if (current) { - StateSaver.Home.popularCurrentState - } else { - StateSaver.Home.popularNextState - } - ) + val loadingState by state.collectAsStateWithLifecycle(null) when (val reachedState = loadingState) { - is SeasonState.Loading -> { - Loading() - } + null -> Loading() is SeasonState.Success -> { SuccessContent( - data = reachedState.data.Page?.mediaFilterNotNull() ?: emptyList(), + data = reachedState.collection.toList(), current = current, titleLanguage = titleLanguage, onClick = onClick @@ -75,7 +66,7 @@ private fun Loading() { @OptIn(ExperimentalFoundationApi::class) @Composable private fun SuccessContent( - data: List, + data: List, current: Boolean, titleLanguage: SettingsTitle?, onClick: (Medium) -> Unit @@ -101,7 +92,7 @@ private fun SuccessContent( ) { itemsIndexed(data, key = { _, it -> it.id }) { _, medium -> MediumCard( - medium = Medium(medium), + medium = medium, titleLanguage = titleLanguage, modifier = Modifier .width(200.dp)