Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
club data sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ckumar03 committed Jun 14, 2023
1 parent 3276df1 commit 4d1d5b1
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();

0 comments on commit 4d1d5b1

Please sign in to comment.