From 811536066569d7d000833a441a576fa21c84fe29 Mon Sep 17 00:00:00 2001 From: Jaime <52668514+jsgalarraga@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:37:35 +0100 Subject: [PATCH 1/3] chore: add local launch config (#105) * feat: add api client to app * feat: create score card object * feat: add create score call to leaderboard resource * feat: add create score endpoint * feat: create score card entry in database * fix: endpoint * fix: remove fake app check token * chore: add local launch config --- .vscode/launch.json | 20 +++++++++++++---- lib/main_local.dart | 46 ++++++++++++++++++++++++++++++++++++++ scripts/start_local_api.sh | 4 ++-- 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 lib/main_local.dart diff --git a/.vscode/launch.json b/.vscode/launch.json index 8c4308e34..df053a913 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,23 +5,35 @@ "version": "0.2.0", "configurations": [ { - "name": "Launch development", + "name": "Web local", + "request": "launch", + "type": "dart", + "program": "lib/main_local.dart", + "args": [ + "--target", + "lib/main_local.dart", + "--web-port", + "24514" + ] + }, + { + "name": "Web development", "request": "launch", "type": "dart", "program": "lib/main_development.dart", "args": [ - "--flavor", - "development", "--target", "lib/main_development.dart" ] }, { - "name": "web development", + "name": "Launch development", "request": "launch", "type": "dart", "program": "lib/main_development.dart", "args": [ + "--flavor", + "development", "--target", "lib/main_development.dart" ] diff --git a/lib/main_local.dart b/lib/main_local.dart new file mode 100644 index 000000000..1d1874703 --- /dev/null +++ b/lib/main_local.dart @@ -0,0 +1,46 @@ +import 'dart:async'; + +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:firebase_core/firebase_core.dart'; +import 'package:flutter/widgets.dart'; +import 'package:io_crossword/app/app.dart'; +import 'package:io_crossword/bootstrap.dart'; +import 'package:io_crossword/firebase_options_development.dart'; + +void main() async { + WidgetsFlutterBinding.ensureInitialized(); + + await Firebase.initializeApp( + options: DefaultFirebaseOptions.currentPlatform, + ); + + unawaited( + bootstrap( + (firestore, firebaseAuth) async { + final authenticationRepository = AuthenticationRepository( + firebaseAuth: firebaseAuth, + ); + + await authenticationRepository.signInAnonymously(); + await authenticationRepository.idToken.first; + + final apiClient = ApiClient( + baseUrl: 'http://localhost:8080', + idTokenStream: authenticationRepository.idToken, + refreshIdToken: authenticationRepository.refreshIdToken, + // TODO(any): implement app check + appCheckTokenStream: const Stream.empty(), + ); + + return App( + apiClient: apiClient, + crosswordRepository: CrosswordRepository(db: firestore), + boardInfoRepository: BoardInfoRepository(firestore: firestore), + ); + }, + ), + ); +} diff --git a/scripts/start_local_api.sh b/scripts/start_local_api.sh index 0331c3b54..f97273848 100755 --- a/scripts/start_local_api.sh +++ b/scripts/start_local_api.sh @@ -1,8 +1,8 @@ #!/bin/bash export FB_APP_ID=io-crossword-dev -export GAME_URL=http://localhost:8080/ -export USE_EMULATOR=true +export GAME_URL=http://localhost:24514 +export USE_EMULATOR=false export ENCRYPTION_KEY=X9YTchZdcnyZTNBSBgzj29p7RMBAIubD export ENCRYPTION_IV=FxC21ctRg9SgiXuZ export INITIALS_BLACKLIST_ID=T1ilfCwjDpLS7iaFzenA From e384199a144b8ac774f3d9a6c17a62cd273d87a7 Mon Sep 17 00:00:00 2001 From: Hugo Walbecq Date: Thu, 21 Mar 2024 11:57:46 +0100 Subject: [PATCH 2/3] fix: fix render mode used if section loads while already existing in bloc (#106) --- lib/crossword/game/components/section_component.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/crossword/game/components/section_component.dart b/lib/crossword/game/components/section_component.dart index 233e0358f..5a6c9e599 100644 --- a/lib/crossword/game/components/section_component.dart +++ b/lib/crossword/game/components/section_component.dart @@ -123,7 +123,7 @@ class SectionComponent extends Component with HasGameRef { final boardSection = gameRef.state.sections[index]; if (boardSection != null) { _boardSection = boardSection; - _loadBoardSection(); + _loadWithCurrentRenderMode(); } else { gameRef.bloc.add( BoardSectionRequested(index), From c1a0e5647bdc3fef84f7281854239146ac2e7ed8 Mon Sep 17 00:00:00 2001 From: Hugo Walbecq Date: Thu, 21 Mar 2024 12:01:20 +0100 Subject: [PATCH 3/3] feat: get render mode info from firestore (#100) * feat: get render mode info from firestore * feat: update method to use several limits --- .../lib/src/board_info_repository.dart | 17 +++++++++++++-- .../test/src/board_info_repository_test.dart | 21 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/board_info_repository/lib/src/board_info_repository.dart b/packages/board_info_repository/lib/src/board_info_repository.dart index d1bfc3a90..aa57b3ea9 100644 --- a/packages/board_info_repository/lib/src/board_info_repository.dart +++ b/packages/board_info_repository/lib/src/board_info_repository.dart @@ -34,7 +34,7 @@ class BoardInfoRepository { /// The [CollectionReference] for the config. late final CollectionReference> boardInfoCollection; - /// Return the total words count available in the crossword. + /// Returns the total words count available in the crossword. Future getTotalWordsCount() async { try { final results = await boardInfoCollection @@ -48,7 +48,7 @@ class BoardInfoRepository { } } - /// Return the solved words count in the crossword. + /// Returns the solved words count in the crossword. Future getSolvedWordsCount() async { try { final results = await boardInfoCollection @@ -61,4 +61,17 @@ class BoardInfoRepository { throw BoardInfoException(error, stackStrace); } } + + /// Returns the limit at which the render mode should switch + Future> getRenderModeZoomLimits() async { + try { + final results = await boardInfoCollection + .where('type', isEqualTo: 'render_mode_limit') + .get(); + + return results.docs.map((e) => e.data()['value'] as double).toList(); + } catch (error, stackStrace) { + throw BoardInfoException(error, stackStrace); + } + } } diff --git a/packages/board_info_repository/test/src/board_info_repository_test.dart b/packages/board_info_repository/test/src/board_info_repository_test.dart index ae1439e63..6ff33377a 100644 --- a/packages/board_info_repository/test/src/board_info_repository_test.dart +++ b/packages/board_info_repository/test/src/board_info_repository_test.dart @@ -39,6 +39,9 @@ void main() { when( () => collection.where('type', isEqualTo: 'solved_words_count'), ).thenReturn(collection); + when( + () => collection.where('type', isEqualTo: 'render_mode_limit'), + ).thenReturn(collection); when(collection.get).thenAnswer((_) async => query); when(() => query.docs).thenReturn([doc]); @@ -87,6 +90,24 @@ void main() { ); }); }); + + group('getRenderModeZoomLimit', () { + test('returns render mode limit from firebase', () async { + mockQueryResult(0.6); + final result = await boardInfoRepository.getRenderModeZoomLimits(); + expect(result, equals([0.6])); + }); + + test('throws BoardInfoException when fetching the info fails', () { + when( + () => collection.where('type', isEqualTo: 'render_mode_limit'), + ).thenThrow(Exception('oops')); + expect( + () => boardInfoRepository.getRenderModeZoomLimits(), + throwsA(isA()), + ); + }); + }); }); group('BoardInfoException', () {