Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make currency configurable per-item in item data #32

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ function dataListenerCallback(data) {
table.appendChild(row);
}
// Extract bid data
let item = bids[0];
let bidCount = Object.keys(bids).length - 1;
row.children[1].innerText = bids[0].title;
row.children[2].innerText = `£${bids[bidCount].amount.toFixed(2)}`;
let currentBid = bids[bidCount];
row.children[1].innerText = item.title;
row.children[2].innerText = `${item.currency}${currentBid.amount.toFixed(
2
)}`;
row.children[3].innerText = bidCount;
if (bids[bidCount].uid) {
getDoc(doc(db, "users", bids[bidCount].uid)).then((user) => {
if (currentBid.uid) {
getDoc(doc(db, "users", currentBid.uid)).then((user) => {
row.children[4].innerText = user.get("name");
console.debug("dataListener() read from users");
});
Expand All @@ -55,14 +59,14 @@ function dataListenerCallback(data) {
if (isDemo) {
// Make sure some items always appear active for the demo
let now = new Date();
let endTime = bids[0].endTime.toDate();
let endTime = item.endTime.toDate();
endTime.setHours(now.getHours());
endTime.setDate(now.getDate());
endTime.setMonth(now.getMonth());
endTime.setFullYear(now.getFullYear());
row.children[5].dataset.endTime = endTime.getTime();
} else {
row.children[5].dataset.endTime = bids[0].endTime.toMillis();
row.children[5].dataset.endTime = item.endTime.toMillis();
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions js/auctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function generateItemCard(auction) {
bidRow.appendChild(bidTitle);

let bid = document.createElement("td");
bid.innerHTML = "£-.-- [- bids]";
bid.innerHTML = "?-.-- [- bids]";
bid.classList.add("current-bid");
bidRow.appendChild(bid);

Expand Down Expand Up @@ -143,11 +143,12 @@ function dataListenerCallback(data) {
let currentBid = card.querySelector(".current-bid");
// Extract bid data
let bidCount = Object.keys(bids).length - 1;
let currPound = bids[bidCount].amount.toFixed(2);
let currentAmount = bids[bidCount].amount.toFixed(2);
// Add bid data to HTML
currentBid.innerHTML = `£${numberWithCommas(currPound)} [${bidCount} bid${
bidCount != 1 ? "s" : ""
}]`;
let plural = bidCount != 1 ? "s" : "";
currentBid.innerHTML = `${item.currency}${numberWithCommas(
currentAmount
)} [${bidCount} bid${plural}]`;
// Update everything else
if (isDemo) {
// Make sure some items always appear active for the demo
Expand Down
12 changes: 12 additions & 0 deletions js/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let items = [
subtitle: "",
detail: "",
secondaryImage: "",
currency: "£",
amount: 55,
endTime: "2023-04-25T00:00:00+00:00",
},
Expand All @@ -18,6 +19,7 @@ let items = [
subtitle: "",
detail: "",
secondaryImage: "",
currency: "£",
amount: 60,
endTime: "2023-04-25T00:05:00+00:00",
},
Expand All @@ -27,6 +29,7 @@ let items = [
subtitle: "",
detail: "",
secondaryImage: "",
currency: "£",
amount: 20,
endTime: "2023-04-25T00:10:00+00:00",
},
Expand All @@ -36,6 +39,7 @@ let items = [
subtitle: "",
detail: "",
secondaryImage: "",
currency: "£",
amount: 0,
endTime: "2023-04-25T00:15:00+00:00",
},
Expand All @@ -45,6 +49,7 @@ let items = [
subtitle: "",
detail: "",
secondaryImage: "",
currency: "£",
amount: 4,
endTime: "2023-04-25T00:20:00+00:00",
},
Expand All @@ -54,6 +59,7 @@ let items = [
subtitle: "",
detail: "",
secondaryImage: "",
currency: "£",
amount: 0,
endTime: "2023-04-25T00:25:00+00:00",
},
Expand All @@ -63,6 +69,7 @@ let items = [
subtitle: "",
detail: "",
secondaryImage: "",
currency: "£",
amount: 99,
endTime: "2023-04-25T00:30:00+00:00",
},
Expand All @@ -72,6 +79,7 @@ let items = [
subtitle: "",
detail: "",
secondaryImage: "",
currency: "£",
amount: 0,
endTime: "2023-04-25T00:35:00+00:00",
},
Expand All @@ -81,6 +89,7 @@ let items = [
subtitle: "",
detail: "",
secondaryImage: "",
currency: "£",
amount: 12,
endTime: "2023-04-25T00:40:00+00:00",
},
Expand All @@ -90,6 +99,7 @@ let items = [
subtitle: "",
detail: "",
secondaryImage: "",
currency: "£",
amount: 6,
endTime: "2023-04-25T00:45:00+00:00",
},
Expand All @@ -99,6 +109,7 @@ let items = [
subtitle: "",
detail: "",
secondaryImage: "",
currency: "£",
amount: 3,
endTime: "2023-04-25T00:50:00+00:00",
},
Expand All @@ -108,6 +119,7 @@ let items = [
subtitle: "",
detail: "",
secondaryImage: "",
currency: "£",
amount: 7,
endTime: "2023-04-25T00:55:00+00:00",
},
Expand Down
6 changes: 4 additions & 2 deletions js/popups.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ if (bidModal) {
let data = doc.data();
let itemId = `item${i.toString().padStart(5, "0")}`;
let bids = Object.keys(data).filter((key) => key.includes(itemId));
let item = data[bids[0]];
let bidId = `bid${bids.length.toString().padStart(5, "0")}`;
let currentBid = data[bids[bids.length - 1]].amount;
if (amount >= 1 + currentBid) {
Expand All @@ -186,8 +187,9 @@ if (bidModal) {
}, 1000);
} else {
amountElement.classList.add("is-invalid");
feedback.innerText =
"You must bid at least £" + (currentBid + 1).toFixed(2) + "!";
feedback.innerText = `You must bid at least ${item.currency}${(
currentBid + 1
).toFixed(2)}!`;
bidModalSubmit.removeAttribute("disabled", "");
}
});
Expand Down
Loading