Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/leaderboard/stre…
Browse files Browse the repository at this point in the history
…ak-team
  • Loading branch information
AyadLaouissi committed Apr 8, 2024
2 parents 51cd943 + d356e30 commit a9a9db8
Show file tree
Hide file tree
Showing 27 changed files with 306 additions and 370 deletions.
4 changes: 4 additions & 0 deletions lib/app/view/app.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:api_client/api_client.dart';
import 'package:authentication_repository/authentication_repository.dart';
import 'package:board_info_repository/board_info_repository.dart';
import 'package:crossword_repository/crossword_repository.dart';
import 'package:flutter/material.dart';
Expand All @@ -15,10 +16,12 @@ class App extends StatelessWidget {
required this.apiClient,
required this.crosswordRepository,
required this.boardInfoRepository,
required this.user,
super.key,
});

final ApiClient apiClient;
final User user;
final CrosswordRepository crosswordRepository;
final BoardInfoRepository boardInfoRepository;

Expand All @@ -29,6 +32,7 @@ class App extends StatelessWidget {
return MultiProvider(
providers: [
Provider.value(value: apiClient.leaderboardResource),
Provider.value(value: user),
Provider.value(value: crosswordResource),
Provider.value(value: crosswordRepository),
Provider.value(value: boardInfoRepository),
Expand Down
24 changes: 1 addition & 23 deletions lib/game_intro/bloc/game_intro_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:api_client/api_client.dart';
import 'package:bloc/bloc.dart';
import 'package:board_info_repository/board_info_repository.dart';
import 'package:equatable/equatable.dart';
import 'package:game_domain/game_domain.dart';

Expand All @@ -9,21 +8,17 @@ part 'game_intro_state.dart';

class GameIntroBloc extends Bloc<GameIntroEvent, GameIntroState> {
GameIntroBloc({
required BoardInfoRepository boardInfoRepository,
required LeaderboardResource leaderboardResource,
}) : _boardInfoRepository = boardInfoRepository,
_leaderboardResource = leaderboardResource,
}) : _leaderboardResource = leaderboardResource,
super(const GameIntroState()) {
on<BlacklistRequested>(_onBlacklistRequested);
on<BoardProgressRequested>(_onBoardProgressRequested);
on<WelcomeCompleted>(_onWelcomeCompleted);
on<MascotUpdated>(_onMascotUpdated);
on<MascotSubmitted>(_onMascotSubmitted);
on<InitialsUpdated>(_onInitialsUpdated);
on<InitialsSubmitted>(_onInitialsSubmitted);
}

final BoardInfoRepository _boardInfoRepository;
final LeaderboardResource _leaderboardResource;
final initialsRegex = RegExp('[A-Z]{3}');

Expand All @@ -39,23 +34,6 @@ class GameIntroBloc extends Bloc<GameIntroEvent, GameIntroState> {
}
}

Future<void> _onBoardProgressRequested(
BoardProgressRequested event,
Emitter<GameIntroState> emit,
) async {
final [solved, total] = await Future.wait([
_boardInfoRepository.getSolvedWordsCount(),
_boardInfoRepository.getTotalWordsCount(),
]);

emit(
state.copyWith(
solvedWords: solved,
totalWords: total,
),
);
}

void _onWelcomeCompleted(
WelcomeCompleted event,
Emitter<GameIntroState> emit,
Expand Down
7 changes: 0 additions & 7 deletions lib/game_intro/bloc/game_intro_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ sealed class GameIntroEvent extends Equatable {
const GameIntroEvent();
}

class BoardProgressRequested extends GameIntroEvent {
const BoardProgressRequested();

@override
List<Object> get props => [];
}

class BlacklistRequested extends GameIntroEvent {
const BlacklistRequested();

Expand Down
8 changes: 0 additions & 8 deletions lib/game_intro/bloc/game_intro_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class GameIntroState extends Equatable {
const GameIntroState({
this.status = GameIntroStatus.welcome,
this.isIntroCompleted = false,
this.solvedWords = 0,
this.totalWords = 0,
this.selectedMascot = Mascots.dash,
this.initials = const ['', '', ''],
this.initialsBlacklist = const [],
Expand All @@ -29,8 +27,6 @@ class GameIntroState extends Equatable {

final GameIntroStatus status;
final bool isIntroCompleted;
final int solvedWords;
final int totalWords;
final Mascots selectedMascot;
final List<String> initials;
final List<String> initialsBlacklist;
Expand All @@ -49,8 +45,6 @@ class GameIntroState extends Equatable {
return GameIntroState(
status: status ?? this.status,
isIntroCompleted: isIntroCompleted ?? this.isIntroCompleted,
solvedWords: solvedWords ?? this.solvedWords,
totalWords: totalWords ?? this.totalWords,
selectedMascot: selectedMascot ?? this.selectedMascot,
initials: initials ?? this.initials,
initialsBlacklist: initialsBlacklist ?? this.initialsBlacklist,
Expand All @@ -62,8 +56,6 @@ class GameIntroState extends Equatable {
List<Object?> get props => [
status,
isIntroCompleted,
solvedWords,
totalWords,
selectedMascot,
initials,
initialsBlacklist,
Expand Down
9 changes: 3 additions & 6 deletions lib/game_intro/view/game_intro_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:api_client/api_client.dart';
import 'package:board_info_repository/board_info_repository.dart';
import 'package:flow_builder/flow_builder.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:io_crossword/about/about.dart';
import 'package:io_crossword/crossword/crossword.dart';
import 'package:io_crossword/game_intro/game_intro.dart';
import 'package:io_crossword/welcome/view/welcome_page.dart';

class GameIntroPage extends StatelessWidget {
const GameIntroPage({super.key});
Expand All @@ -14,11 +14,8 @@ class GameIntroPage extends StatelessWidget {
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => GameIntroBloc(
boardInfoRepository: context.read<BoardInfoRepository>(),
leaderboardResource: context.read<LeaderboardResource>(),
)
..add(const BoardProgressRequested())
..add(const BlacklistRequested()),
)..add(const BlacklistRequested()),
child: const GameIntroView(),
);
}
Expand Down Expand Up @@ -60,7 +57,7 @@ List<Page<void>> onGenerateGameIntroPages(
List<Page<void>> pages,
) {
return switch (state.status) {
GameIntroStatus.welcome => [WelcomeView.page()],
GameIntroStatus.welcome => [WelcomePage.page()],
GameIntroStatus.mascotSelection => [MascotSelectionView.page()],
GameIntroStatus.initialsInput => [InitialsInputView.page()],
};
Expand Down
1 change: 0 additions & 1 deletion lib/game_intro/view/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export 'game_intro_page.dart';
export 'initials_form_view.dart';
export 'initials_input_view.dart';
export 'mascot_selection_view.dart';
export 'welcome_view.dart';
83 changes: 0 additions & 83 deletions lib/game_intro/view/welcome_view.dart

This file was deleted.

1 change: 1 addition & 0 deletions lib/main_debug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void main() async {
apiClient: apiClient,
crosswordRepository: CrosswordRepository(db: firestore),
boardInfoRepository: BoardInfoRepository(firestore: firestore),
user: await authenticationRepository.user.first,
);
},
),
Expand Down
1 change: 1 addition & 0 deletions lib/main_development.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void main() async {
apiClient: apiClient,
crosswordRepository: CrosswordRepository(db: firestore),
boardInfoRepository: BoardInfoRepository(firestore: firestore),
user: await authenticationRepository.user.first,
);
},
),
Expand Down
1 change: 1 addition & 0 deletions lib/main_local.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void main() async {
apiClient: apiClient,
crosswordRepository: CrosswordRepository(db: firestore),
boardInfoRepository: BoardInfoRepository(firestore: firestore),
user: await authenticationRepository.user.first,
);
},
),
Expand Down
1 change: 1 addition & 0 deletions lib/main_production.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void main() async {
apiClient: apiClient,
crosswordRepository: CrosswordRepository(db: firestore),
boardInfoRepository: BoardInfoRepository(firestore: firestore),
user: await authenticationRepository.user.first,
);
},
),
Expand Down
1 change: 1 addition & 0 deletions lib/main_staging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void main() async {
apiClient: apiClient,
crosswordRepository: CrosswordRepository(db: firestore),
boardInfoRepository: BoardInfoRepository(firestore: firestore),
user: await authenticationRepository.user.first,
);
},
),
Expand Down
39 changes: 39 additions & 0 deletions lib/welcome/bloc/welcome_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:bloc/bloc.dart';
import 'package:board_info_repository/board_info_repository.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';

part 'welcome_event.dart';
part 'welcome_state.dart';

class WelcomeBloc extends Bloc<WelcomeEvent, WelcomeState> {
WelcomeBloc({
required BoardInfoRepository boardInfoRepository,
}) : _boardInfoRepository = boardInfoRepository,
super(const WelcomeState.initial()) {
on<WelcomeDataRequested>(_onDataRequested);
}

final BoardInfoRepository _boardInfoRepository;

Future<void> _onDataRequested(
WelcomeDataRequested event,
Emitter<WelcomeState> emit,
) async {
try {
final [solved, total] = await Future.wait([
_boardInfoRepository.getSolvedWordsCount(),
_boardInfoRepository.getTotalWordsCount(),
]);

emit(
state.copyWith(
solvedWords: solved,
totalWords: total,
),
);
} catch (error, stackTrace) {
addError(error, stackTrace);
}
}
}
13 changes: 13 additions & 0 deletions lib/welcome/bloc/welcome_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
part of 'welcome_bloc.dart';

sealed class WelcomeEvent extends Equatable {
const WelcomeEvent();

@override
List<Object> get props => [];
}

/// Requests the data needed to welcome the user.
class WelcomeDataRequested extends WelcomeEvent {
const WelcomeDataRequested();
}
45 changes: 45 additions & 0 deletions lib/welcome/bloc/welcome_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
part of 'welcome_bloc.dart';

class WelcomeState extends Equatable {
const WelcomeState({
required this.solvedWords,
required this.totalWords,
});

/// Creates a [WelcomeState] with the initial status.
const WelcomeState.initial({
this.solvedWords = fallbackSolvedWords,
this.totalWords = fallbackTotalWords,
});

@visibleForTesting
static const fallbackTotalWords = 66666;

@visibleForTesting
static const fallbackSolvedWords = 0;

/// The current solved words in the challenge.
///
/// If the loading of the solved words is yet to be done or fails this will
/// default to [fallbackSolvedWords].
final int solvedWords;

/// The total words to complete the challenge.
///
/// If the loading of the total words is yet to be done or fails this will
/// default to [fallbackTotalWords].
final int totalWords;

WelcomeState copyWith({
int? solvedWords,
int? totalWords,
}) {
return WelcomeState(
solvedWords: solvedWords ?? this.solvedWords,
totalWords: totalWords ?? this.totalWords,
);
}

@override
List<Object> get props => [solvedWords, totalWords];
}
Loading

0 comments on commit a9a9db8

Please sign in to comment.