Skip to content

Commit 9fad762

Browse files
Update script.js
1 parent 19e563d commit 9fad762

1 file changed

Lines changed: 53 additions & 33 deletions

File tree

script.js

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,72 @@
11
let selectedBooth = null;
22
let selectedVibe = null;
33

4-
function setActive(containerId, datasetKey, value) {
5-
const container = document.getElementById(containerId);
6-
const buttons = container.querySelectorAll("button");
7-
buttons.forEach(btn => {
8-
btn.classList.toggle("active", btn.dataset[datasetKey] === value);
9-
});
4+
const boothButtons = document.querySelectorAll("#booths button");
5+
const vibeButtons = document.querySelectorAll("#vibes button");
6+
7+
const detailEl = document.getElementById("detail");
8+
const ticketEl = document.getElementById("ticket");
9+
const placeOrderBtn = document.getElementById("placeOrder");
10+
const copyBtn = document.getElementById("copyBtn");
11+
const confirmText = document.getElementById("confirmText");
12+
13+
function setActive(buttons, target){
14+
buttons.forEach(b => b.classList.remove("active"));
15+
target.classList.add("active");
1016
}
1117

12-
document.getElementById("booths").addEventListener("click", (e) => {
13-
const btn = e.target.closest("button");
14-
if (!btn) return;
15-
selectedBooth = btn.dataset.booth;
16-
setActive("booths", "booth", selectedBooth);
18+
boothButtons.forEach(btn => {
19+
btn.addEventListener("click", () => {
20+
selectedBooth = btn.dataset.booth;
21+
setActive(boothButtons, btn);
22+
confirmText.textContent = "";
23+
});
1724
});
1825

19-
document.getElementById("vibes").addEventListener("click", (e) => {
20-
const btn = e.target.closest("button");
21-
if (!btn) return;
22-
selectedVibe = btn.dataset.vibe;
23-
setActive("vibes", "vibe", selectedVibe);
26+
vibeButtons.forEach(btn => {
27+
btn.addEventListener("click", () => {
28+
selectedVibe = btn.dataset.vibe;
29+
setActive(vibeButtons, btn);
30+
confirmText.textContent = "";
31+
});
2432
});
2533

26-
document.getElementById("placeOrder").addEventListener("click", () => {
27-
const detail = document.getElementById("detail").value.trim();
34+
function buildTicket(){
35+
const detail = (detailEl.value || "").trim();
36+
return `Booth: ${selectedBooth || "(pick one)"}\nVibe: ${selectedVibe || "(pick one)"}\nDetail: ${detail || "(add one sentence)"}`;
37+
}
38+
39+
placeOrderBtn.addEventListener("click", () => {
40+
const detail = (detailEl.value || "").trim();
2841

29-
if (!selectedBooth || !selectedVibe || !detail) {
30-
alert("Pick a booth, pick a vibe, and add one sentence.");
42+
if(!selectedBooth || !selectedVibe){
43+
confirmText.textContent = "Pick a Booth and a Vibe first.";
44+
return;
45+
}
46+
if(detail.length === 0){
47+
confirmText.textContent = "Add one sentence in the detail box.";
3148
return;
3249
}
3350

34-
const ticketText =
35-
`Booth: ${selectedBooth}
36-
Vibe: ${selectedVibe}
37-
Detail: ${detail}`;
51+
const ticket = buildTicket();
52+
ticketEl.textContent = ticket;
3853

39-
document.getElementById("ticket").textContent = ticketText;
40-
document.getElementById("copyBtn").style.display = "inline-block";
41-
document.getElementById("status").style.display = "block";
54+
copyBtn.style.display = "inline-block";
55+
confirmText.textContent = "Order received. The bartender is working.";
4256
});
4357

44-
document.getElementById("copyBtn").addEventListener("click", async () => {
45-
const text = document.getElementById("ticket").textContent;
46-
try {
58+
copyBtn.addEventListener("click", async () => {
59+
const text = ticketEl.textContent.trim();
60+
if(!text){
61+
confirmText.textContent = "No ticket to copy yet.";
62+
return;
63+
}
64+
65+
try{
4766
await navigator.clipboard.writeText(text);
48-
alert("Ticket copied. Paste it into the Bronzed Derby chat.");
49-
} catch {
50-
alert("Couldn’t auto-copy. Manually select the ticket text and copy it.");
67+
confirmText.textContent = "Ticket copied. Paste it into ChatGPT (or your House Generator prompt).";
68+
}catch(e){
69+
// Fallback if clipboard permission fails
70+
confirmText.textContent = "Copy failed. Select the ticket text and copy manually.";
5171
}
5272
});

0 commit comments

Comments
 (0)