Skip to content

Commit

Permalink
Merge pull request #608 from HaonRekcef/fix-puzzle-storm-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce authored Mar 28, 2024
2 parents fea545b + bd09eba commit 8691ecc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
12 changes: 6 additions & 6 deletions lib/src/model/puzzle/puzzle_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ Future<IList<PuzzleHistoryEntry>?> puzzleRecentActivity(
}

@riverpod
Future<StormDashboard?> stormDashboard(StormDashboardRef ref) async {
final session = ref.watch(authSessionProvider);
if (session == null) return null;
return ref.withClientCacheFor(
(client) => PuzzleRepository(client).stormDashboard(session.user.id),
const Duration(minutes: 30),
Future<StormDashboard?> stormDashboard(
StormDashboardRef ref, {
required UserId id,
}) async {
return ref.withClient(
(client) => PuzzleRepository(client).stormDashboard(id),
);
}

Expand Down
15 changes: 11 additions & 4 deletions lib/src/view/puzzle/storm_dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:lichess_mobile/src/model/puzzle/puzzle_providers.dart';
import 'package:lichess_mobile/src/model/user/user.dart';
import 'package:lichess_mobile/src/styles/lichess_colors.dart';
import 'package:lichess_mobile/src/styles/lichess_icons.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
Expand All @@ -12,7 +13,9 @@ import 'package:lichess_mobile/src/widgets/shimmer.dart';
import 'package:lichess_mobile/src/widgets/stat_card.dart';

class StormDashboardModal extends StatelessWidget {
const StormDashboardModal({super.key});
const StormDashboardModal({super.key, required this.user});

final LightUser user;

@override
Widget build(BuildContext context) {
Expand All @@ -28,10 +31,10 @@ class StormDashboardModal extends StatelessWidget {
],
),
),
child: _Body(),
child: _Body(user: user),
)
: Scaffold(
body: _Body(),
body: _Body(user: user),
appBar: AppBar(
title: Row(
children: [
Expand All @@ -46,9 +49,13 @@ class StormDashboardModal extends StatelessWidget {
}

class _Body extends ConsumerWidget {
const _Body({required this.user});

final LightUser user;

@override
Widget build(BuildContext context, WidgetRef ref) {
final stormDashboard = ref.watch(stormDashboardProvider);
final stormDashboard = ref.watch(stormDashboardProvider(id: user.id));
return stormDashboard.when(
data: (data) {
if (data == null) {
Expand Down
9 changes: 5 additions & 4 deletions lib/src/view/puzzle/storm_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -877,14 +877,14 @@ class _StormDashboardButton extends ConsumerWidget {
case TargetPlatform.iOS:
return CupertinoIconButton(
padding: EdgeInsets.zero,
onPressed: () => _showDashboard(context),
onPressed: () => _showDashboard(context, session),
semanticsLabel: 'Storm History',
icon: const Icon(Icons.history),
);
case TargetPlatform.android:
return IconButton(
tooltip: 'Storm History',
onPressed: () => _showDashboard(context),
onPressed: () => _showDashboard(context, session),
icon: const Icon(Icons.history),
);
default:
Expand All @@ -895,10 +895,11 @@ class _StormDashboardButton extends ConsumerWidget {
return const SizedBox.shrink();
}

void _showDashboard(BuildContext context) => pushPlatformRoute(
void _showDashboard(BuildContext context, AuthSessionState session) =>
pushPlatformRoute(
context,
rootNavigator: true,
fullscreenDialog: true,
builder: (_) => const StormDashboardModal(),
builder: (_) => StormDashboardModal(user: session.user),
);
}
2 changes: 1 addition & 1 deletion lib/src/view/user/perf_cards.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class PerfCards extends StatelessWidget {
builder: (context) {
switch (perf) {
case Perf.storm:
return const StormDashboardModal();
return StormDashboardModal(user: user.lightUser);
default:
return PerfStatsScreen(
user: user,
Expand Down
19 changes: 7 additions & 12 deletions lib/src/view/user/perf_stats_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PerfStatsScreen extends StatelessWidget {
return Scaffold(
appBar: AppBar(
titleSpacing: 0,
title: _Title(user: user, perf: perf),
title: _Title(perf: perf),
),
body: _Body(user: user, perf: perf),
);
Expand All @@ -65,31 +65,26 @@ class PerfStatsScreen extends StatelessWidget {
Widget _iosBuilder(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: _Title(user: user, perf: perf),
middle: _Title(perf: perf),
),
child: _Body(user: user, perf: perf),
);
}
}

class _Title extends StatelessWidget {
const _Title({required this.user, required this.perf});
const _Title({required this.perf});

final User user;
final Perf perf;

@override
Widget build(BuildContext context) {
return Row(
children: [
Flexible(
child: UserFullNameWidget(user: user.lightUser),
),
Flexible(
child: Text(
' ${context.l10n.perfStatPerfStats(perf.title)}',
overflow: TextOverflow.ellipsis,
),
Icon(perf.icon),
Text(
' ${context.l10n.perfStatPerfStats(perf.title)}',
overflow: TextOverflow.ellipsis,
),
],
);
Expand Down

0 comments on commit 8691ecc

Please sign in to comment.