From 4d1d5b1055aa70fd1577ec540748e70556768765 Mon Sep 17 00:00:00 2001 From: Ck Algos Date: Wed, 14 Jun 2023 20:50:42 +0100 Subject: [PATCH] club data sync --- app/index.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/app/index.js b/app/index.js index 17bd980..66d5325 100644 --- a/app/index.js +++ b/app/index.js @@ -6,6 +6,7 @@ import { getPlayers, getSettings, initDatabase } from "./utils/dbUtil"; import { setMaxUnassignedCount } from "./utils/pileUtil"; import Amplify, { Auth } from "./external/amplify"; import { setUserData } from "./utils/authUtil"; +import { getAllClubPlayers } from "./services/club"; if (!isMarketAlertApp) { Amplify.configure( @@ -50,10 +51,50 @@ const initScript = function () { if (isAllLoaded) { initOverrides(); + isMarketAlertApp && fetchClubPlayers(); isMarketAlertApp && initListeners(); } else { setTimeout(initScript, 1000); } }; +const fetchClubPlayers = () => { + let isHomePageLoaded = false; + if ( + services.Localization && + $("h1.title").html() === services.Localization.localize("navbar.label.home") + ) { + isHomePageLoaded = true; + } + if (isHomePageLoaded) { + getAllClubPlayers().then(([players]) => { + const clubPlayersData = players.map((player) => ({ + name: player._staticData.name, + assetId: player.assetId, + definitionId: player.definitionId, + rating: player.rating, + isSpecial: player.isSpecial(), + position: player.preferredPosition, + nation: player.nationId, + league: player.nationId, + club: player.teamId, + boughtPrice: player.lastSalePrice, + isLoaned: player.loans > 0, + untradeable: player.untradeable, + imageGuid: player.guidAssetId, + games: player._stats[0], + goals: player._stats[1], + })); + window.ReactNativeWebView.postMessage( + JSON.stringify({ + type: "clubPlayersData", + payload: clubPlayersData, + }) + ); + }); + } else { + setTimeout(fetchClubPlayers, 2000); + } +}; + initScript();