-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
124 lines (101 loc) · 3.78 KB
/
Copy pathindex.js
File metadata and controls
124 lines (101 loc) · 3.78 KB
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
let nameButton = document.getElementById("addButton")
displayMeetings()
// On add button click
nameButton.addEventListener("click", function (e) {
let nameInput = document.getElementById("nameInput")
let linkInput = document.getElementById("linkInput")
let noteInput = document.getElementById("noteInput")
// Fetch the meeting name from local
let meetingName = localStorage.getItem("meetingName")
// In case it doesn't exist
if (meetingName === null) {
meetingNameArray = []
} else {
// Else, assign the input to meetingNameArray
meetingNameArray = JSON.parse(meetingName)
}
let meetingNameLinkNote = {
name: nameInput.value,
link: linkInput.value,
note: noteInput.value
}
// Push the input name value to meetingNameArray
meetingNameArray.push(meetingNameLinkNote)
console.log(nameInput.value)
// Set it in local storage in string format
localStorage.setItem("meetingName", JSON.stringify(meetingNameArray))
// Clear the input fields
nameInput.value = ""
linkInput.value = ""
noteInput.value = ""
console.log(meetingNameArray + " = meetingNameArray")
console.log(localStorage)
displayMeetings()
})
// To show notes in cards in the app
function displayMeetings() {
// Fetch the meeting name from local
let meetingName = localStorage.getItem("meetingName")
// In case it doesn't exist
if (meetingName === null) {
meetingNameArray = []
} else {
// Else, assign the input to meetingNameArray
meetingNameArray = JSON.parse(meetingName)
}
// Empty at first
let cardHTML = ""
meetingNameArray.forEach(function (element, index) {
cardHTML += `
<div class="cards">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">${element.name}</h5>
<p class="card-text">${element.note}</p>
<div id="launchMeeting"><a href="${element.link}" class="btn btn-outline-primary">Launch Meeting</a></div>
<div id="showLink"></div>
<button id="${index}" onclick="deleteMeeting(this.id)" class="btn btn-outline-danger">Delete</button>
<p class="card-text"><small class="text-muted-custom">${element.link}</small></p>
</div>
</div>
</div>
`
})
let meetingNameElem = document.getElementById("meetings")
// If meetings exist
if (meetingNameArray.length != 0) {
meetingNameElem.innerHTML = cardHTML
}
// If there are no meetings
else {
meetingNameElem.innerHTML = `<div id="centre">You have no meetings. Add a meeting from above!</div>`
}
}
// Deleting a meeting
function deleteMeeting(index) {
console.log("Deleting meeting with index: " + index)
let meetingName = localStorage.getItem("meetingName")
// In case it doesn't exist
if (meetingName === null) {
meetingNameArray = []
} else {
// Else, assign the input to meetingNameArray
meetingNameArray = JSON.parse(meetingName)
}
// Delete one meeting with the given index
meetingNameArray.splice(index, 1)
// Refresh the local storage
localStorage.setItem("meetingName", JSON.stringify(meetingNameArray))
// Refresh and display the notes again
displayMeetings()
}
function darkModeToggle(){
document.getElementById('mainBody').classList.toggle("dark-theme");
document.getElementById('mainWindow').classList.toggle("border-dark");
var btn = document.querySelector('.dark-theme-btn');
if(document.querySelector('body').classList.contains('dark-theme')){
btn.innerHTML = 'Light Mode';
}else {
btn.innerHTML = 'Dark Mode';
}
}