diff --git a/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/datastore/internal/DefaultProtoDataStoreMutator.kt b/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/datastore/internal/DefaultProtoDataStoreMutator.kt index 7dc568aa..b83579fe 100644 --- a/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/datastore/internal/DefaultProtoDataStoreMutator.kt +++ b/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/datastore/internal/DefaultProtoDataStoreMutator.kt @@ -42,7 +42,7 @@ class DefaultProtoDataStoreMutator( override suspend fun addGameToFavourites(game: UserFavouriteGame) { favGamesStore.updateData { - if (game !in it.favGame) { + if (game.id !in it.favGame.map { fGame -> fGame.id }) { it.copy(favGame = it.favGame + game) } else { it @@ -52,7 +52,7 @@ class DefaultProtoDataStoreMutator( override suspend fun removeGameFromFavourites(game: UserFavouriteGame) { favGamesStore.updateData { - it.copy(favGame = it.favGame - game) + it.copy(favGame = it.favGame - it.favGame.filter { it.id == game.id }.toSet()) } } @@ -68,7 +68,7 @@ class DefaultProtoDataStoreMutator( override suspend fun removeGenreFromFavourites(genre: UserFavouriteGenre) { favGenresStore.updateData { - it.copy(favGenre = it.favGenre - genre) + it.copy(favGenre = it.favGenre - it.favGenre.filter { it.id == genre.id }.toSet()) } } } diff --git a/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/onboarding/GamesPage.kt b/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/onboarding/GamesPage.kt index a692c325..85b66b51 100644 --- a/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/onboarding/GamesPage.kt +++ b/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/onboarding/GamesPage.kt @@ -239,7 +239,7 @@ fun SelectingFavouriteGamesPage( contentType = games.itemContentType { it } ) { index -> val game = games[index] - val isFavGame = game?.let { FavouriteGame(it.id, it.name, it.imageUrl, it.rating) } in favouriteUserGames + val isFavGame = game?.id in favouriteUserGames.map { it.id } if (!isFavGame) { GameTile( game = game, diff --git a/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/onboarding/GenresPage.kt b/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/onboarding/GenresPage.kt index 7bf866bf..dd91d9cc 100644 --- a/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/onboarding/GenresPage.kt +++ b/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/onboarding/GenresPage.kt @@ -108,6 +108,7 @@ fun GenresPage( horizontalArrangement = Arrangement.spacedBy(8.dp) ) { allGenres.data.forEach { genre -> + val isSelected = genre.id in selectedGenres.map { it.id } Row( modifier = Modifier .padding(vertical = 8.dp) @@ -118,16 +119,16 @@ fun GenresPage( ) .clip(RoundedCornerShape(8.dp)) .conditionalBackground( - predicate = genre in selectedGenres, + predicate = isSelected, color = MaterialTheme.colorScheme.primary.copy(alpha = 0.2f) ) .selectable( - selected = genre in selectedGenres, + selected = isSelected, interactionSource = remember { MutableInteractionSource() }, indication = null, role = Role.Checkbox, onClick = { - if (genre in selectedGenres) { + if (isSelected) { onUnselectingGenre(genre) } else { onSelectingGenre(genre) @@ -137,9 +138,9 @@ fun GenresPage( .animateContentSize() .padding(8.dp) .clearAndSetSemantics { - val stateDesc = if (genre in selectedGenres) strings.genres_page_genre_on_state_desc(genre.name) else strings.genres_page_genre_off_state_desc(genre.name) + val stateDesc = if (isSelected) strings.genres_page_genre_on_state_desc(genre.name) else strings.genres_page_genre_off_state_desc(genre.name) stateDescription = stateDesc - selected = genre in selectedGenres + selected = isSelected role = Role.Checkbox }, verticalAlignment = Alignment.CenterVertically, @@ -157,7 +158,7 @@ fun GenresPage( modifier = Modifier.width(IntrinsicSize.Min), textAlign = TextAlign.Center ) - if (genre in selectedGenres) { + if (isSelected) { Icon( imageVector = Icons.Filled.Check, contentDescription = null, diff --git a/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/settings/EditPreferencesScreen.kt b/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/settings/EditPreferencesScreen.kt index 3b129550..da510ac1 100644 --- a/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/settings/EditPreferencesScreen.kt +++ b/shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/settings/EditPreferencesScreen.kt @@ -318,13 +318,14 @@ fun GenresList( val genres = state.allGenres.data val strings = LocalStrings.current genres.forEachIndexed { index, gameGenre -> + val isSelected = gameGenre.id in state.favouriteGenres.map { it.id } Row( modifier = modifier .fillMaxWidth() .selectable( - gameGenre in state.favouriteGenres, + isSelected, onClick = { - if (gameGenre in state.favouriteGenres) { + if (isSelected) { onRemovingGenreFromFavourites(gameGenre) } else { onAddingGenreToFavourites(gameGenre) @@ -334,12 +335,12 @@ fun GenresList( .padding(8.dp) .clearAndSetSemantics { stateDescription = - if (gameGenre in state.favouriteGenres) { + if (isSelected) { strings.edit_preferences_page_genre_on_state_desc(gameGenre.name) } else { strings.edit_preferences_page_genre_off_state_desc(gameGenre.name) } - selected = gameGenre in state.favouriteGenres + selected = isSelected }, horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically @@ -351,7 +352,7 @@ fun GenresList( style = MaterialTheme.typography.titleLarge ) Checkbox( - checked = gameGenre in state.favouriteGenres, + checked = isSelected, onCheckedChange = null ) }