generated from chingu-voyages/voyage-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
71 lines (56 loc) · 2.16 KB
/
main.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
import { dishes } from './assets/arrays.js';
import { allergies } from './assets/arrays.js';
import {
generateRandomDishes,
generateWeeklyFood,
createWeekdayStructure
} from "./util.js";
//
let userAlergies = new Set();
let userPickedStartDate = 0;
const ulAlergies = document.getElementById("alergies");
//
const calendarStartDate = document.getElementById('calendarStartDatePicker');
const today = new Date();
const formattedDate = today.toISOString().split("T")[0]; // Format as YYYY-MM-DD
calendarStartDate.min = formattedDate;
calendarStartDate.addEventListener('input', function (e) {
//clickedDay is the day someone clicks on
const clickedDay = new Date(e.target.value);
//assigned Monday to index 0, Tuesday to index 1, Wednesday to index 2, Thursday to index 3, Friday to index 4, Saturday to index 5, Sunday to index 6
let weekDay = clickedDay.getDay();
let randomDishes = generateRandomDishes(userAlergies, dishes, 7);
console.log(randomDishes);
userPickedStartDate = weekDay;
generateWeeklyFood(randomDishes, userPickedStartDate);
});
allergies.forEach(allergy => {
// Create a <li> element
const li = document.createElement("li");
li.className = "allergen";
// Create the <input> checkbox
const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.className = "checkbox";
checkbox.id = allergy.toLowerCase().replace(/\s+/g, "-");
checkbox.value = allergy;
checkbox.addEventListener("click", handleCheckBoxClick);
// Create the <p> element for the allergy text
const p = document.createElement("p");
p.textContent = allergy;
// Append the checkbox and <p> to the <li>
li.appendChild(checkbox);
li.appendChild(p);
// Append the <li> to the <ul>
ulAlergies.appendChild(li);
});
function handleCheckBoxClick(event) {
let checkBoxValue = event.target.value;
if (userAlergies.has(checkBoxValue)) {
userAlergies.delete(checkBoxValue);
} else {
userAlergies.add(checkBoxValue);
}
let randomDishes = generateRandomDishes(userAlergies, dishes, 7);
generateWeeklyFood(randomDishes, userPickedStartDate);
}