Skip to content

Commit

Permalink
fixing inconsistent player tiles ordering when logging a game (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkieres authored Apr 15, 2023
1 parent 3f6a83d commit 91bdaf8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
7 changes: 7 additions & 0 deletions board_games_companion/lib/extensions/players_extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import '../models/hive/player.dart';

extension PlayersExtensions on List<Player> {
List<Player> sortAlphabetically() {
return [...this]..sort((player, otherPlayer) => player.name!.compareTo(otherPlayer.name!));
}
}
2 changes: 2 additions & 0 deletions board_games_companion/lib/models/hive/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:image_picker/image_picker.dart';
import '../../common/constants.dart';
import '../../common/hive_boxes.dart';

export '../../extensions/players_extensions.dart';

part 'player.freezed.dart';
part 'player.g.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ abstract class _PlaythroughPlayersSelectionViewModel with Store {
final PlayersStore _playersStore;

@computed
ObservableList<Player> get players => ([..._playersStore.players]
..sort((player, otherPlayer) => player.name!.compareTo(otherPlayer.name!)))
.asObservable();
ObservableList<Player> get players =>
([..._playersStore.players].sortAlphabetically()).asObservable();

@computed
Map<String, Player> get playersMap => {for (final player in players) player.id: player};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,22 @@ class PlaythroughsLogGamePageState extends State<PlaythroughsLogGamePage> {
},
),
Observer(
builder: (_) {
return _PlayersSection(
playthroughTimeline: viewModel.playthroughTimeline,
gameFamily: viewModel.gameFamily,
players: viewModel.playersState,
onCreatePlayer: () => _handleCreatePlayer(),
onSelectPlayers: () => _handleSelectPlayers(),
onPlayerScoreUpdated: (playerScore, score) =>
_handlePlayerScoreUpdate(playerScore, score),
);
},
builder: (_) => _PlayersSection(
playthroughTimeline: viewModel.playthroughTimeline,
gameFamily: viewModel.gameFamily,
players: viewModel.playersState,
onCreatePlayer: () => _handleCreatePlayer(),
onSelectPlayers: () => _handleSelectPlayers(),
onPlayerScoreUpdated: (playerScore, score) =>
_handlePlayerScoreUpdate(playerScore, score),
),
),
Observer(builder: (_) {
return _SubmitSection(
Observer(
builder: (_) => _SubmitSection(
players: viewModel.playersState,
onLogPlaythrough: () => _handleLoggingPlaythrough(),
);
}),
),
),
],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ abstract class _PlaythroughsLogGameViewModel with Store {
}

playersState = PlaythroughsLogGamePlayers.playersSelected(
players: selectedPlayers,
players: selectedPlayers.sortAlphabetically(),
playerScores: playerScores,
);
}
Expand Down

0 comments on commit 91bdaf8

Please sign in to comment.