Skip to content

Commit

Permalink
fixing an issue with logging a game in the past (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkieres authored Nov 14, 2022
1 parent deb2fd3 commit bb53909
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
6 changes: 6 additions & 0 deletions board_games_companion/lib/common/app_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ class AppText {
static const filterGamesPanelClearFiltersButtonText = 'Clear filters';

static const playthroughsLogGamePageHeader = 'Log a game';
static const playthroughsLogGamePlayingPlayedHeaderTitle = 'Playing or played';
static const playthroughsLogGamePlayingNowOption = 'Playing now';
static const playthroughsLogGamePlayedOption = 'Played some time ago';
static const playthroughsLogGamePagePlayerScoresStepTitle = 'Player scores';
static const playthroughsLogGamePageCreatePlayerButtonText = 'Create Player';
static const playthroughsLogGamePageCreatePlayerTitle =
'To log a game, you need to create players first';

static const importCollectionsSucceeded = 'Your collection has been imported from BGG!';
static const importCollectionsButtonText = 'Import';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,13 @@ class _LogPlaythroughStepperState extends State<_LogPlaythroughStepper> {
currentStep: widget.viewModel.logGameStep,
steps: [
Step(
title: const Text('Playing or played'),
title: const Text(AppText.playthroughsLogGamePlayingPlayedHeaderTitle),
state:
completedSteps > playingOrPlayedStep ? StepState.complete : StepState.indexed,
content: _PlayingOrPlayedStep(
viewModel: widget.viewModel,
onSelectionChanged: (PlaythroughStartTime playthroughStartTime) =>
setState(() {}),
),
viewModel: widget.viewModel,
onSelectionChanged: (PlaythroughStartTime playthroughStartTime) =>
setState(() {})),
),
Step(
title: const Text('Select date'),
Expand Down Expand Up @@ -141,6 +140,7 @@ class _LogPlaythroughStepperState extends State<_LogPlaythroughStepper> {
playthroughPlayers: widget.viewModel.playthroughPlayers.toList(),
onPlayerSelectionChanged: (bool? isSelected, PlaythroughPlayer player) =>
_togglePlayerSelection(isSelected, player),
onCreatePlayer: () async => _handleCreatePlayer(),
);
},
),
Expand Down Expand Up @@ -285,6 +285,16 @@ class _LogPlaythroughStepperState extends State<_LogPlaythroughStepper> {
);
}

Future<void> _handleCreatePlayer() async {
await Navigator.pushNamed(
context,
PlayerPage.pageRoute,
arguments: const PlayerPageArguments(),
);
// MK Reload players after getting back from players page
widget.viewModel.loadPlaythroughPlayers();
}

void _togglePlayerSelection(bool? isSelected, PlaythroughPlayer player) {
if (isSelected == null) {
return;
Expand Down Expand Up @@ -405,7 +415,7 @@ class _PlayingOrPlayedStepState extends State<_PlayingOrPlayedStep> {
},
),
Text(
'Playing now',
AppText.playthroughsLogGamePlayingNowOption,
style: AppTheme.theme.textTheme.bodyText1,
),
],
Expand All @@ -428,7 +438,7 @@ class _PlayingOrPlayedStepState extends State<_PlayingOrPlayedStep> {
},
),
Text(
'Played some time ago',
AppText.playthroughsLogGamePlayedOption,
style: AppTheme.theme.textTheme.bodyText1,
),
],
Expand All @@ -452,10 +462,7 @@ class _PlayingOrPlayedStepState extends State<_PlayingOrPlayedStep> {
fontSize: Dimensions.doubleExtraLargeFontSize,
),
),
Text(
'h',
style: AppTheme.theme.textTheme.bodyText2,
),
Text('h', style: AppTheme.theme.textTheme.bodyText2),
const SizedBox(width: Dimensions.halfStandardSpacing),
NumberPicker(
value: math.min(Duration.minutesPerHour - 1, minutesPlyed),
Expand All @@ -469,10 +476,7 @@ class _PlayingOrPlayedStepState extends State<_PlayingOrPlayedStep> {
fontSize: Dimensions.doubleExtraLargeFontSize,
),
),
Text(
'min ',
style: AppTheme.theme.textTheme.bodyText2,
),
Text('min ', style: AppTheme.theme.textTheme.bodyText2),
],
),
],
Expand Down Expand Up @@ -507,15 +511,17 @@ class _SelectPlayersStep extends StatelessWidget {
Key? key,
required this.playthroughPlayers,
required this.onPlayerSelectionChanged,
required this.onCreatePlayer,
}) : super(key: key);

final List<PlaythroughPlayer>? playthroughPlayers;
final Function(bool?, PlaythroughPlayer) onPlayerSelectionChanged;
final void Function(bool?, PlaythroughPlayer) onPlayerSelectionChanged;
final VoidCallback onCreatePlayer;

@override
Widget build(BuildContext context) {
if (playthroughPlayers?.isEmpty ?? true) {
return const _NoPlayers();
return _NoPlayers(onCreatePlayer: () => onCreatePlayer());
}

return SizedBox(
Expand Down Expand Up @@ -657,30 +663,27 @@ class _Players extends StatelessWidget {

class _NoPlayers extends StatelessWidget {
const _NoPlayers({
required this.onCreatePlayer,
Key? key,
}) : super(key: key);

final VoidCallback onCreatePlayer;

@override
Widget build(BuildContext context) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(
'To log a game, you need to create players first',
AppText.playthroughsLogGamePageCreatePlayerTitle,
style: AppTheme.theme.textTheme.bodyText1,
),
const SizedBox(
height: Dimensions.halfStandardSpacing,
),
const SizedBox(height: Dimensions.halfStandardSpacing),
Align(
alignment: Alignment.topRight,
child: ElevatedIconButton(
title: 'Create Player',
title: AppText.playthroughsLogGamePageCreatePlayerButtonText,
icon: const DefaultIcon(Icons.add),
onPressed: () => Navigator.pushNamed(
context,
PlayerPage.pageRoute,
arguments: const PlayerPageArguments(),
),
onPressed: () => onCreatePlayer(),
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract class _PlaythroughsLogGameViewModel with Store {
final indexOfPlaythroughPlayer =
playthroughPlayers.indexWhere((pp) => pp.player.id == playthroughPlayer.player.id);
playthroughPlayers[indexOfPlaythroughPlayer] = playthroughPlayer.copyWith(isChecked: true);
playthroughPlayers = ObservableList.of(playthroughPlayers);
// playthroughPlayers = ObservableList.of(playthroughPlayers);
playerScores[playthroughPlayer.player.id] = PlayerScore(
player: playthroughPlayer.player,
score: Score(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class PlaythroughService extends BaseHiveService<Playthrough, PlaythroughService
if (duration == null) {
newPlaythrough = newPlaythrough.copyWith(status: PlaythroughStatus.Started);
} else {
newPlaythrough.copyWith(
newPlaythrough = newPlaythrough.copyWith(
status: PlaythroughStatus.Finished,
endDate: startDate.add(duration),
);
Expand Down

0 comments on commit bb53909

Please sign in to comment.