Skip to content

Commit

Permalink
Merge pull request #452 from tusharlock10/449-push-new-player-pages-i…
Browse files Browse the repository at this point in the history
…n-a-stack-instead-of-replacing-the-old-page

449 push new player pages in a stack instead of replacing the old page
  • Loading branch information
tusharlock10 authored Mar 10, 2024
2 parents a29d248 + 8b23606 commit 7cf612a
Show file tree
Hide file tree
Showing 74 changed files with 834 additions and 2,189 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- develop

env:
flutter_version: "3.19.1"
flutter_version: "3.19.3"

jobs:
build-test-apk:
Expand All @@ -30,7 +30,6 @@ jobs:

- name: Download credential files
run: |
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/paladins-edge-stage.env ./paladins-edge.env
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/google-services.json ./android/app/
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/upload-keystore.jks ./android/app/
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/key.properties ./android/
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/prod-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

env:
flutter_version: "3.19.1"
flutter_version: "3.19.3"

jobs:
build-apk:
Expand All @@ -28,7 +28,6 @@ jobs:

- name: Download credential files
run: |
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/paladins-edge-prod.env ./paladins-edge.env
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/google-services.json ./android/app/
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/upload-keystore.jks ./android/app/
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/key.properties ./android/
Expand Down Expand Up @@ -95,7 +94,6 @@ jobs:

- name: Download credential files
run: |
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/paladins-edge-prod.env ./paladins-edge.env
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/google-services.json ./android/app/
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/upload-keystore.jks ./android/app/
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/key.properties ./android/
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/staging-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- develop

env:
flutter_version: "3.19.1"
flutter_version: "3.19.3"

jobs:
build-bundle:
Expand All @@ -28,7 +28,6 @@ jobs:

- name: Download credential files
run: |
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/paladins-edge-stage.env ./paladins-edge.env
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/google-services.json ./android/app/
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/upload-keystore.jks ./android/app/
aws s3 cp s3://${{ secrets.PE_PRIVATE_AWS_S3_BUCKET_NAME }}/credentials/client/key.properties ./android/
Expand Down
15 changes: 0 additions & 15 deletions lib/api/players/requests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,6 @@ abstract class PlayersRequests {
}
}

static Future<responses.FavouriteFriendsResponse?> favouriteFriends() async {
try {
final response = await utilities.api.get<Map<String, dynamic>>(
constants.Urls.favouriteFriends,
);
if (response.data != null) {
return responses.FavouriteFriendsResponse.fromJson(response.data!);
}

return null;
} catch (_) {
return null;
}
}

static Future<responses.UpdateFavouriteFriendResponse?>
updateFavouriteFriend({
required String playerId,
Expand Down
11 changes: 0 additions & 11 deletions lib/api/players/responses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,6 @@ class FriendsResponse {
Map<String, dynamic> toJson() => _$FriendsResponseToJson(this);
}

@JsonSerializable()
class FavouriteFriendsResponse {
final List<Player> favouriteFriends;

FavouriteFriendsResponse({required this.favouriteFriends});

factory FavouriteFriendsResponse.fromJson(Map<String, dynamic> json) =>
_$FavouriteFriendsResponseFromJson(json);
Map<String, dynamic> toJson() => _$FavouriteFriendsResponseToJson(this);
}

@JsonSerializable()
class UpdateFavouriteFriendResponse {
final List<String> favouriteFriends;
Expand Down
14 changes: 0 additions & 14 deletions lib/api/players/responses.g.dart

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

14 changes: 14 additions & 0 deletions lib/constants/app_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import "package:paladinsedge/constants/constants.dart";

abstract class AppType {
static const development = "development";
static const production = "production";

static const developmentShort = "dev";
static const productionShort = "prod";

static String get shortAppType =>
isDebug ? developmentShort : productionShort;

static String get appType => isDebug ? development : production;
}
7 changes: 6 additions & 1 deletion lib/constants/constants.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
import "package:paladinsedge/constants/platforms.dart";

const isDebug = kDebugMode;
const apiTimeout = isDebug ? 10 * 1000 : 20 * 1000;
const releaseTag = "stable";
final releaseTag = isWindows ? "alpha" : "stable";

abstract class NotificationChannels {
static const friends = "friends";
Expand Down Expand Up @@ -82,3 +83,7 @@ const themeNames = {
ThemeMode.light: "light",
ThemeMode.system: "system",
};

const baseUrl = "https://api.paladinsedge.app";
const githubLink = "https://github.com/tusharlock10/paladins-edge-client";
const sponsorLink = "https://github.com/sponsors/tusharlock10";
47 changes: 0 additions & 47 deletions lib/constants/environment.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/constants/index.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export "./analytics.dart";
export "./app_type.dart";
export "./champions.dart";
export "./constants.dart";
export "./database.dart";
export "./environment.dart";
export "./login_cta.dart";
export "./match.dart";
export "./platforms.dart";
Expand Down
67 changes: 39 additions & 28 deletions lib/providers/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _AuthNotifier extends ChangeNotifier {
bool isGuest = true;
String? token;
models.User? user;
models.Player? player;
models.Player? userPlayer;
List<models.FAQ>? faqs;
List<models.Sponsor>? sponsors;
List<data_classes.CombinedMatch>? savedMatches;
Expand Down Expand Up @@ -77,24 +77,17 @@ class _AuthNotifier extends ChangeNotifier {

/// Loads and the `essentials` from local db and syncs it with server
Future<void> loadEssentials() async {
// gets the essential data for the app

// getting the essential data from local until the api call is completed
// get the essentials from local db
final savedEssentials = utilities.Database.getEssentials();
final future = _getEssentials();

api.EssentialsResponse? response;
while (true) {
response = await api.AuthRequests.essentials();
if (response == null && savedEssentials != null) {
utilities.Global.essentials = savedEssentials;

return;
}
if (response != null) break;
if (savedEssentials != null) {
// if saved essentials are found, don't wait for future
utilities.Global.essentials = savedEssentials;
} else {
// wait for future, if essentials are not found
await future;
}

utilities.Database.saveEssentials(response.essentials);
utilities.Global.essentials = response.essentials;
}

/// Checks whether the paladins API is in working state
Expand All @@ -109,9 +102,9 @@ class _AuthNotifier extends ChangeNotifier {
bool checkLogin() {
token = utilities.Database.getToken();
user = utilities.Database.getUser();
player = utilities.Database.getPlayer();
userPlayer = utilities.Database.getPlayer();

utilities.Global.isPlayerConnected = player != null;
utilities.Global.isPlayerConnected = userPlayer != null;

if (token != null) {
isGuest = false;
Expand Down Expand Up @@ -157,12 +150,12 @@ class _AuthNotifier extends ChangeNotifier {

user = response.user;
token = response.token;
player = response.player;
userPlayer = response.player;

utilities.api.options.headers["authorization"] = "Bearer $token";
utilities.Global.isAuthenticated = true;
isGuest = false;
if (player != null) utilities.Global.isPlayerConnected = true;
if (userPlayer != null) utilities.Global.isPlayerConnected = true;

_recordLoginAnalytics();
// upon successful login, send FCM token and deviceDetail to server
Expand Down Expand Up @@ -212,17 +205,16 @@ class _AuthNotifier extends ChangeNotifier {
clearData();
ref.read(providers.champions).clearData();
ref.read(providers.loadout).clearData();
ref.read(providers.matches).clearData();
ref.read(providers.players).clearData();
ref.read(providers.appState).clearData();
ref.read(providers.search).clearData();

// clear values from the database and utilities
utilities.Database.clear();

utilities.api.options.headers["authorization"] = null;
utilities.Global.isAuthenticated = false;
isGuest = true;
if (player != null) utilities.Global.isPlayerConnected = false;
if (userPlayer != null) utilities.Global.isPlayerConnected = false;

notifyListeners();

Expand All @@ -234,11 +226,11 @@ class _AuthNotifier extends ChangeNotifier {
final response = await api.AuthRequests.connectPlayer(playerId: playerId);
if (response == null) return null;

player = response.player;
user = response.user;
userPlayer = response.player;

utilities.Database.saveUser(response.user);
utilities.Database.savePlayer(player!);
utilities.Database.savePlayer(userPlayer!);

utilities.Global.isPlayerConnected = true;
utilities.Analytics.logEvent(constants.AnalyticsEvent.connectPlayer);
Expand Down Expand Up @@ -311,7 +303,7 @@ class _AuthNotifier extends ChangeNotifier {
(_) => _.match.matchId == matchId,
);
if (combinedMatch == null) {
final matchDetails = ref.read(providers.matches).matchDetails;
final matchDetails = ref.read(providers.matches(matchId)).matchDetails;
if (matchDetails != null && matchDetails.match.matchId == matchId) {
combinedMatch = data_classes.CombinedMatch(
match: matchDetails.match,
Expand Down Expand Up @@ -422,13 +414,32 @@ class _AuthNotifier extends ChangeNotifier {
}

void clearData() {
player = null;
userPlayer = null;
token = null;
isGuest = false;
user = null;
}

Future<void> _getEssentials() async {
while (true) {
final response = await api.AuthRequests.essentials();
if (response != null) {
utilities.Global.essentials = response.essentials;
utilities.Database.saveEssentials(response.essentials);

return;
}

await Future.delayed(const Duration(seconds: 1));
}
}

Future<_GetFirebaseAuthResponse> _getFirebaseAuthCredentials() async {
// NOTE: for development login in windows
if (constants.isWindows && constants.isDebug) {
return _GetFirebaseAuthResponse(idToken: "testUser");
}

final GoogleSignInAccount? googleUser;
try {
googleUser = await GoogleSignIn().signIn();
Expand Down Expand Up @@ -503,7 +514,7 @@ class _AuthNotifier extends ChangeNotifier {
);
}
if (user != null) utilities.Analytics.setUserId(user!.uid);
if (player != null) {
if (userPlayer != null) {
utilities.Analytics.logEvent(constants.AnalyticsEvent.existingUserLogin);
} else {
utilities.Analytics.logEvent(constants.AnalyticsEvent.newUserLogin);
Expand Down
Loading

0 comments on commit 7cf612a

Please sign in to comment.