Skip to content

Commit

Permalink
[#31] Annapurna/Shubham - Fix the bug with continue button.
Browse files Browse the repository at this point in the history
What changes have you made?

*

Why do we need this change?

*

What can this change impact?
  • Loading branch information
cognitiveskull committed Feb 26, 2019
1 parent 5d43c7c commit febd9ea
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
19 changes: 10 additions & 9 deletions public/scripts/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ const declineCharity = function() {
fetch("/declineCharity");
};

const getCardTitle = function() {
let card = getElementById("card");
return card.children[0] && card.children[0].children[0].innerText;
};

const isSameCard = function(cardTitle) {
return cardTitle == getCardTitle();
const isSameCard = function(card) {
const {title, message} = card;
const cardTitleDiv = getElementById("card-title");
const cardMessageDiv = getElementById("card-message");
const cardTitle = cardTitleDiv && cardTitleDiv.innerText;
const cardMessage = cardMessageDiv && cardMessageDiv.innerText;
return cardTitle == title && cardMessage == message;
};

const showPlainCard = function(title, expenseAmount, type, msg) {
Expand All @@ -138,9 +138,9 @@ const showPlainCard = function(title, expenseAmount, type, msg) {
cardDiv.classList = [];
cardDiv.classList.add("plain-card");
cardDiv.classList.add(type);
const titleDiv = createTextDiv(title);
const titleDiv = createTextDiv(title, "card-title");
titleDiv.classList.add("card-title");
const expenseDiv = createTextDiv("Pay $ " + expenseAmount);
const expenseDiv = createTextDiv("Pay $ " + expenseAmount, "card-message");
expenseDiv.classList.add("card-expense");
cardDiv.appendChild(titleDiv);
cardDiv.appendChild(expenseDiv);
Expand Down Expand Up @@ -265,6 +265,7 @@ const polling = function(game) {
};

const showCard = function(card, isMyTurn, player) {
if (isSameCard(card.data)) return;
const bigDealactions = [acceptBigDeal, declineBigDeal];

const cardHandlers = {
Expand Down
15 changes: 6 additions & 9 deletions public/scripts/deals.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const getCardDiv = function(type) {

const acceptSmallDeal = function(event) {
let parent = event.target.parentElement;
console.log(parent);
fetch("/acceptSmallDeal")
.then(data => data.json())
.then(({isSuccessful}) => {
Expand Down Expand Up @@ -99,8 +98,8 @@ const createCardButtons = function(actions) {
const createRealEstateDealCard = function(actions, card, isMyTurn) {
const {title, message, cost, mortgage, downPayment, cashflow} = card;
const cardDiv = getCardDiv("smallDeal");
const titleDiv = createTextDiv(title);
const messageDiv = createTextDiv(message);
const titleDiv = createTextDiv(title, "card-title");
const messageDiv = createTextDiv(message, "card-message");
const mortgageDiv = createTextDiv(`Mortgage : ${mortgage}`);
const costDiv = createTextDiv(`Cost : ${cost}`);
const downPaymentDiv = createTextDiv(`Down Payment : ${downPayment}`);
Expand All @@ -118,8 +117,8 @@ const createRealEstateDealCard = function(actions, card, isMyTurn) {
const createGoldSmallDeal = function(actions, card, isMyTurn) {
const {title, message, numberOfCoins, cost} = card;
const cardDiv = getCardDiv("smallDeal");
const titleDiv = createTextDiv(title);
const messageDiv = createTextDiv(message);
const titleDiv = createTextDiv(title, "card-title");
const messageDiv = createTextDiv(message, "card-message");
const numberDiv = createTextDiv(`Coins : ${numberOfCoins}`);
const costDiv = createTextDiv(`Cost : ${cost}`);
const bottomDiv = createElement("div");
Expand All @@ -132,8 +131,8 @@ const createGoldSmallDeal = function(actions, card, isMyTurn) {
const createCard = function(card) {
const {title, message, symbol, historicTradingRange, currentPrice} = card;
const cardDiv = getCardDiv("smallDeal");
const titleDiv = createTextDiv(title);
const messageDiv = createTextDiv(message);
const titleDiv = createTextDiv(title, "card-title");
const messageDiv = createTextDiv(message, "card-message");
const symbolDiv = createTextDiv(`Company Name : ${symbol}`);
const rangeDiv = createTextDiv(`Range : ${historicTradingRange}`);
const currentPriceDiv = createTextDiv(`current price : ${currentPrice}`);
Expand Down Expand Up @@ -214,7 +213,6 @@ const showBuyAndSellOptions = function(card) {

const showBuyOption = function(card) {
const cardDiv = createCard(card);
console.log("in show buy option");
const buttons = createElement("div", "buttons-container");
buttons.classList.add("buttons-div");
const accept = createAcceptButton(showOptions.bind(null, false));
Expand Down Expand Up @@ -251,7 +249,6 @@ const getSmallDealHandler = function(card, isMyTurn) {
goldCoins: createGoldSmallDeal.bind(null, smallDealactions),
realEstate: createRealEstateDealCard.bind(null, smallDealactions)
};
// if (card.dealDone) return nothing;
return (
dealCardTypes[card.data.relatedTo] &&
dealCardTypes[card.data.relatedTo].bind(null, card.data, isMyTurn)
Expand Down
12 changes: 6 additions & 6 deletions public/scripts/market.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const getCommon = function(list1, list2) {
}, []);
};

const handleRealEstate = function(player, { relatedRealEstates }) {
const handleRealEstate = function(player, {relatedRealEstates}) {
const playerRealEstates = player.liabilities.realEstate;
const commonEstates = getCommon(relatedRealEstates, playerRealEstates);
const cardDiv = getElementById("card");
Expand All @@ -23,7 +23,7 @@ const handleRealEstate = function(player, { relatedRealEstates }) {

const handleGoldCoin = function() {};
const handleMarketCard = function(player, card) {
const { relatedTo } = card;
const {relatedTo} = card;
const marketHandlers = {
realEstate: handleRealEstate,
goldCoin: handleGoldCoin
Expand All @@ -33,10 +33,10 @@ const handleMarketCard = function(player, card) {
};

const showMarketCard = function(card, player) {
const { title, message } = card.data;
const {title, message} = card.data;
const cardDiv = getElementById("card");
const titleDiv = createTextDiv(title);
const messageDiv = createTextDiv(message);
const titleDiv = createTextDiv(title, "card-title");
const messageDiv = createTextDiv(message, "card-message");
cardDiv.className = "plain-card market-card";
titleDiv.className = "card-title";
messageDiv.className = "card-message";
Expand All @@ -55,7 +55,7 @@ const completeTurn = function() {
const sellEstate = function(estate) {
fetch("/sellestate", {
method: "POST",
headers: { "Content-Type": "application/json" },
headers: {"Content-Type": "application/json"},
body: JSON.stringify(estate)
});
showCommonEstates();
Expand Down
2 changes: 1 addition & 1 deletion public/scripts/professions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const getProfessions = function() {
fetch("/getgame")
.then(data => data.json())
.then(({players}) => {
let container = document.getElementById("container");
let container = document.getElementById("profession-container");
players.map(getProfessionsDiv).join("");
let button = createPopupButton("continue", createFinancialStatement);
container.appendChild(button);
Expand Down
3 changes: 2 additions & 1 deletion public/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ const showOverlay = function(id) {
element.style.visibility = "visible";
};

const createTextDiv = function(text) {
const createTextDiv = function(text, id) {
const textDiv = document.createElement("div");
const textPara = document.createElement("p");
textPara.innerText = text;
textPara.id = id;
textDiv.appendChild(textPara);
return textDiv;
};

0 comments on commit febd9ea

Please sign in to comment.