Add login, save and invite features

This commit is contained in:
thoenykaroli committed 2026-04-10 22:50:25 +02:00
1 parent 66c51e9238
commit 3208977b9a
7 files changed
+422 -15

No files matched your search

+77
View File
@@ -33,5 +33,82 @@ export function createEventCard(event) {
article.append(title, date, venue);
// =========================
// BUTTON CONTAINER
// =========================
const buttonContainer = document.createElement("div");
buttonContainer.className = "d-flex gap-2 mt-2";
// =========================
// SAVE BUTTON
// =========================
const saveBtn = document.createElement("button");
saveBtn.textContent = "Save";
saveBtn.className = "btn btn-outline-primary btn-sm";
saveBtn.addEventListener("click", () => {
if (!window.currentUser) {
alert("Please login to save events");
return;
}
const saved = JSON.parse(localStorage.getItem("savedEvents") || "[]");
// prevent duplicates
if (saved.find(e => e.id === event.id)) {
alert("Event already saved");
return;
}
saved.push(event);
localStorage.setItem("savedEvents", JSON.stringify(saved));
alert("Event saved!");
});
saveBtn.disabled = !window.currentUser;
// =========================
// INVITE BUTTON
// =========================
const inviteBtn = document.createElement("button");
inviteBtn.textContent = "Invite";
inviteBtn.className = "btn btn-primary btn-sm";
inviteBtn.addEventListener("click", async () => {
if (!window.currentUser) {
alert("Please login to invite users");
return;
}
const toUser = prompt("Enter username to invite:");
if (!toUser) return;
await fetch("http://localhost:3000/api/invitation", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Username": window.currentUser
},
body: JSON.stringify({
toUser,
eventId: event.id,
eventName: event.name
})
});
alert("Invitation sent!");
});
inviteBtn.disabled = !window.currentUser;
// =========================
// APPEND BUTTONS
// =========================
buttonContainer.append(saveBtn, inviteBtn);
article.appendChild(buttonContainer);
return article;
}