Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions lib/src/model/game/archived_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,18 @@ class LightArchivedGame with _$LightArchivedGame {

factory LightArchivedGame.fromServerJson(
Map<String, dynamic> json, {

/// Whether to ask the server if the game is bookmarked
bool withBookmarked = false,

/// Whether it is already known that the game is bookmarked
bool isBookmarked = false,
}) {
return _lightArchivedGameFromPick(pick(json).required(), withBookmarked: withBookmarked);
return _lightArchivedGameFromPick(
pick(json).required(),
withBookmarked: withBookmarked,
isBookmarked: isBookmarked,
);
}

factory LightArchivedGame.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -208,7 +217,11 @@ ArchivedGame _archivedGameFromPick(RequiredPick pick, {bool withBookmarked = fal
);
}

LightArchivedGame _lightArchivedGameFromPick(RequiredPick pick, {bool withBookmarked = false}) {
LightArchivedGame _lightArchivedGameFromPick(
RequiredPick pick, {
bool withBookmarked = false,
bool isBookmarked = false,
}) {
return LightArchivedGame(
id: pick('id').asGameIdOrThrow(),
fullId: pick('fullId').asGameFullIdOrNull(),
Expand All @@ -229,7 +242,12 @@ LightArchivedGame _lightArchivedGameFromPick(RequiredPick pick, {bool withBookma
lastMove: pick('lastMove').asUciMoveOrNull(),
clock: pick('clock').letOrNull(_clockDataFromPick),
opening: pick('opening').letOrNull(_openingFromPick),
bookmarked: withBookmarked ? pick('bookmarked').asBoolOrFalse() : null,
bookmarked:
isBookmarked
? true
: withBookmarked
? pick('bookmarked').asBoolOrFalse()
: null,
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/game/game_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class GameRepository {
},
),
headers: {'Accept': 'application/x-ndjson'},
mapper: (json) => LightArchivedGame.fromServerJson(json),
mapper: (json) => LightArchivedGame.fromServerJson(json, isBookmarked: true),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this. The server should already return the right value, and we should not have to override it client side.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server only sends bookmark games so it doesn't add the field bookmarked: true in the json as it would just wastes bandwidth.

)
.then(
(value) =>
Expand Down
1 change: 1 addition & 0 deletions lib/src/view/account/game_bookmarks_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class _BodyState extends ConsumerState<_Body> {
Theme.of(context).platform == TargetPlatform.iOS
? const EdgeInsets.symmetric(horizontal: 14.0, vertical: 12.0)
: null,
onPressedBookmark: onRemoveBookmark,
);

return Slidable(
Expand Down