Skip to content

Commit

Permalink
Add unrated puzzles option
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudyDino committed Feb 15, 2025
1 parent 7074971 commit 264a498
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/src/model/puzzle/puzzle_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);

Expand Down
10 changes: 9 additions & 1 deletion lib/src/model/puzzle/puzzle_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class PuzzlePreferences extends _$PuzzlePreferences with SessionPreferencesStora
Future<void> setAutoNext(bool autoNext) async {
save(state.copyWith(autoNext: autoNext));
}

Future<void> setRated(bool rated) async {
save(state.copyWith(rated: rated));
}
}

@Freezed(fromJson: true, toJson: true)
Expand All @@ -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<String, dynamic> json) => _$PuzzlePrefsFromJson(json);
}
11 changes: 11 additions & 0 deletions lib/src/view/puzzle/puzzle_settings_screen.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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(
Expand All @@ -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),
Expand Down

0 comments on commit 264a498

Please sign in to comment.