|
@@ -3,12 +3,13 @@ import { getOnlineUserCount, getUserList } from './service/chat.js';
|
|
|
import { getProducts, sendOrder } from './service/product.js';
|
|
import { getProducts, sendOrder } from './service/product.js';
|
|
|
import { login } from './service/auth.js';
|
|
import { login } from './service/auth.js';
|
|
|
import { createGlobalLoader, showGlobalLoader, hideGlobalLoader } from './utils/loader.js';
|
|
import { createGlobalLoader, showGlobalLoader, hideGlobalLoader } from './utils/loader.js';
|
|
|
-import { updateProgress, claimReward } from './utils/progressBar.js';
|
|
|
|
|
|
|
+import { updateProgress, claimReward, getProgress } from './utils/progressBar.js';
|
|
|
import { showError } from './utils/error.js';
|
|
import { showError } from './utils/error.js';
|
|
|
import { addHistoryRow, setupShoppingCart } from './utils/shoppingCart.js';
|
|
import { addHistoryRow, setupShoppingCart } from './utils/shoppingCart.js';
|
|
|
import { hideGUI, showGUI } from './utils/gui.js';
|
|
import { hideGUI, showGUI } from './utils/gui.js';
|
|
|
import { smartSearch } from './utils/searching.js';
|
|
import { smartSearch } from './utils/searching.js';
|
|
|
import { getUserData } from './service/user.js';
|
|
import { getUserData } from './service/user.js';
|
|
|
|
|
+import { getComment, COMMENT_TYPES } from './utils/get_comment.js';
|
|
|
|
|
|
|
|
// --- Variables Globales ---
|
|
// --- Variables Globales ---
|
|
|
|
|
|
|
@@ -46,14 +47,7 @@ const productPriority = {
|
|
|
]
|
|
]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// --- Chat History ---
|
|
|
|
|
-let chatHistory = [
|
|
|
|
|
- {
|
|
|
|
|
- user: "name",
|
|
|
|
|
- time: "00:00",
|
|
|
|
|
- content: "Hola Mundo"
|
|
|
|
|
- }
|
|
|
|
|
-];
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
const userColors = [
|
|
const userColors = [
|
|
|
// Rojos
|
|
// Rojos
|
|
@@ -80,6 +74,16 @@ const userColors = [
|
|
|
"text-neutral-500", "text-neutral-600", "text-stone-500", "text-stone-600"
|
|
"text-neutral-500", "text-neutral-600", "text-stone-500", "text-stone-600"
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
|
|
+const productsWithVariety = {
|
|
|
|
|
+ "480": [
|
|
|
|
|
+ "Frambuesa",
|
|
|
|
|
+ "Mango",
|
|
|
|
|
+ "Maracuyá",
|
|
|
|
|
+ "Piña",
|
|
|
|
|
+ "Tradicional"
|
|
|
|
|
+ ]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
|
|
|
//--- Elementos del DOM ---
|
|
//--- Elementos del DOM ---
|
|
|
|
|
|
|
@@ -337,6 +341,11 @@ function initializeChat() {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+export function beforeUnloadHandler() {
|
|
|
|
|
+ if (userToken) {
|
|
|
|
|
+ logout();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
/**
|
|
/**
|
|
|
* Setup basic event listeners
|
|
* Setup basic event listeners
|
|
|
*/
|
|
*/
|
|
@@ -357,11 +366,7 @@ function setupBasicListeners() {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- window.addEventListener('beforeunload', function (event) {
|
|
|
|
|
- // Show a confirmation dialog
|
|
|
|
|
- event.preventDefault();
|
|
|
|
|
- event.returnValue = 'Estas saliendo de la aplicacion, estas seguro?';
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ window.addEventListener('beforeunload', beforeUnloadHandler);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -845,15 +850,32 @@ async function renderProductsWithAnimation(products, groupInCategories = true, s
|
|
|
/**
|
|
/**
|
|
|
* Add product to cart with visual feedback
|
|
* Add product to cart with visual feedback
|
|
|
*/
|
|
*/
|
|
|
-window.addToCart = function(productId, buttonElement = null) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+window.addComment = async function(productId) {
|
|
|
|
|
+ const cartItem = cart.find(p => p.id === productId);
|
|
|
|
|
+ if (!cartItem) return;
|
|
|
|
|
+ const comment = await getComment(COMMENT_TYPES.LIBRE, [cartItem.comment]).catch(e => console.error(e));
|
|
|
|
|
+ if (!comment) return;
|
|
|
|
|
+ cartItem.comment += ` ${comment}`;
|
|
|
|
|
+ console.log(cartItem);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+window.addToCart = async function(productId, buttonElement = null) {
|
|
|
|
|
+ let comment = "";
|
|
|
|
|
+ if (productsWithVariety[String(productId)]) {
|
|
|
|
|
+ comment = await getComment(COMMENT_TYPES.DESPLEGABLE, productsWithVariety[String(productId)]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const product = Allproducts.find(p => p.id === productId);
|
|
const product = Allproducts.find(p => p.id === productId);
|
|
|
if (!product) return;
|
|
if (!product) return;
|
|
|
|
|
|
|
|
const cartItem = cart.find(item => item.id === productId);
|
|
const cartItem = cart.find(item => item.id === productId);
|
|
|
if (cartItem) {
|
|
if (cartItem) {
|
|
|
cartItem.quantity++;
|
|
cartItem.quantity++;
|
|
|
|
|
+ cartItem.comment += `${comment}, `;
|
|
|
|
|
+
|
|
|
} else {
|
|
} else {
|
|
|
- cart.push({ ...product, quantity: 1 });
|
|
|
|
|
|
|
+ cart.push({ ...product, quantity: 1, comment });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Visual feedback for button
|
|
// Visual feedback for button
|
|
@@ -951,6 +973,9 @@ function updateCartDisplay() {
|
|
|
<p class="text-sm accent-red">${formatPrice(item.price * item.quantity)}</p>
|
|
<p class="text-sm accent-red">${formatPrice(item.price * item.quantity)}</p>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="flex items-center gap-1 sm:gap-2">
|
|
<div class="flex items-center gap-1 sm:gap-2">
|
|
|
|
|
+ <button class="comment-button text-gray-500 hover:text-gray-400 text-lg sm:text-xl font-bold p-1 rounded-full hover:bg-gray-700 transition-colors" onclick="addComment(${item.id})">
|
|
|
|
|
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-message-plus"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M8 9h8" /><path d="M8 13h6" /><path d="M12.01 18.594l-4.01 2.406v-3h-2a3 3 0 0 1 -3 -3v-8a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v5.5" /><path d="M16 19h6" /><path d="M19 16v6" /></svg>
|
|
|
|
|
+ </button>
|
|
|
<button onclick="addToCart(${item.id})" class="plus-button text-green-500 hover:text-green-400 text-lg sm:text-xl font-bold p-1 rounded-full hover:bg-gray-700 transition-colors">+</button>
|
|
<button onclick="addToCart(${item.id})" class="plus-button text-green-500 hover:text-green-400 text-lg sm:text-xl font-bold p-1 rounded-full hover:bg-gray-700 transition-colors">+</button>
|
|
|
<button onclick="removeFromCart(${item.id})" class="minus-button text-yellow-500 hover:text-yellow-400 text-lg sm:text-xl font-bold p-1 rounded-full hover:bg-gray-700 transition-colors">-</button>
|
|
<button onclick="removeFromCart(${item.id})" class="minus-button text-yellow-500 hover:text-yellow-400 text-lg sm:text-xl font-bold p-1 rounded-full hover:bg-gray-700 transition-colors">-</button>
|
|
|
<button onclick="removeFromCart(${item.id}, true)" class="remove-button text-red-500 hover:text-red-400 text-base sm:text-lg p-1 rounded-full hover:bg-gray-700 transition-colors">
|
|
<button onclick="removeFromCart(${item.id}, true)" class="remove-button text-red-500 hover:text-red-400 text-base sm:text-lg p-1 rounded-full hover:bg-gray-700 transition-colors">
|
|
@@ -987,7 +1012,8 @@ async function processOrder() {
|
|
|
items: cart.map(item => ({
|
|
items: cart.map(item => ({
|
|
|
id: item.id,
|
|
id: item.id,
|
|
|
price: item.price,
|
|
price: item.price,
|
|
|
- quantity: item.quantity
|
|
|
|
|
|
|
+ quantity: item.quantity,
|
|
|
|
|
+ comment: item.comment ?? ""
|
|
|
})),
|
|
})),
|
|
|
totalAmount: cart.reduce((sum, item) => sum + item.price * item.quantity, 0),
|
|
totalAmount: cart.reduce((sum, item) => sum + item.price * item.quantity, 0),
|
|
|
orderDate: new Date().toLocaleString('sv-SE').replace(' ', 'T')
|
|
orderDate: new Date().toLocaleString('sv-SE').replace(' ', 'T')
|
|
@@ -995,7 +1021,7 @@ async function processOrder() {
|
|
|
|
|
|
|
|
const data = await sendOrder(orderData, userToken);
|
|
const data = await sendOrder(orderData, userToken);
|
|
|
|
|
|
|
|
- if (data && data.new_progress) {
|
|
|
|
|
|
|
+ if (data && data.new_progress && data.new_progress !== getProgress()) {
|
|
|
updateProgress(data.new_progress);
|
|
updateProgress(data.new_progress);
|
|
|
}
|
|
}
|
|
|
|
|
|