-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyproduct.js
76 lines (52 loc) · 2.47 KB
/
myproduct.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
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
let content_product = document.querySelector('.content_product')
let showproducts = function (products = []) {
// let loopproducts = products.filter(item => item.me === 'yes');
// content_product.innerHTML = ""; // مسح المحتوى السابق قبل إضافة المحتوى الجديد
// loopproducts.map(ele => {
// let new_product = document.createElement("div");
// new_product.classList.add("content_product_item");
// new_product.style.border = ele.me == 'yes' ? "1px solid red" : "none";
// new_product.innerHTML = `
// <img src="${ele.img_src}" alt="">
// <div class="content_product_item_desc">
// <h2 onclick="savedeatlisid(${ele.id})">${ele.title}</h2>
// <p>${ele.desc}</p>
// <p>${ele.size}</p>
// <h2 id="button" onclick="deleteproduct(${ele.id})">Delete product</h2>
// ${ele.me === "yes" ? `<h2 class='edti_product'onclick='editproduct(${ele.id})'>Edit product</h2>` : ''}
// <i class="fa fa-heart" aria-hidden="true"></i>
// </div>
// `
// content_product.appendChild(new_product);
// });
let loopproducts = products.filter(item => item.me === 'yes');
let mabproduct=loopproducts.map((ele)=>{
return `
<div class="content_product_item"style='border:${ele.me == 'yes' && '1px solid red'}'>
<img src="${ele.img_src}" alt="">
<div class="content_product_item_desc">
<h2 onclick="savedeatlisid(${ele.id})">${ele.title}</h2>
<p>${ele.desc}</p>
<p>${ele.size}</p>
${ele.me ==="yes"?`<h2 class='edti_product'onclick='editproduct(${ele.id})'>Edit product</h2>`:''}
<h2 id="button" onclick="deleteproduct(${ele.id})">Delete product</h2>
<i class="fa fa-heart" aria-hidden="true"></i>
</div>
</div>
`
})
content_product.innerHTML=mabproduct
}
showproducts(JSON.parse(localStorage.getItem('data_api')))
function editproduct(id) {
localStorage.setItem('editid', id)
setTimeout(() => {
window.location = 'Edit.html'
}, 500);
}
function deleteproduct(id) {
let products = JSON.parse(localStorage.getItem('data_api'));
let updated_products = products.filter(item => item.id !== id);
localStorage.setItem('data_api', JSON.stringify(updated_products));
showproducts(updated_products);
}