Skip to content

Commit

Permalink
Merge pull request #91 from canopas/Mayank/refactor-home-screen
Browse files Browse the repository at this point in the history
Refactor home screen
  • Loading branch information
cp-mayank authored Sep 6, 2024
2 parents 5ccd710 + 5a43b00 commit b2602ce
Show file tree
Hide file tree
Showing 17 changed files with 1,095 additions and 86 deletions.
33 changes: 28 additions & 5 deletions data/lib/service/match/match_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,8 @@ class MatchService {
}).handleError((error, stack) => throw AppError.fromError(error, stack));
}

Stream<List<MatchModel>> streamRunningMatches() {
return _matchCollection
.where(FireStoreConst.matchStatus, isEqualTo: MatchStatus.running.value)
.snapshots()
.asyncMap((snapshot) async {
Stream<List<MatchModel>> streamMatches() {
return _matchCollection.snapshots().asyncMap((snapshot) async {
return await Future.wait(
snapshot.docs.map((mainDoc) async {
final match = mainDoc.data();
Expand All @@ -189,6 +186,32 @@ class MatchService {
}).handleError((error, stack) => throw AppError.fromError(error, stack));
}

Future<List<MatchModel>> getMatchesByStatus({
required List<MatchStatus> status,
String? lastMatchId,
int limit = 10,
}) async {
final filter = status.map((e) => e.value).toList();

var query = _matchCollection
.where(FireStoreConst.matchStatus, whereIn: filter)
.orderBy(FieldPath.documentId);

if (lastMatchId != null) {
query = query.startAfter([lastMatchId]);
}

final snapshot = await query.limit(limit).get();

return Future.wait(
snapshot.docs.map((doc) async {
final match = doc.data();
final teams = await getTeamsList(match.teams);
return match.copyWith(teams: teams);
}).toList(),
);
}

Stream<MatchModel> streamMatchById(String id) {
return _matchCollection.doc(id).snapshots().asyncMap((snapshot) async {
final match = snapshot.data();
Expand Down
22 changes: 19 additions & 3 deletions khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,25 @@
"@_HOME": {
},
"home_screen_title": "Home",
"home_screen_no_matches_title": "No matches are running currently",
"home_screen_no_matches_description_text": "Running matches will be shown here, Stay tuned for some intense matches.",
"home_screen_live_title": "Live",
"home_screen_upcoming_title": "Upcoming",
"home_screen_finished_title": "Finished",
"home_screen_set_up_match_title": "Set up a match in minutes.",
"home_screen_create_match_btn": "Create match",
"home_screen_set_up_team_title": "Set up a team in minutes.",
"home_screen_create_team_btn": "Create team",
"home_screen_view_all_btn": "View all",
"home_screen_no_matches_title": "No Matches in this area!",
"home_screen_no_matches_description_text": "Enjoy the freedom of creating your own cricket matches or teams.",

"@_HOME_SEARCH": {
},
"home_search_hint_title": "Search matches by team name...",
"home_search_empty_title": "Start your search here!",
"home_search_empty_message": "Type your search above to find what you need fast.",
"home_search_results_title": "Results",
"home_match_list_empty_search_title": "No match results",
"home_match_list_empty_search_message": "No results found. Make sure the team name is correct or try again later.",

"@_MY_CRICKET": {
},
Expand Down Expand Up @@ -618,7 +635,6 @@
"score_board_batsman_title": "batsMan",
"score_board_bowler_title": "bowler",
"score_board_change_striker_title": "Change Striker",
"score_board_add_substitute_title": "Add substitute",
"score_board_can_undo_till_running_over_title": "Undo is only allowed till running over",
"score_board_undo_last_ball_title": "Undo Last Ball",
"score_board_undo_last_ball_description_text": "are you sure you want to undo last ball?",
Expand Down
2 changes: 1 addition & 1 deletion khelo/lib/components/match_detail_cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class MatchDetailCell extends StatelessWidget {
child: Row(
children: [
ImageAvatar(
initial: matchTeam.team.name[0].toUpperCase(),
initial: matchTeam.team.name.characters.first.toUpperCase(),
imageUrl: matchTeam.team.profile_img_url,
size: 32,
),
Expand Down
20 changes: 20 additions & 0 deletions khelo/lib/ui/app_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:data/api/team/team_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:khelo/ui/flow/home/home_view_model.dart';
import 'package:khelo/ui/flow/home/search/search_screen.dart';
import 'package:khelo/ui/flow/intro/intro_screen.dart';
import 'package:khelo/ui/flow/matches/add_match/add_match_screen.dart';
import 'package:khelo/ui/flow/matches/add_match/match_officials/add_match_officials_screen.dart';
Expand All @@ -20,6 +22,7 @@ import 'package:khelo/ui/flow/team/add_team_member/add_team_member_screen.dart';
import 'package:khelo/ui/flow/team/detail/make_admin/make_team_admin_screen.dart';
import 'package:khelo/ui/flow/team/detail/team_detail_screen.dart';
import 'package:khelo/ui/flow/team/search_team/search_team_screen.dart';
import 'flow/home/view_all/home_view_all_screen.dart';
import 'flow/main/main_screen.dart';
import 'flow/settings/support/contact_support_screen.dart';
import 'flow/sign_in/sign_in_with_phone/sign_in_with_phone_screen.dart';
Expand All @@ -42,6 +45,8 @@ class AppRoute {
static const pathTeamDetail = '/team-detail';
static const pathUserDetail = '/user-detail';
static const pathMatchDetailTab = '/match-detail-tab';
static const pathSearchHome = "/search-home";
static const pathViewAll = "/view-all";

final String path;
final String? name;
Expand Down Expand Up @@ -130,6 +135,13 @@ class AppRoute {
),
);

static AppRoute searchHome({required List<MatchModel> matches}) =>
AppRoute(pathSearchHome,
builder: (_) => SearchHomeScreen(matches: matches));

static AppRoute viewAll(MatchStatusLabel status) =>
AppRoute(pathViewAll, builder: (_) => HomeViewAllScreen(status: status));

static AppRoute addTossDetail({required String matchId}) => AppRoute(
pathAddTossDetail,
builder: (_) => AddTossDetailScreen(
Expand Down Expand Up @@ -246,6 +258,14 @@ class AppRoute {
return state.extra == null ? const MainScreen() : state.widget(context);
},
),
GoRoute(
path: pathSearchHome,
builder: (context, state) => state.widget(context),
),
GoRoute(
path: pathViewAll,
builder: (context, state) => state.widget(context),
),
GoRoute(
path: intro.path,
builder: (context, state) {
Expand Down
Loading

0 comments on commit b2602ce

Please sign in to comment.