forked from yash11255/FINALDC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetail.html
94 lines (89 loc) · 3.1 KB
/
detail.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>COIN DETAIL</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<div class="title">
COIN DETAIL
<a href="dashboard.html" class="button-34" role="button">Dashboard</a>
</div>
<div class="detail">
<div class="image">
<img src="" />
</div>
<div class="content">
<h1 class="name"></h1>
<div class="price"></div>
<div class="buttons">
<button>Check Out</button>
<button>
Add To Cart
<span>
<svg
class=""
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 18 20"
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 15a2 2 0 1 0 0 4 2 2 0 0 0 0-4Zm0 0h8m-8 0-1-4m9 4a2 2 0 1 0 0 4 2 2 0 0 0 0-4Zm-9-4h10l2-7H3m2 7L3 4m0 0-.792-3H1"
/>
</svg>
</span>
</button>
</div>
<div class="description"></div>
</div>
</div>
<div class="title">TRENDING COINS</div>
<div class="listProduct"></div>
</div>
<script>
let products = null;
// get datas from file json
fetch("products.json")
.then((response) => response.json())
.then((data) => {
products = data;
showDetail();
});
function showDetail() {
// remove datas default from HTML
let detail = document.querySelector(".detail");
let listProduct = document.querySelector(".listProduct");
let productId = new URLSearchParams(window.location.search).get("id");
let thisProduct = products.filter((value) => value.id == productId)[0];
//if there is no product with id = productId => return to home page
if (!thisProduct) {
window.location.href = "/";
}
detail.querySelector(".image img").src = thisProduct.image;
detail.querySelector(".name").innerText = thisProduct.name;
detail.querySelector(".price").innerText = "$" + thisProduct.price;
detail.querySelector(".description").innerText =
"$" + thisProduct.description;
products
.filter((value) => value.id != productId)
.forEach((product) => {
let newProduct = document.createElement("a");
newProduct.href = "FINALDC/detail.html?id=" + product.id;
newProduct.classList.add("item");
newProduct.innerHTML = `<img src="${product.image}" alt="">
<h2>${product.name}</h2>
<div class="price">$${product.price}</div>`;
listProduct.appendChild(newProduct);
});
}
</script>
</body>
</html>