Skip to content

Commit

Permalink
Main page upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
foucblg committed Mar 17, 2024
1 parent e3f4e0b commit 6157eeb
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 87 deletions.
5 changes: 5 additions & 0 deletions lib/elocaps/providers/players_provider.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/gestures.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:myecl/user/class/list_users.dart';
import 'package:myecl/user/providers/user_provider.dart';
Expand All @@ -8,6 +9,10 @@ class PlayersNotifier extends StateNotifier<Map<int, SimpleUser>> {
void setPlayer(int playerIndex, SimpleUser user) {
state[playerIndex] = user;
}

void reset() {
state = {0: state.values.first};
}
}

final playersProvider =
Expand Down
3 changes: 1 addition & 2 deletions lib/elocaps/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class ElocapsRouter {

static final Module module = Module(
name: ElocapsTextConstant.elocaps,
icon: const Right(
'/images/beer.svg'), // Mettre un icon venant d'un svg [plus tard]
icon: const Right('images/beer.svg'),
root: ElocapsRouter.root,
selected: false);
ElocapsRouter(this.ref);
Expand Down
2 changes: 2 additions & 0 deletions lib/elocaps/ui/pages/game_page/game_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class GamePage extends HookConsumerWidget {
final gameNotifier = ref.watch(gameProvider.notifier);
final me = ref.watch(userProvider);
final players = ref.watch(playersProvider);
final playersNotifier = ref.watch(playersProvider.notifier);
final playersKey = GlobalKey<FormState>();
final scoreKey = GlobalKey<FormState>();
final playersForm = [
Expand Down Expand Up @@ -215,6 +216,7 @@ class GamePage extends HookConsumerWidget {
mode: modeChosen);
final value = await gameNotifier.createGame(game);
if (value) {
playersNotifier.reset();
displayToastWithContext(
TypeMsg.msg, ElocapsTextConstant.savedGame);
QR.to(ElocapsRouter.root);
Expand Down
166 changes: 81 additions & 85 deletions lib/elocaps/ui/pages/main_page/main_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:heroicons/heroicons.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:myecl/elocaps/class/caps_mode.dart';
import 'package:myecl/elocaps/class/game.dart';
import 'package:myecl/elocaps/providers/leader_board_player_map_notifier.dart';
import 'package:myecl/elocaps/providers/mode_chosen_provider.dart';
import 'package:myecl/elocaps/providers/player_histo_provider.dart';
Expand Down Expand Up @@ -36,104 +36,100 @@ class EloCapsMainPage extends HookConsumerWidget {
ref.read(leaderBoardPlayerListProvider.notifier);
final modeChosenNotifier = ref.watch(modeChosenProvider.notifier);
final history = ref.watch(playerHistoProvider);
void f(List<Game> games) {
print(games.map((e) => e.gamePlayers
.where((user) => user.playerId == me.id)
.first
.hasConfirmed));
}

final displayBadge = history.maybeWhen(
data: (games) {
f(games);
return games.where((e) => !e.isConfirmed && !e.isCancelled).any(
(element) => !element.gamePlayers
.where((user) => user.playerId == me.id)
.first
.hasConfirmed);
},
data: ((games) => games
.where((e) => !e.isConfirmed && !e.isCancelled)
.any((element) => !element.gamePlayers
.where((user) => user.playerId == me.id)
.first
.hasConfirmed)),
orElse: () => false);
return ElocapsTemplate(
child: Refresher(
child: Stack(
children: [
Refresher(
onRefresh: () async {
leaderBoardPlayerNotifier.loadRanking;
},
child: Stack(
child: Column(
children: [
Column(
const SizedBox(height: 5),
const SizedBox(height: 10),
Row(
children: [
const SizedBox(height: 20),
const AlignLeftText(ElocapsTextConstant.gameMode,
padding: EdgeInsets.symmetric(horizontal: 30)),
const SizedBox(height: 20),
HorizontalListView.builder(
items: CapsMode.values,
itemBuilder: (context, item, i) {
final selected = item == modeChosen;
return ItemChip(
selected: selected,
onTap: () {
modeChosenNotifier.setMode(item);
},
child: Text(
capsModeToString(item),
style: TextStyle(
color:
selected ? Colors.white : Colors.black),
));
},
height: 40),
const SizedBox(height: 20),
AutoLoaderChild(
group: leaderBoardPlayerList,
mapKey: modeChosen,
notifier: leaderBoardPlayerListNotifier,
listLoader: leaderBoardPlayerNotifier.loadRanking,
dataBuilder: (context, players) => SingleChildScrollView(
child: Column(children: [
Podium(players: players),
LeaderBoard(players: players),
]),
),
Expanded(
child: HorizontalListView.builder(
items: CapsMode.values,
itemBuilder: (context, item, i) {
final selected = item == modeChosen;
return ItemChip(
selected: selected,
onTap: () {
modeChosenNotifier.setMode(item);
},
child: Text(
capsModeToString(item),
style: TextStyle(
color: selected
? Colors.white
: Colors.black),
));
},
height: 40),
),
GestureDetector(
onTap: () {
QR.to(ElocapsRouter.root + ElocapsRouter.history);
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Center(
child: (displayBadge)
? Badge(
isLabelVisible: displayBadge,
smallSize: 10,
child: const HeroIcon(
HeroIcons.clipboardDocumentList,
size: 30,
))
: const HeroIcon(
HeroIcons.clipboardDocumentList,
size: 30,
)),
)),
],
),
Positioned(
bottom: 20,
left: 0,
right: 0,
child: GestureDetector(
onTap: () {
modeChosenNotifier.setMode(CapsMode.values.first);
QR.to(ElocapsRouter.root + ElocapsRouter.game);
},
child: const MyButton(
text: ElocapsTextConstant.play,
),
const SizedBox(height: 20),
AutoLoaderChild(
group: leaderBoardPlayerList,
mapKey: modeChosen,
notifier: leaderBoardPlayerListNotifier,
listLoader: leaderBoardPlayerNotifier.loadRanking,
dataBuilder: (context, players) => SingleChildScrollView(
child: Column(children: [
Podium(players: players),
LeaderBoard(players: players),
]),
),
),
Positioned(
top: 0,
right: 10,
child: GestureDetector(
onTap: () {
QR.to(ElocapsRouter.root + ElocapsRouter.history);
},
child: Center(
child: (displayBadge)
? Badge(
isLabelVisible: displayBadge,
smallSize: 10,
child: const HeroIcon(
HeroIcons.clipboardDocumentList,
size: 30,
))
: const HeroIcon(
HeroIcons.clipboardDocumentList,
size: 30,
))),
)
],
)));
)),
Positioned(
bottom: 10,
left: 0,
right: 0,
child: GestureDetector(
onTap: () {
modeChosenNotifier.setMode(CapsMode.values.first);
QR.to(ElocapsRouter.root + ElocapsRouter.game);
},
child: const MyButton(
text: ElocapsTextConstant.play,
),
),
),
],
));
}
}

0 comments on commit 6157eeb

Please sign in to comment.