From cddcda78dedbaea716da48db1066243370a215e9 Mon Sep 17 00:00:00 2001 From: DatLag Date: Tue, 28 May 2024 17:02:37 +0200 Subject: [PATCH] added search state --- .../datlag/aniflow/anilist/state/SearchState.kt | 8 +++++++- .../screen/discover/component/DiscoverSearchBar.kt | 14 ++++++++++++++ .../src/commonMain/moko-resources/base/strings.xml | 1 + .../commonMain/moko-resources/de-DE/strings.xml | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/SearchState.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/SearchState.kt index 11740c1..d025fd5 100644 --- a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/SearchState.kt +++ b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/SearchState.kt @@ -29,6 +29,8 @@ sealed interface SearchState { internal val throwable: Throwable? ) : PostLoading + data object Empty : PostLoading + companion object { fun fromResponse(response: ApolloResponse?): SearchState { return if (response == null) { @@ -46,7 +48,11 @@ sealed interface SearchState { val mediumList = data.Page?.mediaFilterNotNull() if (mediumList.isNullOrEmpty()) { - Failure(response.exception) + if (response.hasNonCacheError()) { + Failure(response.exception) + } else { + Empty + } } else { Success(mediumList.map(::Medium).distinctBy { it.id }.toImmutableList()) } diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/component/DiscoverSearchBar.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/component/DiscoverSearchBar.kt index 9f50a9d..2b5ac67 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/component/DiscoverSearchBar.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/component/DiscoverSearchBar.kt @@ -41,6 +41,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import dev.chrisbanes.haze.hazeChild import dev.datlag.aniflow.LocalHaze @@ -182,6 +183,19 @@ fun DiscoverSearchBar( } } } + + is SearchState.Empty -> { + Box( + modifier = Modifier.fillMaxSize().padding(horizontal = 16.dp), + contentAlignment = Alignment.Center + ) { + Text( + text = stringResource(SharedRes.strings.nothing_on_search), + textAlign = TextAlign.Center + ) + } + } + } } ) diff --git a/composeApp/src/commonMain/moko-resources/base/strings.xml b/composeApp/src/commonMain/moko-resources/base/strings.xml index 378d789..ad1e7ac 100644 --- a/composeApp/src/commonMain/moko-resources/base/strings.xml +++ b/composeApp/src/commonMain/moko-resources/base/strings.xml @@ -119,6 +119,7 @@ Recommendation This feature will be supported with Burning-Series version 6.0.0 and upwards. You have nothing on your list, either change the filter or add any Anime/Manga. + Nothing found, please change your search query. Enable Ignore Enable In-App View diff --git a/composeApp/src/commonMain/moko-resources/de-DE/strings.xml b/composeApp/src/commonMain/moko-resources/de-DE/strings.xml index 77c7b54..6a58b61 100644 --- a/composeApp/src/commonMain/moko-resources/de-DE/strings.xml +++ b/composeApp/src/commonMain/moko-resources/de-DE/strings.xml @@ -119,6 +119,7 @@ Empfehlung Diese Option wird mit Burning-Series Version 6.0.0 und höher unterstützt. Du hast nichts auf deiner Liste, ändere den Filter oder füge einen Anime/Manga hinzu. + Nichts gefunden, passe bitte deine Suche an. Aktivieren Ignorieren In-App Ansicht aktivieren