Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcast player results screen #1253

Merged
merged 21 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
39 changes: 19 additions & 20 deletions lib/src/view/broadcast/broadcast_game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:lichess_mobile/src/constants.dart';
import 'package:lichess_mobile/src/model/analysis/analysis_preferences.dart';
import 'package:lichess_mobile/src/model/broadcast/broadcast.dart';
import 'package:lichess_mobile/src/model/broadcast/broadcast_game_controller.dart';
import 'package:lichess_mobile/src/model/broadcast/broadcast_round_controller.dart';
import 'package:lichess_mobile/src/model/common/chess.dart';
import 'package:lichess_mobile/src/model/common/eval.dart';
import 'package:lichess_mobile/src/model/common/id.dart';
Expand All @@ -19,6 +18,7 @@ import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/view/analysis/analysis_layout.dart';
import 'package:lichess_mobile/src/view/broadcast/broadcast_game_bottom_bar.dart';
import 'package:lichess_mobile/src/view/broadcast/broadcast_game_screen_providers.dart';
import 'package:lichess_mobile/src/view/broadcast/broadcast_game_settings.dart';
import 'package:lichess_mobile/src/view/broadcast/broadcast_game_tree_view.dart';
import 'package:lichess_mobile/src/view/broadcast/broadcast_player_results_screen.dart';
Expand Down Expand Up @@ -82,17 +82,21 @@ class _BroadcastGameScreenState extends ConsumerState<BroadcastGameScreen>

@override
Widget build(BuildContext context) {
final broadcastGameState = ref
.watch(broadcastGameControllerProvider(widget.roundId, widget.gameId));
final title = ref.watch(
broadcastRoundControllerProvider(widget.roundId)
.select((round) => round.value?.round.name),
final broadcastGameState = ref.watch(
broadcastGameProvider(widget.roundId, widget.gameId),
);
final broadcastGamePgn = ref
.watch(broadcastGameControllerProvider(widget.roundId, widget.gameId));
final title = widget.title ??
(switch (ref.watch(broadcastGameScreenTitleProvider(widget.roundId))) {
AsyncData(value: final title) => title,
_ => 'Broadcast Game',
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather have a SizedBox.shrink() here than a default title.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

});

return PlatformScaffold(
appBar: PlatformAppBar(
title: Text(
widget.title ?? title ?? 'BroadcastGame',
title,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
Expand All @@ -102,7 +106,7 @@ class _BroadcastGameScreenState extends ConsumerState<BroadcastGameScreen>
controller: _tabController,
),
AppBarIconButton(
onPressed: (broadcastGameState.hasValue)
onPressed: (broadcastGamePgn.hasValue)
? () {
pushPlatformRoute(
context,
Expand All @@ -118,16 +122,19 @@ class _BroadcastGameScreenState extends ConsumerState<BroadcastGameScreen>
),
],
),
body: switch (broadcastGameState) {
AsyncData() => _Body(
body: switch ((broadcastGameState, broadcastGamePgn)) {
(AsyncData(), AsyncData()) => _Body(
widget.tournamentId,
widget.roundId,
widget.gameId,
widget.tournamentSlug,
widget.roundSlug,
tabController: _tabController,
),
AsyncError(:final error) => Center(
(AsyncError(:final error), _) => Center(
child: Text('Cannot load broadcast game: $error'),
),
(_, AsyncError(:final error)) => Center(
child: Text('Cannot load broadcast game: $error'),
),
_ => const Center(child: CircularProgressIndicator.adaptive()),
Expand Down Expand Up @@ -385,15 +392,7 @@ class _PlayerWidget extends ConsumerWidget {
final broadcastGameState = ref
.watch(broadcastGameControllerProvider(roundId, gameId))
.requireValue;
// TODO
// we'll probably want to remove this and get the game state from a single controller
// this won't work with deep links for instance
final game = ref.watch(
broadcastRoundControllerProvider(roundId)
.select((round) => round.value?.games[gameId]),
);

if (game == null) return const SizedBox.shrink();
final game = ref.watch(broadcastGameProvider(roundId, gameId)).requireValue;

final isCursorOnLiveMove =
broadcastGameState.currentPath == broadcastGameState.broadcastLivePath;
Expand Down
30 changes: 30 additions & 0 deletions lib/src/view/broadcast/broadcast_game_screen_providers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/model/broadcast/broadcast.dart';
import 'package:lichess_mobile/src/model/broadcast/broadcast_round_controller.dart';
import 'package:lichess_mobile/src/model/common/id.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'broadcast_game_screen_providers.g.dart';

@riverpod
Future<BroadcastGame> broadcastGame(
Ref ref,
BroadcastRoundId roundId,
BroadcastGameId gameId,
) {
return ref.watch(
broadcastRoundControllerProvider(roundId)
.selectAsync((round) => round.games[gameId]!),
);
}

@riverpod
Future<String> broadcastGameScreenTitle(
Ref ref,
BroadcastRoundId roundId,
) {
return ref.watch(
broadcastRoundControllerProvider(roundId)
.selectAsync((round) => round.round.name),
);
}
Loading