Skip to content

Commit

Permalink
Merge branch 'nav-28-stats-screen-update'
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Apr 17, 2024
2 parents ac570f9 + 6dc0c05 commit d8b63a1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 13 deletions.
6 changes: 4 additions & 2 deletions lib/src/view/user/perf_cards.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:lichess_mobile/src/styles/lichess_icons.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/view/account/rating_pref_aware.dart';
import 'package:lichess_mobile/src/view/puzzle/dashboard_screen.dart';
import 'package:lichess_mobile/src/view/puzzle/storm_dashboard.dart';
import 'package:lichess_mobile/src/view/user/perf_stats_screen.dart';
import 'package:lichess_mobile/src/widgets/buttons.dart';
Expand Down Expand Up @@ -49,8 +50,7 @@ class PerfCards extends StatelessWidget {
itemBuilder: (context, index) {
final perf = userPerfs[index];
final userPerf = user.perfs[perf]!;
final bool isPerfWithoutStats =
Perf.puzzle == perf || Perf.streak == perf;
final bool isPerfWithoutStats = Perf.streak == perf;
return SizedBox(
height: 100,
width: 100,
Expand Down Expand Up @@ -125,6 +125,8 @@ class PerfCards extends StatelessWidget {
switch (perf) {
case Perf.storm:
return StormDashboardModal(user: user.lightUser);
case Perf.puzzle:
return PuzzleDashboardScreen(user: user.lightUser);
default:
return PerfStatsScreen(
user: user,
Expand Down
65 changes: 54 additions & 11 deletions lib/src/view/user/perf_stats_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:lichess_mobile/l10n/l10n.dart';
import 'package:lichess_mobile/src/constants.dart';
import 'package:lichess_mobile/src/model/auth/auth_session.dart';
import 'package:lichess_mobile/src/model/common/http.dart';
import 'package:lichess_mobile/src/model/common/perf.dart';
Expand All @@ -23,6 +24,7 @@ import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/utils/string.dart';
import 'package:lichess_mobile/src/view/game/archived_game_screen.dart';
import 'package:lichess_mobile/src/widgets/adaptive_action_sheet.dart';
import 'package:lichess_mobile/src/widgets/buttons.dart';
import 'package:lichess_mobile/src/widgets/feedback.dart';
import 'package:lichess_mobile/src/widgets/list.dart';
Expand Down Expand Up @@ -61,7 +63,7 @@ class PerfStatsScreen extends StatelessWidget {
return Scaffold(
appBar: AppBar(
titleSpacing: 0,
title: _Title(perf: perf),
title: _Title(user: user, perf: perf),
),
body: _Body(user: user, perf: perf),
);
Expand All @@ -70,28 +72,69 @@ class PerfStatsScreen extends StatelessWidget {
Widget _iosBuilder(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: _Title(perf: perf),
middle: _Title(user: user, perf: perf),
),
child: _Body(user: user, perf: perf),
);
}
}

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

final Perf perf;
final User user;

@override
Widget build(BuildContext context) {
return Row(
children: [
Icon(perf.icon),
Text(
' ${context.l10n.perfStatPerfStats(perf.title)}',
overflow: TextOverflow.ellipsis,
),
],
final allPerfs = Perf.values.where((element) {
if ([Perf.storm, Perf.puzzle, Perf.streak, Perf.fromPosition]
.contains(element)) {
return false;
}
final p = user.perfs[element];
return p != null &&
p.numberOfGames > 0 &&
p.ratingDeviation < kClueLessDeviation;
}).toList(growable: false);
return AppBarTextButton(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(perf.icon),
Text(
' ${context.l10n.perfStatPerfStats(perf.title)}',
overflow: TextOverflow.ellipsis,
),
const Icon(Icons.arrow_drop_down),
],
),
onPressed: () {
showAdaptiveActionSheet<void>(
context: context,
actions: allPerfs.map((p) {
return BottomSheetAction(
makeLabel: (context) => Text(
context.l10n.perfStatPerfStats(p.title),
overflow: TextOverflow.ellipsis,
),
trailing: Icon(
LichessIcons.circle,
color: perf == p ? LichessColors.good : LichessColors.grey,
size: 16,
),
onPressed: (ctx) {
pushReplacementPlatformRoute(
context,
builder: (ctx) {
return PerfStatsScreen(user: user, perf: p);
},
);
},
);
}).toList(growable: false),
);
},
);
}
}
Expand Down

0 comments on commit d8b63a1

Please sign in to comment.