Skip to content

Commit

Permalink
Merge pull request #74 from canopas/Mayank/hide-deactivate-users
Browse files Browse the repository at this point in the history
Hide deactivated users
  • Loading branch information
cp-mayank authored Jul 10, 2024
2 parents 295e21a + affaaf0 commit f60ca81
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 45 deletions.
1 change: 1 addition & 0 deletions data/lib/api/user/user_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class UserModel with _$UserModel {
PlayerRole? player_role,
BattingStyle? batting_style,
BowlingStyle? bowling_style,
@Default(true) bool isActive,
}) = _UserModel;

factory UserModel.fromJson(Map<String, dynamic> json) =>
Expand Down
37 changes: 30 additions & 7 deletions data/lib/api/user/user_models.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mixin _$UserModel {
PlayerRole? get player_role => throw _privateConstructorUsedError;
BattingStyle? get batting_style => throw _privateConstructorUsedError;
BowlingStyle? get bowling_style => throw _privateConstructorUsedError;
bool get isActive => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
Expand All @@ -60,7 +61,8 @@ abstract class $UserModelCopyWith<$Res> {
DateTime? updated_at,
PlayerRole? player_role,
BattingStyle? batting_style,
BowlingStyle? bowling_style});
BowlingStyle? bowling_style,
bool isActive});
}

/// @nodoc
Expand Down Expand Up @@ -90,6 +92,7 @@ class _$UserModelCopyWithImpl<$Res, $Val extends UserModel>
Object? player_role = freezed,
Object? batting_style = freezed,
Object? bowling_style = freezed,
Object? isActive = null,
}) {
return _then(_value.copyWith(
id: null == id
Expand Down Expand Up @@ -148,6 +151,10 @@ class _$UserModelCopyWithImpl<$Res, $Val extends UserModel>
? _value.bowling_style
: bowling_style // ignore: cast_nullable_to_non_nullable
as BowlingStyle?,
isActive: null == isActive
? _value.isActive
: isActive // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}
}
Expand All @@ -174,7 +181,8 @@ abstract class _$$UserModelImplCopyWith<$Res>
DateTime? updated_at,
PlayerRole? player_role,
BattingStyle? batting_style,
BowlingStyle? bowling_style});
BowlingStyle? bowling_style,
bool isActive});
}

/// @nodoc
Expand Down Expand Up @@ -202,6 +210,7 @@ class __$$UserModelImplCopyWithImpl<$Res>
Object? player_role = freezed,
Object? batting_style = freezed,
Object? bowling_style = freezed,
Object? isActive = null,
}) {
return _then(_$UserModelImpl(
id: null == id
Expand Down Expand Up @@ -260,6 +269,10 @@ class __$$UserModelImplCopyWithImpl<$Res>
? _value.bowling_style
: bowling_style // ignore: cast_nullable_to_non_nullable
as BowlingStyle?,
isActive: null == isActive
? _value.isActive
: isActive // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
Expand All @@ -281,7 +294,8 @@ class _$UserModelImpl extends _UserModel {
this.updated_at,
this.player_role,
this.batting_style,
this.bowling_style})
this.bowling_style,
this.isActive = true})
: super._();

factory _$UserModelImpl.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -315,10 +329,13 @@ class _$UserModelImpl extends _UserModel {
final BattingStyle? batting_style;
@override
final BowlingStyle? bowling_style;
@override
@JsonKey()
final bool isActive;

@override
String toString() {
return 'UserModel(id: $id, name: $name, name_lowercase: $name_lowercase, location: $location, phone: $phone, dob: $dob, email: $email, profile_img_url: $profile_img_url, gender: $gender, created_at: $created_at, updated_at: $updated_at, player_role: $player_role, batting_style: $batting_style, bowling_style: $bowling_style)';
return 'UserModel(id: $id, name: $name, name_lowercase: $name_lowercase, location: $location, phone: $phone, dob: $dob, email: $email, profile_img_url: $profile_img_url, gender: $gender, created_at: $created_at, updated_at: $updated_at, player_role: $player_role, batting_style: $batting_style, bowling_style: $bowling_style, isActive: $isActive)';
}

@override
Expand Down Expand Up @@ -347,7 +364,9 @@ class _$UserModelImpl extends _UserModel {
(identical(other.batting_style, batting_style) ||
other.batting_style == batting_style) &&
(identical(other.bowling_style, bowling_style) ||
other.bowling_style == bowling_style));
other.bowling_style == bowling_style) &&
(identical(other.isActive, isActive) ||
other.isActive == isActive));
}

@JsonKey(ignore: true)
Expand All @@ -367,7 +386,8 @@ class _$UserModelImpl extends _UserModel {
updated_at,
player_role,
batting_style,
bowling_style);
bowling_style,
isActive);

@JsonKey(ignore: true)
@override
Expand Down Expand Up @@ -398,7 +418,8 @@ abstract class _UserModel extends UserModel {
final DateTime? updated_at,
final PlayerRole? player_role,
final BattingStyle? batting_style,
final BowlingStyle? bowling_style}) = _$UserModelImpl;
final BowlingStyle? bowling_style,
final bool isActive}) = _$UserModelImpl;
const _UserModel._() : super._();

factory _UserModel.fromJson(Map<String, dynamic> json) =
Expand Down Expand Up @@ -433,6 +454,8 @@ abstract class _UserModel extends UserModel {
@override
BowlingStyle? get bowling_style;
@override
bool get isActive;
@override
@JsonKey(ignore: true)
_$$UserModelImplCopyWith<_$UserModelImpl> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
2 changes: 2 additions & 0 deletions data/lib/api/user/user_models.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions data/lib/service/team/team_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:data/errors/app_error.dart';
import 'package:data/extensions/string_extensions.dart';
import 'package:data/service/user/user_service.dart';
import 'package:data/utils/constant/firestore_constant.dart';
import 'package:data/utils/dummy_deactivated_account.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import '../../storage/app_preferences.dart';
Expand Down Expand Up @@ -42,8 +43,7 @@ class TeamService {
final teamRequestModel = teamDoc.data();

if (teamRequestModel == null) {
return TeamModel(
id: teamId, name: "Deleted Team", name_lowercase: "deletedteam");
return deActiveDummyTeamModel(teamId);
}

final member = (teamRequestModel.players?.isNotEmpty ?? false)
Expand All @@ -70,8 +70,7 @@ class TeamService {
return _teamsCollection.doc(teamId).snapshots().asyncMap((teamDoc) async {
final teamRequestModel = teamDoc.data();
if (teamRequestModel == null) {
return TeamModel(
id: teamId, name: "Deleted Team", name_lowercase: "deletedteam");
return deActiveDummyTeamModel(teamId);
}
final member = (teamRequestModel.players?.isNotEmpty ?? false)
? await getMemberListFromUserIds(teamRequestModel.players ?? [])
Expand Down
15 changes: 5 additions & 10 deletions data/lib/service/user/user_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:data/errors/app_error.dart';
import 'package:data/extensions/list_extensions.dart';
import 'package:data/utils/constant/firestore_constant.dart';
import 'package:data/utils/dummy_deactivated_account.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../api/user/user_models.dart';
Expand Down Expand Up @@ -66,11 +67,7 @@ class UserService {
final snapshot = await _userCollection.doc(id).get();
var userModel = snapshot.data();
if (userModel == null) {
return UserModel(
id: id,
name: "Deactivated User",
created_at: DateTime(1950),
location: "--");
return deActiveDummyUserAccount(id);
}
return userModel;
} catch (error, stack) {
Expand All @@ -92,11 +89,9 @@ class UserService {

final deactivatedUserIds =
tenIds.where((id) => !users.map((user) => user.id).contains(id));
users.addAll(deactivatedUserIds.map((id) => UserModel(
id: id,
name: "Deactivated User",
created_at: DateTime(1950),
location: "--")));
users.addAll(deactivatedUserIds.map(
(id) => deActiveDummyUserAccount(id),
));
}

return users;
Expand Down
20 changes: 20 additions & 0 deletions data/lib/utils/dummy_deactivated_account.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:data/api/team/team_model.dart';
import 'package:data/api/user/user_models.dart';

UserModel deActiveDummyUserAccount(String id) {
return UserModel(
id: id,
name: 'Deactivated User',
created_at: DateTime(1950),
location: '--',
isActive: false);
}

TeamModel deActiveDummyTeamModel(String id) {
return TeamModel(
id: id,
name: 'Deactivated Team',
name_lowercase: 'deactivatedteam',
created_at: DateTime(1950),
city: '--');
}
2 changes: 1 addition & 1 deletion khelo/lib/components/user_detail_cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class UserDetailCell extends StatelessWidget {
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
onTap: user.isActive ? onTap : null,
child: Row(
children: [
ImageAvatar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ class TeamSelectionView extends StatelessWidget {
onTap: () async {
final squad = await AppRoute.selectSquad(
team: team,
squad: type == TeamType.a ? state.squadA : state.squadB,
squad: type == TeamType.a
? state.squadA
?.where(
(element) => element.player.isActive,
)
.toList()
: state.squadB
?.where((element) => element.player.isActive)
.toList(),
captainId: type == TeamType.a
? state.teamACaptainId
: state.teamBCaptainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ class _SelectSquadScreenState extends ConsumerState<SelectSquadScreen> {
List<UserModel> getFilteredList(SelectSquadViewState state) {
return state.team?.players
?.where((element) =>
!state.squad.map((e) => e.player.id).contains(element.id))
!state.squad.map((e) => e.player.id).contains(element.id) &&
element.isActive)
.toList() ??
[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,28 @@ class MatchDetailSquadView extends ConsumerWidget {
Widget _listView(BuildContext context, MatchDetailTabState state) {
final firstTeam = state.match!.teams.firstOrNull;
final secondTeam = state.match!.teams.elementAtOrNull(1);
final firstTeamSquad = firstTeam?.squad.map((e) => e.player).toList() ?? [];
final secondTeamSquad =
secondTeam?.squad.map((e) => e.player).toList() ?? [];
final firstTeamSquad = firstTeam?.squad
.where((element) => element.player.isActive)
.map((e) => e.player)
.toList() ??
[];
final secondTeamSquad = secondTeam?.squad
.where((element) => element.player.isActive)
.map((e) => e.player)
.toList() ??
[];

final firstTeamBench = firstTeam?.team.players
?.where((element) =>
!firstTeamSquad.map((e) => e.id).contains(element.id))
!firstTeamSquad.map((e) => e.id).contains(element.id) &&
element.isActive)
.toList() ??
[];

final secondTeamBench = secondTeam?.team.players
?.where((element) =>
!secondTeamSquad.map((e) => e.id).contains(element.id))
!secondTeamSquad.map((e) => e.id).contains(element.id) &&
element.isActive)
.toList() ??
[];

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 @@ -1085,9 +1085,10 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {
: state.otherInning?.team_id) ??
"INVALID ID";
final teamPlayers = state.match?.teams
.where((element) => element.team.id == teamId)
.firstOrNull
?.squad;
.firstWhere((element) => element.team.id == teamId)
.squad
.where((element) => element.player.isActive)
.toList();

if (type == PlayerSelectionType.bowler) {
return teamPlayers ?? [];
Expand All @@ -1113,7 +1114,9 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {
final teamId = state.otherInning?.team_id ?? "INVALID ID";
final teamPlayers = state.match?.teams
.firstWhere((element) => element.team.id == teamId)
.squad;
.squad
.where((element) => element.player.isActive)
.toList();

return teamPlayers ?? [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,17 @@ class TeamMemberSheet extends StatelessWidget {
children: (team.players ?? [])
.map((member) => UserDetailCell(
user: member,
onTap: () => UserDetailSheet.show(context, member),
trailing: isForVerification
onTap: () => UserDetailSheet.show(
context,
member,
actionButtonTitle:
isForVerification && member.isActive
? context.l10n.common_select_title
: null,
onButtonTap: () =>
_onSelectButtonTap(context, member),
),
trailing: isForVerification && member.isActive
? _selectButton(context, member)
: null,
))
Expand All @@ -80,15 +89,17 @@ class TeamMemberSheet extends StatelessWidget {
Widget _selectButton(BuildContext context, UserModel user) {
return SecondaryButton(
context.l10n.common_select_title,
onPressed: () async {
if (user.phone != null) {
final res = await VerifyTeamMemberSheet.show(context,
phoneNumber: user.phone!);
if (res != null && res && context.mounted) {
context.pop(res);
}
}
},
onPressed: () => _onSelectButtonTap(context, user),
);
}

Future<void> _onSelectButtonTap(BuildContext context, UserModel user) async {
if (user.phone != null) {
final res =
await VerifyTeamMemberSheet.show(context, phoneNumber: user.phone!);
if (res != null && res && context.mounted) {
context.pop(res);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ class SearchTeamViewNotifier extends StateNotifier<SearchTeamState> {

void onTeamCellTap(TeamModel team) {
state = state.copyWith(showSelectionError: false);
final playersCount = (team.players ?? []).length;
final playersCount =
(team.players?.where((player) => player.isActive).toList() ?? [])
.length;
if (playersCount >= 2) {
final isAlreadySelected = state.selectedTeam?.id == team.id;
state = state.copyWith(selectedTeam: isAlreadySelected ? null : team);
Expand Down

0 comments on commit f60ca81

Please sign in to comment.