Skip to content

Commit

Permalink
fix team detail not updating (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sidhdhi-p authored Jun 26, 2024
1 parent 03a6bab commit 4a8a07d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion khelo/lib/ui/flow/matches/add_match/add_match_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class _AddMatchScreenState extends ConsumerState<AddMatchScreen> {
ref.listen(addMatchViewStateProvider.select((value) => value.pop),
(previous, next) {
if (next != null && next) {
context.pop();
context.pop(true);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion khelo/lib/ui/flow/team/add_team/add_team_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class _AddTeamScreenState extends ConsumerState<AddTeamScreen> {
addTeamStateProvider.select((value) => value.isPop),
(previous, current) async {
if (current && context.mounted) {
context.pop();
context.pop(current);
}
},
);
Expand Down
30 changes: 22 additions & 8 deletions khelo/lib/ui/flow/team/detail/team_detail_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:data/api/user/user_models.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -70,7 +71,7 @@ class _TeamDetailScreenState extends ConsumerState<TeamDetailScreen> {
? Icons.more_horiz_rounded
: Icons.more_vert_rounded,
color: context.colorScheme.textPrimary),
onPressed: () => _moreActionButton(context, state),
onPressed: () => _moreActionButton(context, notifier, state),
),
]
: null,
Expand Down Expand Up @@ -185,32 +186,45 @@ class _TeamDetailScreenState extends ConsumerState<TeamDetailScreen> {

void _moreActionButton(
BuildContext context,
TeamDetailViewNotifier notifier,
TeamDetailState state,
) async {
return showActionBottomSheet(context: context, items: [
BottomSheetAction(
title: context.l10n.common_edit_team_title,
onTap: () {
onTap: () async {
context.pop();
AppRoute.addTeam(team: state.team).push(context);
bool? isUpdated =
await AppRoute.addTeam(team: state.team).push<bool>(context);
if (isUpdated == true && context.mounted) {
notifier.loadTeamById();
}
},
),
BottomSheetAction(
title: context.l10n.add_match_screen_title,
onTap: () {
onTap: () async {
context.pop();
AppRoute.addMatch(
bool? isUpdated = await AppRoute.addMatch(
defaultTeam: (state.team?.players?.length ?? 0) >= 2
? state.team
: null)
.push(context);
.push<bool>(context);
if (isUpdated == true && context.mounted) {
notifier.loadTeamById();
}
},
),
BottomSheetAction(
title: context.l10n.team_list_add_members_title,
onTap: () {
onTap: () async {
context.pop();
AppRoute.addTeamMember(team: state.team!).push(context);
List<UserModel>? memberList =
await AppRoute.addTeamMember(team: state.team!)
.push<List<UserModel>>(context);
if (memberList != null && context.mounted) {
notifier.updateTeamMember(memberList);
}
},
),
]);
Expand Down
11 changes: 9 additions & 2 deletions khelo/lib/ui/flow/team/detail/team_detail_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:data/api/match/match_model.dart';
import 'package:data/api/team/team_model.dart';
import 'package:data/api/user/user_models.dart';
import 'package:data/service/match/match_service.dart';
import 'package:data/service/team/team_service.dart';
import 'package:data/storage/app_preferences.dart';
Expand Down Expand Up @@ -36,7 +37,7 @@ class TeamDetailViewNotifier extends StateNotifier<TeamDetailState> {
}

try {
state = state.copyWith(loading: true);
state = state.copyWith(loading: state.team == null);

final team = await _teamService.getTeamById(teamId!);
state = state.copyWith(team: team, loading: false);
Expand All @@ -53,7 +54,7 @@ class TeamDetailViewNotifier extends StateNotifier<TeamDetailState> {
return;
}
try {
state = state.copyWith(loading: true);
state = state.copyWith(loading: state.matches == null);
final matches = await _matchService
.getMatchesByTeamId(state.team!.id ?? "INVALID ID");
final teamStat = _calculateTeamStat(matches);
Expand Down Expand Up @@ -187,6 +188,12 @@ class TeamDetailViewNotifier extends StateNotifier<TeamDetailState> {
);
}

void updateTeamMember(List<UserModel> members) {
state = state.copyWith(
team: state.team
?.copyWith(players: [...state.team?.players ?? [], ...members]));
}

void onTabChange(int tab) {
if (state.selectedTab != tab) {
state = state.copyWith(selectedTab: tab);
Expand Down

0 comments on commit 4a8a07d

Please sign in to comment.