diff --git a/lib/src/model/puzzle/puzzle_controller.dart b/lib/src/model/puzzle/puzzle_controller.dart index 48c0f19a5c..a97b3e5d34 100644 --- a/lib/src/model/puzzle/puzzle_controller.dart +++ b/lib/src/model/puzzle/puzzle_controller.dart @@ -324,7 +324,7 @@ class PuzzleController extends _$PuzzleController { solution: PuzzleSolution( id: state.puzzle.puzzle.id, win: state.result == PuzzleResult.win, - rated: initialContext.userId != null, + rated: initialContext.userId != null && ref.read(puzzlePreferencesProvider).rated, ), ); diff --git a/lib/src/model/puzzle/puzzle_preferences.dart b/lib/src/model/puzzle/puzzle_preferences.dart index 774fc549bb..6482f1d49a 100644 --- a/lib/src/model/puzzle/puzzle_preferences.dart +++ b/lib/src/model/puzzle/puzzle_preferences.dart @@ -32,6 +32,10 @@ class PuzzlePreferences extends _$PuzzlePreferences with SessionPreferencesStora Future setAutoNext(bool autoNext) async { save(state.copyWith(autoNext: autoNext)); } + + Future setRated(bool rated) async { + save(state.copyWith(rated: rated)); + } } @Freezed(fromJson: true, toJson: true) @@ -44,10 +48,14 @@ class PuzzlePrefs with _$PuzzlePrefs implements Serializable { /// no effect on puzzle streaks, which always show next puzzle. Defaults to /// `false`. @Default(false) bool autoNext, + + /// If `true`, the puzzle will be rated for logged in users. + /// Defaults to `true`. + @Default(true) bool rated, }) = _PuzzlePrefs; factory PuzzlePrefs.defaults({UserId? id}) => - PuzzlePrefs(id: id, difficulty: PuzzleDifficulty.normal, autoNext: false); + PuzzlePrefs(id: id, difficulty: PuzzleDifficulty.normal, autoNext: false, rated: true); factory PuzzlePrefs.fromJson(Map json) => _$PuzzlePrefsFromJson(json); } diff --git a/lib/src/view/puzzle/puzzle_settings_screen.dart b/lib/src/view/puzzle/puzzle_settings_screen.dart index 3725ed8425..0f4a860b29 100644 --- a/lib/src/view/puzzle/puzzle_settings_screen.dart +++ b/lib/src/view/puzzle/puzzle_settings_screen.dart @@ -1,5 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_preferences.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; import 'package:lichess_mobile/src/view/settings/board_settings_screen.dart'; @@ -12,7 +13,9 @@ class PuzzleSettingsScreen extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { + final signedIn = ref.watch(authSessionProvider)?.user.id != null; final autoNext = ref.watch(puzzlePreferencesProvider.select((value) => value.autoNext)); + final rated = ref.watch(puzzlePreferencesProvider.select((value) => value.rated)); return BottomSheetScrollableContainer( children: [ SwitchSettingTile( @@ -22,6 +25,14 @@ class PuzzleSettingsScreen extends ConsumerWidget { ref.read(puzzlePreferencesProvider.notifier).setAutoNext(value); }, ), + if (signedIn) + SwitchSettingTile( + title: Text(context.l10n.rated), + value: rated, + onChanged: (value) { + ref.read(puzzlePreferencesProvider.notifier).setRated(value); + }, + ), PlatformListTile( title: const Text('Board settings'), trailing: const Icon(CupertinoIcons.chevron_right),