forked from NITRR-Open-Source-Community/NOSC-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
past-events.js
130 lines (116 loc) · 3.92 KB
/
past-events.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
const pastEvents = [
{
title: "HactoberFest 2023 plan",
date: "2022-04-08",
category: "speaker-session",
link: "speaker-session-2022.html",
},
{
title: "Coding Fest 2022",
date: "2022-08-15",
category: "Coding Fest",
link: "coding-fest-2022.html",
},
{
title: "Hackathon Challenge",
date: "2022-06-20",
category: "Hackathon",
link: "hackathon-challenge.html",
},
{
title: "20hour coding marathon",
date: "2022-08-15",
category: "Coding Fest",
link: "coding-fest-2022.html",
},
{
title: "Hackerrank challenge",
date: "2021-08-15",
category: "coding Fest",
link: "coding-fest-2022.html",
},
{
title: "Coding Fest 2021",
date: "2021-08-15",
category: "Coding Fest",
link: "coding-fest-2022.html",
},
];
function filterEvents(category) {
const eventList = document.querySelector(".PastEvents #event-list");
eventList.innerHTML = "";
pastEvents.forEach((event) => {
if (category === "All" || event.category === category) {
const listItem = document.createElement("li");
listItem.innerHTML = `<a href="${event.link}">${event.title} (${event.date})</a>`;
eventList.appendChild(listItem);
}
});
}
const filterSelect = document.getElementById("filter");
filterSelect.addEventListener("change", () => {
filterEvents(filterSelect.value);
});
filterEvents("All");
function subscribeToEvent(eventId) {
const eventElement = document.getElementById(eventId);
const eventName = eventElement.getAttribute('data-event-name');
const eventDate = eventElement.getAttribute('data-event-date');
if (!isSubscribed(eventId)) {
var eventData = {
eventName,
eventDate,
};
var eventDataJSON = JSON.stringify(eventData);
console.log(eventDataJSON);
localStorage.setItem(eventId, eventDataJSON);
toggleButtons(eventId);
alert(`You have successfully subscribed to ${eventName}.`);
} else {
alert(`You are already subscribed to ${eventName}.`);
}
}
function unsubscribeFromEvent(eventId) {
const eventElement = document.getElementById(eventId);
const eventName = eventElement.getAttribute('data-event-name');
if (isSubscribed(eventId)) {
localStorage.removeItem(eventId);
toggleButtons(eventId);
alert(`You have successfully unsubscribed from ${eventName}.`);
} else {
alert(`You are not subscribed to ${eventName}.`);
}
}
function isSubscribed(eventName) {
return localStorage.getItem(eventName) !== null;
}
function toggleButtons(eventId) {
const eventElement = document.getElementById(eventId);
const subscribeButton = eventElement.querySelector('.subscribe-button');
const unsubscribeButton = eventElement.querySelector('.unsubscribe-button');
if (localStorage.getItem(eventId)) {
subscribeButton.style.display = "none";
unsubscribeButton.style.display = "block";
} else {
subscribeButton.style.display = "block";
unsubscribeButton.style.display = "none";
}
}
function updateButtons() {
const events = document.querySelectorAll('.event');
events.forEach((event) => {
const eventId = event.id;
const subscribeButton = event.querySelector('.subscribe-button');
const unsubscribeButton = event.querySelector('.unsubscribe-button');
if (subscribeButton && unsubscribeButton) {
if (isSubscribed(eventId)) {
subscribeButton.style.display = 'none';
unsubscribeButton.style.display = 'block';
} else {
subscribeButton.style.display = 'block';
unsubscribeButton.style.display = 'none';
}
}
});
}
window.addEventListener('load', updateButtons);