-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
37 lines (29 loc) · 1.06 KB
/
script.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
import { displayCartItems } from './cart.js';
import { displayData } from './products.js';
const iconQtyAction = document.querySelector('.header__icon');
//fetch all data
function fetchData() {
fetch('./products.json')
.then((data) => data.json())
.then((response) => displayData(response))
.catch((err) => console.error(err.message));
}
function getLocalStorage(description) {
return localStorage.getItem(description)
? JSON.parse(localStorage.getItem(description))
: undefined;
}
function setLocalStorage(description, article) {
localStorage.setItem(description, JSON.stringify(article));
if (description === 'currentCart') displayCartItems(article);
}
iconQtyAction.addEventListener('click', handlePageView);
function handlePageView() {
const allProductsApp = document.querySelector('.allProductsApp');
const shoppingCartApp = document.querySelector('.shoppingCartApp');
allProductsApp.style.display = 'none';
shoppingCartApp.style.display = 'block';
}
//start app loading all data
fetchData();
export { getLocalStorage, setLocalStorage };