|
@@ -28,6 +28,23 @@ let cacheMode = false;
|
|
|
|
|
|
|
|
// --- Configuration ---
|
|
// --- Configuration ---
|
|
|
const favoriteCategories = ["Shop", "Pizzas Familiares", "Pizza Medianas"];
|
|
const favoriteCategories = ["Shop", "Pizzas Familiares", "Pizza Medianas"];
|
|
|
|
|
+const productPriority = {
|
|
|
|
|
+ "Shop": [
|
|
|
|
|
+ 6, 12, 163, 168, 15, 665, 1
|
|
|
|
|
+ ],
|
|
|
|
|
+ "Cervezas": [
|
|
|
|
|
+ 17,
|
|
|
|
|
+ ],
|
|
|
|
|
+ "Coctelería Gin Klein": [
|
|
|
|
|
+ 655
|
|
|
|
|
+ ],
|
|
|
|
|
+ "Pizzas Familiares": [
|
|
|
|
|
+ 27
|
|
|
|
|
+ ],
|
|
|
|
|
+ "Pizza Medianas": [
|
|
|
|
|
+ 2
|
|
|
|
|
+ ]
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
// --- Chat History ---
|
|
// --- Chat History ---
|
|
|
let chatHistory = [
|
|
let chatHistory = [
|
|
@@ -166,7 +183,7 @@ function initializeLoginModal() {
|
|
|
userToken = null;
|
|
userToken = null;
|
|
|
cacheMode = false;
|
|
cacheMode = false;
|
|
|
hideGUI();
|
|
hideGUI();
|
|
|
- sessionModal.classList.remove('hidden');
|
|
|
|
|
|
|
+ sessionModal.classList.remove('hidden');false
|
|
|
|
|
|
|
|
// Reset UI elements
|
|
// Reset UI elements
|
|
|
document.querySelector("#emailInputContainer").classList.remove("hidden");
|
|
document.querySelector("#emailInputContainer").classList.remove("hidden");
|
|
@@ -355,7 +372,7 @@ function setupSearchListener() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const foundProducts = smartSearch(Allproducts, searchTerm);
|
|
const foundProducts = smartSearch(Allproducts, searchTerm);
|
|
|
- renderProductsWithAnimation(foundProducts, false, searchTerm);
|
|
|
|
|
|
|
+ renderProductsWithAnimation(foundProducts, true, searchTerm);
|
|
|
}, 200);
|
|
}, 200);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -521,7 +538,28 @@ async function renderProducts(products, groupInCategories = true, searchTerm = "
|
|
|
let productsInCategory = groupInCategories
|
|
let productsInCategory = groupInCategories
|
|
|
? products.filter(product => product.type === category)
|
|
? products.filter(product => product.type === category)
|
|
|
: products;
|
|
: products;
|
|
|
-
|
|
|
|
|
|
|
+ // Prioritize products in favorite categories
|
|
|
|
|
+ if (favoriteCategories.includes(category) && productPriority[category]) {
|
|
|
|
|
+ productsInCategory.sort((a, b) => {
|
|
|
|
|
+ const aIndex = productPriority[category].indexOf(a.id);
|
|
|
|
|
+ const bIndex = productPriority[category].indexOf(b.id);
|
|
|
|
|
+
|
|
|
|
|
+ // If both products are in priority list, sort by their priority order
|
|
|
|
|
+ if (aIndex !== -1 && bIndex !== -1) {
|
|
|
|
|
+ return aIndex - bIndex;
|
|
|
|
|
+ }
|
|
|
|
|
+ // If only 'a' is in priority list, it should come first
|
|
|
|
|
+ if (aIndex !== -1 && bIndex === -1) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ // If only 'b' is in priority list, it should come first
|
|
|
|
|
+ if (aIndex === -1 && bIndex !== -1) {
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ // If neither is in priority list, maintain original order
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
if (productsInCategory.length === 0) continue;
|
|
if (productsInCategory.length === 0) continue;
|
|
|
|
|
|
|
|
productsInCategory.forEach(product => {
|
|
productsInCategory.forEach(product => {
|
|
@@ -568,6 +606,13 @@ async function renderProductsWithAnimation(products, groupInCategories = true, s
|
|
|
categoryContainers = [{ category: searchTerm, container: productListElement }];
|
|
categoryContainers = [{ category: searchTerm, container: productListElement }];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // ordenar las categorias por favoriteCategories
|
|
|
|
|
+ categoryContainers.sort((a, b) => {
|
|
|
|
|
+ const aIndex = favoriteCategories.indexOf(a.category);
|
|
|
|
|
+ const bIndex = favoriteCategories.indexOf(b.category);
|
|
|
|
|
+ return aIndex - bIndex;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
if (products.length === 0) {
|
|
if (products.length === 0) {
|
|
|
const noProductsMessage = document.createElement("p");
|
|
const noProductsMessage = document.createElement("p");
|
|
|
noProductsMessage.textContent = "No hay productos disponibles.";
|
|
noProductsMessage.textContent = "No hay productos disponibles.";
|
|
@@ -596,6 +641,28 @@ async function renderProductsWithAnimation(products, groupInCategories = true, s
|
|
|
|
|
|
|
|
if (productsInCategory.length === 0) continue;
|
|
if (productsInCategory.length === 0) continue;
|
|
|
|
|
|
|
|
|
|
+ if (favoriteCategories.includes(category) && productPriority[category]) {
|
|
|
|
|
+ productsInCategory.sort((a, b) => {
|
|
|
|
|
+ const aIndex = productPriority[category].indexOf(a.id);
|
|
|
|
|
+ const bIndex = productPriority[category].indexOf(b.id);
|
|
|
|
|
+
|
|
|
|
|
+ // If both products are in priority list, sort by their priority order
|
|
|
|
|
+ if (aIndex !== -1 && bIndex !== -1) {
|
|
|
|
|
+ return aIndex - bIndex;
|
|
|
|
|
+ }
|
|
|
|
|
+ // If only 'a' is in priority list, it should come first
|
|
|
|
|
+ if (aIndex !== -1 && bIndex === -1) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ // If only 'b' is in priority list, it should come first
|
|
|
|
|
+ if (aIndex === -1 && bIndex !== -1) {
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ // If neither is in priority list, maintain original order
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
productsInCategory.forEach((product, index) => {
|
|
productsInCategory.forEach((product, index) => {
|
|
|
const clone = template.content.cloneNode(true);
|
|
const clone = template.content.cloneNode(true);
|
|
|
|
|
|
|
@@ -946,6 +1013,15 @@ function initializeRewards() {
|
|
|
closeModal();
|
|
closeModal();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ // Close model - Back button on phone
|
|
|
|
|
+ WindowEventHandlers.onpopstate = function (event) {
|
|
|
|
|
+ if (!rewardModal.classList.contains('hidden')) {
|
|
|
|
|
+ event.preventDefault();
|
|
|
|
|
+ event.stopPropagation();
|
|
|
|
|
+ closeModal();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Close modal - click outside
|
|
// Close modal - click outside
|
|
|
rewardModal.addEventListener('click', function (e) {
|
|
rewardModal.addEventListener('click', function (e) {
|
|
|
if (e.target === rewardModal) {
|
|
if (e.target === rewardModal) {
|
|
@@ -1003,24 +1079,6 @@ function closeModal() {
|
|
|
claimRewardBtn.classList.add('opacity-50', 'cursor-not-allowed');
|
|
claimRewardBtn.classList.add('opacity-50', 'cursor-not-allowed');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * Reset reward progress to 0%
|
|
|
|
|
- */
|
|
|
|
|
-function resetRewardProgress() {
|
|
|
|
|
- const progressBar = document.getElementById('progressBar');
|
|
|
|
|
- const progressText = document.getElementById('progressText');
|
|
|
|
|
- const rewardBtn = document.getElementById('rewardBtn');
|
|
|
|
|
-
|
|
|
|
|
- progressBar.style.width = '0%';
|
|
|
|
|
- progressText.textContent = '0%';
|
|
|
|
|
-
|
|
|
|
|
- rewardBtn.disabled = true;
|
|
|
|
|
- rewardBtn.classList.add('opacity-50', 'cursor-not-allowed');
|
|
|
|
|
- rewardBtn.classList.remove('bg-yellow-500', 'hover:bg-yellow-600');
|
|
|
|
|
- rewardBtn.textContent = '🎉 ¡Reclamar!';
|
|
|
|
|
-}
|
|
|
|
|
//--- Inicialización de la Aplicación ---
|
|
//--- Inicialización de la Aplicación ---
|
|
|
|
|
|
|
|
/**
|
|
/**
|