Skip to content
Open
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
20 changes: 10 additions & 10 deletions public/birthday.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@
style="display: block; font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--gold); margin-bottom: 12px; font-weight: 700;">Select
Flavor</label>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;">
<button class="filter-pill active" onclick="updateBirthdayCake('Red Velvet')">Red Velvet</button>
<button class="filter-pill" onclick="updateBirthdayCake('Dutch Truffle')">Dutch Truffle</button>
<button class="filter-pill" onclick="updateBirthdayCake('Pineapple')">Pineapple</button>
<button class="filter-pill" onclick="updateBirthdayCake('Chocoholic')">Chocoholic</button>
<button class="filter-pill" onclick="updateBirthdayCake('Black Forest')">Black Forest</button>
<button class="filter-pill" onclick="updateBirthdayCake('Cheesecake')">Cheesecake</button>
<button class="filter-pill flavor-btn active" onclick="updateBirthdayCake('Red Velvet')">Red Velvet</button>
<button class="filter-pill flavor-btn" onclick="updateBirthdayCake('Dutch Truffle')">Dutch Truffle</button>
<button class="filter-pill flavor-btn" onclick="updateBirthdayCake('Pineapple')">Pineapple</button>
<button class="filter-pill flavor-btn" onclick="updateBirthdayCake('Chocoholic')">Chocoholic</button>
<button class="filter-pill flavor-btn" onclick="updateBirthdayCake('Black Forest')">Black Forest</button>
<button class="filter-pill flavor-btn" onclick="updateBirthdayCake('Cheesecake')">Cheesecake</button>
</div>
</div>

Expand All @@ -118,10 +118,10 @@
style="display: block; font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--gold); margin-bottom: 12px; font-weight: 700;">Weight
(kg)</label>
<div style="display: flex; gap: 15px;">
<button class="filter-pill" onclick="setCakeWeight('0.5')">0.5 kg</button>
<button class="filter-pill active" onclick="setCakeWeight('1.0')">1.0 kg</button>
<button class="filter-pill" onclick="setCakeWeight('1.5')">1.5 kg</button>
<button class="filter-pill" onclick="setCakeWeight('2.0')">2.0 kg</button>
<button class="filter-pill weight-btn" onclick="setCakeWeight('0.5')">0.5 kg</button>
<button class="filter-pill weight-btn active" onclick="setCakeWeight('1.0')">1.0 kg</button>
<button class="filter-pill weight-btn" onclick="setCakeWeight('1.5')">1.5 kg</button>
<button class="filter-pill weight-btn" onclick="setCakeWeight('2.0')">2.0 kg</button>
</div>
</div>

Expand Down
86 changes: 79 additions & 7 deletions public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let recentSearches = JSON.parse(
localStorage.getItem('brownie_recent_searches') || '[]'
);
let selectedWeight = '1.0';
const BIRTHDAY_DRAFT_KEY = 'brownie_bliss_birthday_draft';
const BIRTHDAY_BASE_PRICES = {
0.5: 450,
'1.0': 850,
Expand Down Expand Up @@ -151,10 +152,77 @@ function useFallbackProducts() {
filterProducts('all');
}
if (document.getElementById('cakePrice')) {
restoreBirthdayDraft();
calculateBdayPrice();
}
}

function readBirthdayDraft() {
try {
const draft = JSON.parse(localStorage.getItem(BIRTHDAY_DRAFT_KEY) || '{}');
return draft && typeof draft === 'object' ? draft : {};
} catch (e) {
console.error('Error parsing birthday draft from localStorage:', e);
return {};
}
}

function saveBirthdayDraft() {
const msgInput = document.getElementById('cakeMessage');
try {
localStorage.setItem(
BIRTHDAY_DRAFT_KEY,
JSON.stringify({
flavor: selectedFlavor,
weight: selectedWeight,
message: msgInput ? msgInput.value : '',
})
);
} catch (e) {
console.error('Error saving birthday draft to localStorage:', e);
}
}

function updateCakeWeightButtons() {
document.querySelectorAll('.weight-btn').forEach((btn) => {
btn.classList.toggle(
'active',
btn.textContent.trim().startsWith(selectedWeight)
);
});
}

function restoreBirthdayDraft() {
if (!document.getElementById('cakePrice')) return;

const draft = readBirthdayDraft();
if (draft.flavor && bdayCakes[draft.flavor]) {
selectedFlavor = draft.flavor;
}
if (draft.weight && BIRTHDAY_BASE_PRICES[draft.weight]) {
selectedWeight = draft.weight;
}
if (!bdayCakes[selectedFlavor]) {
selectedFlavor = Object.keys(bdayCakes)[0] || 'Red Velvet';
}

const msgInput = document.getElementById('cakeMessage');
if (msgInput && typeof draft.message === 'string') {
msgInput.value = draft.message;
}

if (bdayCakes[selectedFlavor]) {
updateBirthdayCake(selectedFlavor, { skipSave: true });
}
updateCakeWeightButtons();
}

function bindBirthdayDraftInput() {
const msgInput = document.getElementById('cakeMessage');
if (!msgInput) return;
msgInput.addEventListener('input', saveBirthdayDraft);
}

const FAVOURITES_KEY = 'brownie_bliss_favourites';
const BROWNIE_BLISS_BAKERY = {
id: 'brownie-bliss',
Expand Down Expand Up @@ -363,6 +431,7 @@ async function loadProducts() {
renderFavouritesPage();
}
if (document.getElementById('cakePrice')) {
restoreBirthdayDraft();
calculateBdayPrice();
}

Expand Down Expand Up @@ -860,7 +929,7 @@ function filterProducts(category = 'all', btn = null) {
// --- BIRTHDAY CAKE BUILDER ---
// bdayCakes object is now populated dynamically via loadProducts()

function updateBirthdayCake(flavor) {
function updateBirthdayCake(flavor, options = {}) {
if (!bdayCakes[flavor]) {
console.error('Cake flavor not found:', flavor);
return;
Expand Down Expand Up @@ -888,18 +957,17 @@ function updateBirthdayCake(flavor) {
});

calculateBdayPrice();
if (!options.skipSave) saveBirthdayDraft();
}

function setCakeWeight(weight, event) {
selectedWeight = weight;

document
.querySelectorAll('.weight-btn')
.forEach((b) => b.classList.remove('active'));

if (event?.target) event.target.classList.add('active');
updateCakeWeightButtons();

calculateBdayPrice();
saveBirthdayDraft();
}

function calculateBdayPrice() {
Expand Down Expand Up @@ -1065,7 +1133,10 @@ function addBirthdayToCart() {
});

showToast('🎂 Birthday cake added to cart!');
if (msgInput) msgInput.value = '';
if (msgInput) {
msgInput.value = '';
saveBirthdayDraft();
}
openCart();
}

Expand Down Expand Up @@ -1577,6 +1648,7 @@ document.addEventListener('DOMContentLoaded', async () => {
renderFavouritesPage();
updateFavouriteButtons('bakeries', BROWNIE_BLISS_BAKERY.id);
initStarRatings();
bindBirthdayDraftInput();

// Track Order auto-fill if on track.html
const urlParams = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -1840,4 +1912,4 @@ document.addEventListener('DOMContentLoaded', () => {
setTimeout(function () {
btn.classList.add("visible");
}, 2000);
})();
})();