-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (42 loc) · 1.91 KB
/
Copy pathapp.js
File metadata and controls
51 lines (42 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Función para mostrar "app" y ocultar "main"
function mostrarAppYOcultarMain() {
const app = document.getElementById("app");
const main = document.getElementById("maincontenido");
app.style.display = ""; // Mostrar "app"
main.style.display = "none"; // Ocultar "main"
}
// Escuchar el clic en el botón de inicio de sesión para mostrar "app" y ocultar "main"
document.getElementById("btnLogin").addEventListener("click", () => {
mostrarAppYOcultarMain();
});
// Función para cargar y mostrar los productos desde JSON Server
async function cargarProductos() {
try {
const response = await fetch("https://raw.githubusercontent.com/PunksCode/Ecommerce/main/db.json"); // Reemplaza la URL con la del servidor JSON
const data = await response.json();
const productos = data.juguetes;
// Lógica para mostrar los productos en tu página
const productosContainer = document.querySelector(".juguetes"); // Reemplaza con el selector correcto de tu contenedor de productos
productos.forEach((producto) => {
const card = nuevosProductos(producto.id, producto.name, producto.imageUrl, producto.price);
productosContainer.appendChild(card);
});
} catch (error) {
console.error(error);
}
}
// Función para mostrar "app" y ocultar "main"
function mostrarAppYOcultarMain() {
const app = document.getElementById("app");
const main = document.getElementById("maincontenido");
app.style.display = ""; // Mostrar "app"
main.style.display = "none"; // Ocultar "main"
}
// Escuchar el clic en el botón de inicio de sesión para mostrar "app" y ocultar "main"
document.getElementById("btnLogin").addEventListener("click", () => {
mostrarAppYOcultarMain();
});
// Después de que se cargue la página, cargar automáticamente los productos
document.addEventListener("DOMContentLoaded", () => {
cargarProductos();
});