-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.js
152 lines (127 loc) · 4.12 KB
/
store.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const store = JSON.parse(localStorage.getItem("store"));
let user_info = JSON.parse(localStorage.getItem("user_info"));
const profile = document.getElementById("profile");
profile.textContent = user_info[0][0][0].toUpperCase();
let m = 0;
const cardContainer = document.getElementById("cardContainer");
let filter_time = false;
let filter_const_time = null;
let filter_cuisine = false;
let filter_const_cuisine = null;
let stored = JSON.parse(localStorage.getItem("selected"));
let recipes = [];
function display() {
function card_display() {
console.log(store[i][0]);
const card = document.createElement("div");
card.className = "card";
const mainText = document.createElement("div");
mainText.className = "main-text";
mainText.textContent = store[i][0];
const smallText = document.createElement("div");
smallText.className = "small-text";
smallText.textContent = "Time: " + store[i][2];
const smallerText = document.createElement("div");
smallerText.className = "small-text";
smallerText.textContent = "Cuisine: " + store[i][7];
const ingText = document.createElement("div");
ingText.className = "ing-text";
ingText.textContent = "Ingredients : " + store[i][1];
const img = document.createElement("img");
img.setAttribute("src", "files/" + store[i][3]);
img.className = "p";
card.appendChild(mainText);
card.appendChild(smallText);
card.appendChild(ingText);
card.appendChild(smallerText);
card.appendChild(img);
cardContainer.appendChild(card);
m++;
}
let m = 0;
for (i in store) {
let c = 0;
for (j = 0; j < stored.length; j++) {
if (store[i][1].includes(stored[j])) {
c++;
}
}
if (c > 1) {
console.log(filter_time, filter_cuisine);
if (filter_time) {
if (filter_const_time == "Less than 15 minutes") {
if (store[i][2] < 15) {
card_display();
}
} else if (filter_const_time == "15-30 minutes") {
if (store[i][2] >= 15 && store[i][2] < 30) {
card_display();
}
} else if (filter_const_time == "30-60 minutes") {
if (store[i][2] >= 30 && store[i][2] <= 60) {
card_display();
}
} else if (filter_const_time == "More than 60 minutes") {
if (store[i][2] > 60) {
card_display();
}
}
}
if (filter_cuisine) {
if (store[i][7] == filter_const_cuisine) {
card_display();
}
} else if (filter_time == false && filter_cuisine == false) {
card_display();
}
}
if (m > 2) {
const bg = document.getElementById("recipe_img");
let h = 588 + (m - 2) * 200;
bg.style.height = h.toString() + "px";
}
}
}
display();
filters = document.querySelectorAll(".a");
filters.forEach((filter) => {
filter.addEventListener("click", () => {
filter_time = true;
filter_const_time = filter.innerHTML;
cardContainer.innerHTML = "";
display();
cards = document.querySelectorAll(".card");
cards.forEach((card) => {
card.addEventListener("click", () => {
sub_card = card.querySelector(".main-text");
localStorage.setItem("recipe", JSON.stringify(sub_card.innerHTML));
location.href = "detail.html";
});
});
});
});
filters2 = document.querySelectorAll(".c");
filters2.forEach((filter2) => {
filter2.addEventListener("click", () => {
filter_cuisine = true;
filter_const_cuisine = filter2.innerHTML;
cardContainer.innerHTML = "";
display();
cards = document.querySelectorAll(".card");
cards.forEach((card) => {
card.addEventListener("click", () => {
sub_card = card.querySelector(".main-text");
localStorage.setItem("recipe", JSON.stringify(sub_card.innerHTML));
location.href = "detail.html";
});
});
});
});
cards = document.querySelectorAll(".card");
cards.forEach((card) => {
card.addEventListener("click", () => {
sub_card = card.querySelector(".main-text");
localStorage.setItem("recipe", JSON.stringify(sub_card.innerHTML));
location.href = "detail.html";
});
});