-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductDetails.js
48 lines (41 loc) · 2.05 KB
/
productDetails.js
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
import { toggleMenu } from "./components/hamburger-menu/hamburgerMenuController.js";
import { toggleLoader } from "./components/loader/loaderController.js";
import { showProductDetails } from "./components/product-details/productDetailsController.js";
import { showNotifications } from "./components/notifications/notificationsController.js";
import { handleSession } from "./components/session/sessionController.js";
document.addEventListener("DOMContentLoaded", () => {
const hamburger = document.querySelector(".hamburger");
const navMenu = document.querySelector(".nav-menu");
const loaderContainer = document.querySelector(".loader-container");
const notificationsContainer = document.querySelector(".notifications");
const productContainer = document.querySelector(".product-container");
const { notify } = showNotifications(notificationsContainer);
const searchParams = new URLSearchParams(window.location.search);
const productId = searchParams.get("id");
hamburger.addEventListener("click", () => { toggleMenu(hamburger, navMenu) });
handleSession(navMenu);
if (productId) {
productContainer.addEventListener("load-details-started", () => {
toggleLoader(loaderContainer);
});
productContainer.addEventListener("load-details-finished", () => {
toggleLoader(loaderContainer);
});
productContainer.addEventListener("load-details-failed", (event) => {
const errorMessage = event.detail;
notify(errorMessage);
});
showProductDetails(productContainer, productId);
productContainer.addEventListener("remove-product-succeed", (event) => {
const successMessage = event.detail.message;
const messageType = event.detail.type;
localStorage.setItem("removeProductNotification", JSON.stringify({
message: successMessage,
type: messageType
}));
toggleLoader(loaderContainer);
});
} else {
window.location = "/";
}
});