Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-mayank committed Nov 27, 2024
1 parent ec82ede commit 4cd3df3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
13 changes: 3 additions & 10 deletions data/lib/api/ball_score/ball_score_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -640,26 +640,19 @@ extension BallScoreList on List<BallScoreModel> {
String currentUserId, {
UserStat? oldUserStats,
UserStatType? type,
bool isMatchComplete = false,
}) {
final newBattingStat = calculateBattingStats(currentUserId);
final newBowlingStat = calculateBowlingStats(currentUserId);
final newFieldingStat = calculateFieldingStats(currentUserId);

final uniqueMatches = where(
(ball) =>
ball.batsman_id == currentUserId ||
ball.non_striker_id == currentUserId ||
ball.bowler_id == currentUserId ||
ball.player_out_id == currentUserId ||
ball.wicket_taker_id == currentUserId,
).map((ball) => ball.match_id).toSet();

final newUserStats = UserStat(
matches: uniqueMatches.length,
matches: isMatchComplete ? 1 : 0,
type: type,
batting: newBattingStat,
bowling: newBowlingStat,
fielding: newFieldingStat,

);

return oldUserStats?.updateStat(newUserStats) ?? newUserStats;
Expand Down
11 changes: 7 additions & 4 deletions khelo/lib/ui/flow/score_board/score_board_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {
}
}

void _addPlayerStats() async {
void _addPlayerStats({bool isMatchComplete = false}) async {
try {
final userStatType = state.match?.match_type == MatchType.testMatch
? UserStatType.test
Expand All @@ -787,8 +787,11 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {
element.wicket_taker_id == player,
)
.toList()
.calculateUserStats(player,
oldUserStats: oldStats, type: userStatType);
.calculateUserStats(
player,
oldUserStats: oldStats,
type: userStatType,
);
await _userService.updateUserStats(player, newState);
}
} catch (e) {
Expand Down Expand Up @@ -1200,7 +1203,7 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {
}
try {
state = state.copyWith(actionError: null, isActionInProgress: true);
_addPlayerStats();
_addPlayerStats(isMatchComplete: true);
List<MatchPlayer> batsMan = [];
if (state.batsMans?.isNotEmpty ?? false) {
batsMan = state.batsMans!
Expand Down

0 comments on commit 4cd3df3

Please sign in to comment.