Skip to content

Commit

Permalink
Merge pull request #1071 from lichess-org/puzzle_tab_revamp
Browse files Browse the repository at this point in the history
Revamp puzzle tab
  • Loading branch information
veloce authored Oct 7, 2024
2 parents 840ccd4 + 520ba76 commit a5df12d
Show file tree
Hide file tree
Showing 15 changed files with 637 additions and 362 deletions.
2 changes: 2 additions & 0 deletions lib/src/model/puzzle/puzzle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class PuzzleData with _$PuzzleData {
required ISet<String> themes,
}) = _PuzzleData;

Side get sideToMove => initialPly.isEven ? Side.black : Side.white;

factory PuzzleData.fromJson(Map<String, dynamic> json) =>
_$PuzzleDataFromJson(json);
}
Expand Down
58 changes: 58 additions & 0 deletions lib/src/utils/connectivity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,61 @@ Future<bool> isOnline(Client client) {
}
return completer.future;
}

extension AsyncValueConnectivity on AsyncValue<ConnectivityStatus> {
/// Switches between device's connectivity status.
///
/// Using this method assumes the the device is offline when the status is
/// not yet available (i.e. [AsyncValue.isLoading].
/// If you want to handle the loading state separately, use
/// [whenIsLoading] instead.
///
/// This method is similar to [AsyncValueX.maybeWhen], but it takes two
/// functions, one for when the device is online and another for when it is
/// offline.
///
/// Example:
/// ```dart
/// final status = ref.watch(connectivityChangesProvider);
/// final result = status.whenIs(
/// online: () => 'Online',
/// offline: () => 'Offline',
/// );
/// ```
R whenIs<R>({
required R Function() online,
required R Function() offline,
}) {
return maybeWhen(
data: (status) => status.isOnline ? online() : offline(),
orElse: offline,
);
}

/// Switches between device's connectivity status, but handling the loading state.
///
/// This method is similar to [AsyncValueX.when], but it takes three
/// functions, one for when the device is online, another for when it is
/// offline, and the last for when the status is still loading.
///
/// Example:
/// ```dart
/// final status = ref.watch(connectivityChangesProvider);
/// final result = status.whenIsLoading(
/// online: () => 'Online',
/// offline: () => 'Offline',
/// loading: () => 'Loading',
/// );
/// ```
R whenIsLoading<R>({
required R Function() online,
required R Function() offline,
required R Function() loading,
}) {
return when(
data: (status) => status.isOnline ? online() : offline(),
loading: loading,
error: (error, stack) => offline(),
);
}
}
2 changes: 2 additions & 0 deletions lib/src/view/puzzle/puzzle_history_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import 'package:timeago/timeago.dart' as timeago;
final _dateFormatter = DateFormat.yMMMd();

class PuzzleHistoryScreen extends StatelessWidget {
const PuzzleHistoryScreen();

@override
Widget build(BuildContext context) {
return PlatformScaffold(
Expand Down
Loading

0 comments on commit a5df12d

Please sign in to comment.