Skip to content

Commit

Permalink
Merge pull request #662 from lichess-org/carousel
Browse files Browse the repository at this point in the history
Ongoing games carousel
  • Loading branch information
veloce authored May 6, 2024
2 parents 8051e3d + e7873ec commit f1d8179
Show file tree
Hide file tree
Showing 6 changed files with 484 additions and 50 deletions.
11 changes: 10 additions & 1 deletion lib/src/model/correspondence/correspondence_game_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ Future<IList<(DateTime, OfflineCorrespondenceGame)>>
// cannot use ref.watch because it would create a circular dependency
// as we invalidate this provider in the storage save and delete methods
final storage = ref.read(correspondenceGameStorageProvider);
return storage.fetchOngoingGames(session?.user.id);
final data = await storage.fetchOngoingGames(session?.user.id);
return data.sort(
(a, b) {
final aIsMyTurn = a.$2.isMyTurn;
final bIsMyTurn = b.$2.isMyTurn;
if (aIsMyTurn && !bIsMyTurn) return -1;
if (!aIsMyTurn && bIsMyTurn) return 1;
return b.$1.compareTo(a.$1);
},
);
}

const kCorrespondenceStorageTable = 'correspondence_game';
Expand Down
2 changes: 2 additions & 0 deletions lib/src/model/correspondence/offline_correspondence_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class OfflineCorrespondenceGame

Side get sideToMove => lastPosition.turn;

bool get isMyTurn => sideToMove == youAre;

Duration? myTimeLeft(DateTime lastModifiedTime) =>
estimatedTimeLeft(youAre, lastModifiedTime);

Expand Down
Loading

0 comments on commit f1d8179

Please sign in to comment.