diff --git a/src/App.js b/src/App.js index 2be56fc..6f4d4e8 100644 --- a/src/App.js +++ b/src/App.js @@ -8,6 +8,7 @@ import { HomeMenu, PlayerInfo, PlayerList, SearchBar, TournamentInfo, Tournament import decks from './data/decks.js'; import tournamentList from './data/tournaments.js'; import playerList from './data/players.js'; +import topDecks from './data/topDecks.js'; const buttonStyle = { height: '25px', @@ -51,10 +52,14 @@ class App extends React.Component { tournamentList: tournamentList, decks: decks, playerList: playerList, + topDecks: topDecks, + currentTournament: null, currentPlayer: null, + show: 'home', data: null, + checkedChallenge: false, checkedPoints: false, tracker: 0 @@ -195,6 +200,11 @@ class App extends React.Component { playerList.sort(function (a, b) { return a.name.localeCompare(b.name); }); + topDecks.sort(function (a, b) { + return b.currCP - a.currCP; + }); + + this.setState({ playerList: playerList, topDecks: topDecks}) // Call our fetch function below once the component mounts this.callBackendAPI() .then(res => this.setState({ data: res.express })) @@ -214,7 +224,7 @@ class App extends React.Component { render () { const { tournamentList, currentTournament, playerList, currentPlayer, - decks, show, checkedChallenge, checkedPoints } = this.state; + decks, topDecks, show, checkedChallenge, checkedPoints } = this.state; return ( @@ -241,7 +251,8 @@ class App extends React.Component { setCurrentTournament={this.setCurrentTournament} tournaments={tournamentList} decks={decks} - players={playerList}/>} + players={playerList} + topDecks={topDecks}/>} {show === 'tournamentList' && } diff --git a/src/components/HomeMenu.js b/src/components/HomeMenu.js index 4da0613..a8e842e 100644 --- a/src/components/HomeMenu.js +++ b/src/components/HomeMenu.js @@ -9,7 +9,7 @@ const text = { padding: '10px' } -const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => { +const HomeMenu = ({ setCurrentTournament, tournaments, decks, topDecks, players }) => { players = players.sort(function (a, b) { return b.points - a.points; }); @@ -20,11 +20,13 @@ const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => { const isDesktop = useMediaQuery({ minWidth: 992 }); const isNotMobile = useMediaQuery({ minWidth: 768 }); + const isNotTablet = useMediaQuery({ minWidth: 992 }); let headerStyle = {}; let cellStyle = {}; let tableGrid = {}; + let flexContainer = {}; - if (isNotMobile) { + if (isNotTablet) { headerStyle = { color: 'white', fontFamily: 'Muli', @@ -40,6 +42,10 @@ const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => { height: '80%', backgroundColor: 'white' }; + flexContainer = { + display: 'flex', + flex: 1 + } } else { headerStyle = { color: 'white', @@ -48,12 +54,12 @@ const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => { }; cellStyle = { fontFamily: 'Muli', - fontSize: '10px' + fontSize: '16px' }; tableGrid = { - margin: '20px', - width: '90%', - height: '85%', + margin: '10px', + width: '95%', + height: '90%', backgroundColor: 'white' }; } @@ -72,7 +78,7 @@ const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => { width: '100%', }, tableWrapper: { - maxHeight: 750, + maxHeight: 800, minWidth: 100, overflow: 'hidden', }, @@ -103,7 +109,7 @@ const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => { - {currFormat.map((tournament, key) => { + {currFormat.slice(0,5).map((tournament, key) => { var search = compareDecks(tournament.standings[0]); if (search.hasOwnProperty('thumbnails')) { var sprites = search.thumbnails.map((img, key) => { @@ -159,29 +165,66 @@ const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => { */} - -

Top Performing Players

- -
- - - - Name - Points - - - - {players.map((player, key) => { - return( - - {player.name} - {player.points} - - )})} - -
-
-
+ + +

Top Performing Decks of the Week

+ +
+ + + + Deck + + Points + + + + {topDecks.slice(0,5).map((deck, key) => { + var search = compareDecks(deck); + if (search.hasOwnProperty('thumbnails')) { + var sprites = search.thumbnails.map((img, key) => { + if (isDesktop) { + return rekt + } else { + return rekt + } + })}; + return( + + {deck.deck} + {sprites} + {deck.currCP} + + )})} + +
+
+
+
+ +

Top Performing Players

+ +
+ + + + Name + Points + + + + {players.slice(0,10).map((player, key) => { + return( + + {player.name} + {player.points} + + )})} + +
+
+
+
) diff --git a/src/components/mediaQuery.js b/src/components/mediaQuery.js index b629c55..36de616 100644 --- a/src/components/mediaQuery.js +++ b/src/components/mediaQuery.js @@ -4,6 +4,7 @@ const isDesktop = useMediaQuery({ minWidth: 992 }); const isTablet = useMediaQuery({ minWidth: 768, maxWidth: 991 }); const isMobile = useMediaQuery({ maxWidth: 767 }); const isNotMobile = useMediaQuery({ minWidth: 768 }); +const isNotTablet = useMediaQuery({ minWidth: 992 }); module.exports = isMobile; diff --git a/src/data/topDecks.js b/src/data/topDecks.js new file mode 100644 index 0000000..32b2ffa --- /dev/null +++ b/src/data/topDecks.js @@ -0,0 +1,31 @@ +const topDecks = [ +{ deck: "Pikachu & Zekrom-GX", currCP: 971, totalCP: 1118 }, +{ deck: "Ability Reshiram & Charizard-GX", currCP: 1234, totalCP: 1269 }, +{ deck: "Blacephalon-GX / Naganadel", currCP: 272, totalCP: 307 }, +{ deck: "Malamar / Giratina", currCP: 164, totalCP: 164 }, +{ deck: "Malamar / Ultra Necrozma-GX", currCP: 50, totalCP: 135 }, +{ deck: "Gardevoir & Sylveon-GX", currCP: 57, totalCP: 57 }, +{ deck: "Mew & Mewtwo-GX Toolbox", currCP: 511, totalCP: 519 }, +{ deck: "Spiritomb / Froslass", currCP: 32, totalCP: 32 }, +{ deck: "Beheeyem", currCP: 50, totalCP: 50 }, +{ deck: "Pidgeotto Control", currCP: 40, totalCP: 40 }, +{ deck: "Green's Reshiram & Charizard-GX", currCP: 349, totalCP: 398 }, +{ deck: "Malamar / Garchomp & Giratina-GX", currCP: 85, totalCP: 85 }, +{ deck: "Quagsire / Naganadel", currCP: 160, totalCP: 160 }, +{ deck: "Naganadel-GX Checkmate", currCP: 80, totalCP: 80 }, +{ deck: "Blastoise / Keldeo-GX", currCP: 60, totalCP: 60 }, +{ deck: "Baby Blacephalon", currCP: 60, totalCP: 134 }, +{ deck: "Weavile-GX Toolbox", currCP: 10, totalCP: 10 }, +{ deck: "Donphan / Florges", currCP: 0, totalCP: 15 }, +{ deck: "Zoroark-GX / Greninja & Zoroark-GX", currCP: 0, totalCP: 10 }, +{ deck: "Zoroark-GX Checkmate", currCP: 0, totalCP: 12 }, +{ deck: "Vileplume Stall", currCP: 0, totalCP: 45 }, +{ deck: "Zoroark-GX / Persian", currCP: 0, totalCP: 50 }, +{ deck: "Zygarde-GX", currCP: 0, totalCP: 32 }, +{ deck: "Zoroark-GX / Silvally-GX", currCP: 0, totalCP: 32 }, +{ deck: "Zoroark-GX / Dewgong", currCP: 0, totalCP: 40 }, +{ deck: "Beast Box", currCP: 0, totalCP: 15 }, +{ deck: "Zapdos / Ultra Beasts", currCP: 0, totalCP: 25 }, +]; + +module.exports = topDecks; \ No newline at end of file diff --git a/src/scripts/init_players.js b/src/scripts/init_homeData.js similarity index 64% rename from src/scripts/init_players.js rename to src/scripts/init_homeData.js index c1c90b2..c0e0608 100644 --- a/src/scripts/init_players.js +++ b/src/scripts/init_homeData.js @@ -1,4 +1,4 @@ -/* This script is primarily only used to initialise players into the objects +/* This script is primarily only used to initialise players and decks into the objects to be exported for data use. The class initialisation is included and the script will go through the tournament list to insert any new occurrence of players. */ @@ -47,6 +47,29 @@ function calcPointPayout(tournament, player) { return 0; }; +// Class declaration for Deck +class Deck { + constructor(deck) { + this.deck = deck; + this.totalCP = 0; // total CP earnt + this.currCP = 0; // CP earnt in last 10 tournaments + } + + get string() { + var string = ''; + string += '{ deck: "' + this.deck + '", currCP: ' + this.currCP + ', totalCP: ' + this.totalCP + ' },\n' + return string + } + + addCurrCP(value) { + this.currCP += value; + } + + addTotalCP(value) { + this.totalCP += value; + } +} + // Class declaration for Player class Player { constructor(name) { @@ -90,40 +113,62 @@ class Player { } // Inputs all the players from all the tournaments into a PlayerList database -var PlayerList = [] +var PlayerList = []; +var DeckList = []; // Iterates through each tournament and the standings for (let i = 0; i < tournaments.length; i++) { tournaments[i].standings.map((player, key) => { - var search = PlayerList.some(entry => entry.name === player.name); + var playerSearch = PlayerList.some(entry => entry.name === player.name); + var deckSearch = DeckList.some(entry => entry.deck === player.deck); // If the player is already in the database - if (search) { + if (playerSearch) { } else { PlayerList.push(new Player(player.name)); } + if (deckSearch) { + } else { + DeckList.push(new Deck(player.deck)); + } + // Adds the achievement into the database PlayerList[PlayerList.findIndex(x => x.name === player.name)].addAchievement(tournaments[i].date, tournaments[i].name, tournaments[i].cycle, player.deck, player.placing); PlayerList[PlayerList.findIndex(x => x.name === player.name)].addPoints(calcPointPayout(tournaments[i], player)); + if (i < 10) { + DeckList[DeckList.findIndex(x => x.deck === player.deck)].addCurrCP(calcPointPayout(tournaments[i], player)); + } + DeckList[DeckList.findIndex(x => x.deck === player.deck)].addTotalCP(calcPointPayout(tournaments[i], player)); }); } // Debugging purposes -// for (let j = 0; j < PlayerList.length; j++) { -// if (PlayerList[j].name === 'Brent Tonisson' || PlayerList[j].name === 'Henry Brand') -// console.log(PlayerList[j].achievements); +// for (let j = 0; j < DeckList.length; j++) { +// // if (PlayerList[j].name === 'Brent Tonisson' || PlayerList[j].name === 'Henry Brand') +// console.log(DeckList[j]); // } -// console.log(PlayerList.length) +// console.log(DeckList.length); -var data = 'const players = [\n'; +var playerData = 'const players = [\n'; for (var i = 0; i < PlayerList.length; i++) { - data += '{ name: "' + PlayerList[i].name + '",\nachievements: [' + PlayerList[i].achievementList + '], points: ' + PlayerList[i].points + ' },\n'; + playerData += '{ name: "' + PlayerList[i].name + '",\nachievements: [' + PlayerList[i].achievementList + '], points: ' + PlayerList[i].points + ' },\n'; +} + +playerData += '];\n\nmodule.exports = players;' + +var deckData = 'const topDecks = [\n'; +for (var i = 0; i < DeckList.length; i++) { + deckData += DeckList[i].string; } -data += '];\n\nmodule.exports = players;' +deckData += '];\n\nmodule.exports = topDecks;' var fs = require('fs'); -fs.writeFile('../data/players.js', data, function (err, file) { +fs.writeFile('../data/players.js', playerData, function (err, file) { + if (err) throw err; +}); + +fs.writeFile('../data/topDecks.js', deckData, function (err, file) { if (err) throw err; });