Skip to content

Commit

Permalink
Fix game history screen overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Sep 6, 2024
1 parent 09afb83 commit 609cc71
Showing 1 changed file with 59 additions and 56 deletions.
115 changes: 59 additions & 56 deletions lib/src/view/user/game_history_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class GameHistoryScreen extends ConsumerWidget {
semanticsLabel: context.l10n.filterGames,
onPressed: () => showAdaptiveBottomSheet<GameFilterState>(
context: context,
isScrollControlled: true,
builder: (_) => _FilterGames(
filter: ref.read(gameFilterProvider(filter: gameFilter)),
user: user,
Expand Down Expand Up @@ -250,75 +251,48 @@ class _FilterGamesState extends ConsumerState<_FilterGames> {
filter = widget.filter;
}

static const gamePerfs = [
Perf.ultraBullet,
Perf.bullet,
Perf.blitz,
Perf.rapid,
Perf.classical,
Perf.correspondence,
Perf.chess960,
Perf.antichess,
Perf.kingOfTheHill,
Perf.threeCheck,
Perf.atomic,
Perf.horde,
Perf.racingKings,
Perf.crazyhouse,
];
static const filterGroupSpace = SizedBox(height: 10.0);

@override
Widget build(BuildContext context) {
const gamePerfs = [
Perf.ultraBullet,
Perf.bullet,
Perf.blitz,
Perf.rapid,
Perf.classical,
Perf.correspondence,
Perf.chess960,
Perf.antichess,
Perf.kingOfTheHill,
Perf.threeCheck,
Perf.atomic,
Perf.horde,
Perf.racingKings,
Perf.crazyhouse,
];
const filterGroupSpace = SizedBox(height: 10.0);

final session = ref.read(authSessionProvider);
final userId = widget.user?.id ?? session?.user.id;

List<Perf> availablePerfs(User user) {
final perfs = gamePerfs.where((perf) {
final p = user.perfs[perf];
return p != null && p.numberOfGamesOrRuns > 0;
}).toList(growable: false);
perfs.sort(
(p1, p2) => user.perfs[p2]!.numberOfGamesOrRuns
.compareTo(user.perfs[p1]!.numberOfGamesOrRuns),
);
return perfs;
}

Widget perfFilter(List<Perf> choices) => _Filter<Perf>(
filterName: context.l10n.variant,
filterType: FilterType.multipleChoice,
choices: choices,
choiceSelected: (choice) => filter.perfs.contains(choice),
choiceLabel: (t) => t.shortTitle,
onSelected: (value, selected) => setState(
() {
filter = filter.copyWith(
perfs: selected
? filter.perfs.add(value)
: filter.perfs.remove(value),
);
},
),
);
final Widget filters = userId != null
? ref.watch(userProvider(id: userId)).when(
data: (user) => perfFilter(availablePerfs(user)),
loading: () => const Center(
child: CircularProgressIndicator.adaptive(),
),
error: (_, __) => perfFilter(gamePerfs),
)
: perfFilter(gamePerfs);

return SafeArea(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
filters,
const SizedBox(height: 12.0),
if (userId != null)
ref.watch(userProvider(id: userId)).when(
data: (user) => perfFilter(availablePerfs(user)),
loading: () => const Center(
child: CircularProgressIndicator.adaptive(),
),
error: (_, __) => perfFilter(gamePerfs),
)
else
perfFilter(gamePerfs),
const PlatformDivider(thickness: 1, indent: 0),
filterGroupSpace,
_Filter<Side>(
Expand Down Expand Up @@ -356,6 +330,35 @@ class _FilterGamesState extends ConsumerState<_FilterGames> {
),
);
}

List<Perf> availablePerfs(User user) {
final perfs = gamePerfs.where((perf) {
final p = user.perfs[perf];
return p != null && p.numberOfGamesOrRuns > 0;
}).toList(growable: false);
perfs.sort(
(p1, p2) => user.perfs[p2]!.numberOfGamesOrRuns
.compareTo(user.perfs[p1]!.numberOfGamesOrRuns),
);
return perfs;
}

Widget perfFilter(List<Perf> choices) => _Filter<Perf>(
filterName: context.l10n.variant,
filterType: FilterType.multipleChoice,
choices: choices,
choiceSelected: (choice) => filter.perfs.contains(choice),
choiceLabel: (t) => t.shortTitle,
onSelected: (value, selected) => setState(
() {
filter = filter.copyWith(
perfs: selected
? filter.perfs.add(value)
: filter.perfs.remove(value),
);
},
),
);
}

enum FilterType {
Expand Down

0 comments on commit 609cc71

Please sign in to comment.