11 Commits

Author SHA1 Message Date
8837c4c09e fix #2 2025-06-02 14:08:07 +02:00
e20347d8fa fix: org buttons 2025-06-02 13:58:46 +02:00
AleksDw
3aabcd831e Add log in / log off to messages page 2025-06-02 13:41:46 +02:00
AleksDw
f5d7637d2f Merge branch 'master' of https://github.com/GCMatters/hermes 2025-06-02 13:39:26 +02:00
AleksDw
0b27a0f91c Add log in / log off in calendar 2025-06-02 13:38:58 +02:00
Witkopawel
fd6c4dfb11 messages
messages
2025-06-02 13:34:32 +02:00
a4cea4eeb3 chore: small visual fixes 2025-06-02 08:09:56 +02:00
b8990be51e chore: translate strings into english 2025-06-02 07:53:33 +02:00
9dbbb7690d Merge branch 'calendar' 2025-06-02 07:50:11 +02:00
Witkopawel
a8d706bf97 Calendar
Calendar that show all events that we joined
2025-06-02 07:11:30 +02:00
80ad9db83d feat: front-end date ranges support 2025-06-02 07:10:08 +02:00
23 changed files with 908 additions and 164 deletions

View File

@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.EntityFrameworkCore;
using System.Security.Cryptography;
@@ -128,7 +128,26 @@ namespace WebApp.Endpoints
return Results.Json(new { success = true });
});
group.MapGet("/registered",
async (ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
{
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
User? user = await guhf.GetUserFromToken(token);
if (user is null || user.IsOrganisation)
return Results.Json(new { success = false, error_msg = "Unauthorized or organisations cannot register." });
var events = await dbContext.EventRegistrations
.Where(r => r.UserId == user.UserId)
.Select(r => new {
r.Event.EventId,
r.Event.Title,
r.Event.EventDate
})
.ToListAsync();
return Results.Json(events);
});
return group;
}
}

View File

@@ -0,0 +1,113 @@
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using WebApp.Data;
using WebApp.Entities;
using System.Linq;
namespace WebApp.Endpoints
{
public static class MessagesEndpoints
{
public static RouteGroupBuilder MapMessagesEndpoints(this WebApplication app)
{
Console.WriteLine("Registering MessagesEndpoints...");
var group = app.MapGroup("api/messages");
// Test endpoint to verify registration
group.MapGet("/test", () => Results.Ok("Messages endpoint is working"));
// POST /api/messages/sendFromOrgToVolunteers
group.MapPost("/sendFromOrgToVolunteers",
async (SendMessageRequest request, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
{
Console.WriteLine("Hit sendFromOrgToVolunteers endpoint.");
// Get token and organization
var token = await guhf.GetTokenFromHTTPContext(httpContext);
var org = await guhf.GetOrganisationFromToken(token);
if (org == null)
return Results.Unauthorized();
// Verify event belongs to org
var ev = await dbContext.Events.FindAsync(request.EventId);
if (ev == null || ev.OrganisationId != org.OrganisationId)
return Results.BadRequest("Event not found or unauthorized.");
// Get all volunteers (non-org users)
var volunteers = await dbContext.WebUsers
.Where(u => !u.IsOrganisation)
.ToListAsync();
// Create message entities
var messages = volunteers.Select(v => new Message
{
EventType = request.EventId,
VolunteerId = v.UserId,
OrganizationId = org.OrganisationId,
IsMsgFromVolunteer = false,
IsoDate = DateTime.UtcNow,
Content = request.Content
}).ToList();
dbContext.Messages.AddRange(messages);
await dbContext.SaveChangesAsync();
return Results.Ok();
});
// GET /api/messages/my - get messages for current user
group.MapGet("/my",
async (ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
{
var token = await guhf.GetTokenFromHTTPContext(httpContext);
var user = await guhf.GetUserFromToken(token);
if (user == null)
return Results.Unauthorized();
var messages = await dbContext.Messages
.Where(m =>
(user.IsOrganisation && m.OrganizationId == user.UserId) ||
(!user.IsOrganisation && m.VolunteerId == user.UserId))
.OrderByDescending(m => m.IsoDate)
.ToListAsync();
return Results.Ok(messages);
});
// DELETE /api/messages/{id}
group.MapDelete("/{id:int}", async (int id, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
{
var token = await guhf.GetTokenFromHTTPContext(httpContext);
var user = await guhf.GetUserFromToken(token);
if (user == null)
return Results.Unauthorized();
var message = await dbContext.Messages.FindAsync(id);
if (message == null)
return Results.NotFound();
// Only allow deleting if user is either the organization or volunteer in the message
if (user.IsOrganisation && message.OrganizationId != user.UserId)
return Results.Forbid();
if (!user.IsOrganisation && message.VolunteerId != user.UserId)
return Results.Forbid();
dbContext.Messages.Remove(message);
await dbContext.SaveChangesAsync();
return Results.NoContent();
});
return group;
}
}
public class SendMessageRequest
{
public int EventId { get; set; }
public string Content { get; set; }
}
}

View File

@@ -55,5 +55,6 @@ app.MapOrganizationsEndpoints();
app.MapAuthEndpoints();
app.MapSkillsEndpoints();
app.MapEventsRegistrationEndpoints();
app.MapMessagesEndpoints();
app.Run();

53
WebApp/ts/calendar.ts Normal file
View File

@@ -0,0 +1,53 @@
import { unhideElementById, getMyAccount } from './generalUseHelpers.js';
async function getRegisteredEvents(): Promise<any[]> {
const res = await fetch("/api/events/registered");
if (!res.ok) throw new Error("Couldn't load joined events");
const data = await res.json();
return data.map((ev: any) => ({
title: ev.title,
start: ev.eventDate,
url: `/view.html?event=${ev.eventId}`
}));
}
document.addEventListener("DOMContentLoaded", async () => {
try {
var user = await getMyAccount();
if (user) {
unhideElementById(document, "logout-btn");
}
} catch {
unhideElementById(document, "joinnow-btn");
unhideElementById(document, "signin-btn");
}
const calendarEl = document.getElementById("calendar") as HTMLElement;
if (!calendarEl) return;
const events = await getRegisteredEvents();
const calendar = new (window as any).FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,listWeek'
},
themeSystem: 'bootstrap5',
events: events,
eventClick: function (info: any) {
if (info.event.url) {
window.location.href = info.event.url;
info.jsEvent.preventDefault();
}
}
});
calendar.render();
});

View File

@@ -1,61 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
console.log("TypeScript działa!");
function createEvent() {
return __awaiter(this, void 0, void 0, function* () {
// Pobieranie danych z formularza
const title = document.getElementById('title').value;
const location = document.getElementById('location').value;
const description = document.getElementById('description').value;
const eventDateRaw = document.getElementById('eventDate').value;
const organisationIdRaw = document.getElementById('organisationId').value;
// Walidacja prostych pól
if (!title || !location || !eventDateRaw || !organisationIdRaw) {
alert("Uzupełnij wszystkie wymagane pola!");
return;
}
const eventDate = new Date(eventDateRaw).toISOString();
const organisationId = parseInt(organisationIdRaw);
const payload = {
title,
location,
description,
eventDate,
organisationId
};
try {
const response = yield fetch('/api/events', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (!response.ok) {
const errorText = yield response.text();
throw new Error(errorText);
}
alert("Wydarzenie zostało utworzone!");
window.location.href = "/"; // Przekierowanie do strony głównej
}
catch (error) {
console.error("Błąd podczas tworzenia:", error);
alert("Nie udało się utworzyć wydarzenia: " + error);
}
});
}
document.addEventListener("DOMContentLoaded", () => {
const saveBtn = document.getElementById("saveBtn");
if (saveBtn) {
saveBtn.addEventListener("click", (e) => {
e.preventDefault();
createEvent();
});
}
});

View File

@@ -1,40 +1,91 @@
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
import { getEvent, getMyAccount, unhideElementById, hideElementById } from './generalUseHelpers.js';
var isAscending: boolean = false;
var optionsVisibility: boolean = false;
function toggleListSortOrder(org_id: number) {
isAscending = !isAscending;
loadEvents(org_id);
}
function toggleOptionsVisibility() {
optionsVisibility = !optionsVisibility;
if (optionsVisibility) {
unhideElementById(document, "fDate");
unhideElementById(document, "tDate");
unhideElementById(document, "flabel");
unhideElementById(document, "tlabel");
} else {
hideElementById(document, "fDate");
hideElementById(document, "tDate");
hideElementById(document, "flabel");
hideElementById(document, "tlabel");
}
}
async function getEvents(titleOrDescription?: string, fDate?: Date, tDate?: Date) {
var res: Response;
var searchbar = document.getElementById("searchbar") as HTMLInputElement;
var eventDateFrom = (document.getElementById('fDate') as HTMLInputElement).value;
var eventDateTo = (document.getElementById('tDate') as HTMLInputElement).value;
if (titleOrDescription == null) {
titleOrDescription = searchbar.value;
//res = await fetch("/api/events" + (isAscending ? "?sort=asc" : ""));
//if (!res.ok) throw new Error("Couldn't load events");
}
var payload = {
if (optionsVisibility) {
var payload_visible = {
titleOrDescription,
fDate,
tDate
eventDateFrom,
eventDateTo
};
res = await fetch('/api/events/search' + (isAscending ? "?sort=asc" : ""), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
body: JSON.stringify(payload_visible)
});
if (!res.ok) throw new Error("Failed to get search results");
} else {
var payload_invisible = {
titleOrDescription
};
res = await fetch('/api/events/search' + (isAscending ? "?sort=asc" : ""), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload_invisible)
});
if (!res.ok) throw new Error("Failed to get search results");
}
const events = await res.json();
return events;
}
async function sendMessageForEvent(eventId: number) {
const messageContent = `Help me with <a href="/view.html?event=${eventId}">this event</a>`;
try {
const response = await fetch('/api/messages/sendFromOrgToVolunteers', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ eventId, content: messageContent })
});
if (response.ok) {
alert('Message sent successfully to all volunteers!');
} else {
let error = await response.text();
if (!error) error = `Status code: ${response.status}`;
alert('Failed to send message: ' + error);
console.error('Send message failed', response.status, error);
}
} catch (error) {
alert('Error sending message: ' + error);
console.error('Fetch error:', error);
}
}
async function loadEvents(org_id: number, evs?: Promise<any>) {
const container = document.getElementById("eventList");
if (!container) return;
@@ -53,39 +104,58 @@ async function loadEvents(org_id: number, evs?: Promise<any>) {
return;
}
// Wyczyść kontener przed dodaniem nowych
container.innerHTML = '';
const styleDefault = "color: #2898BD";
const styleHighlighted = "#2393BD";
for (const ev of events) {
const card = document.createElement("div");
card.className = "event-card filled";
let formattedDate: string = new Intl.DateTimeFormat('en-US', {
weekday: 'long', // "Monday"
year: 'numeric', // "2023"
month: 'long', // "December"
day: 'numeric' // "1"
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
}).format(new Date(ev.eventDate));
card.innerHTML = `
<span>
<a href="/view.html?event=${ev.eventId}" style="color: #2898BD">${ev.title}</a>
<p style="margin: 0">👥 ${ev.organisation} | 📍 ${ev.location} | 📅 ${formattedDate}</p>
</span>`
const eventInfoSpan = document.createElement("span");
eventInfoSpan.innerHTML = `
<a href="/view.html?event=${ev.eventId}" style="color: #2898BD">${ev.title}</a>
<p style="margin: 0">👥 ${ev.organisation} | 📍 ${ev.location} | 📅 ${formattedDate}</p>
`;
card.appendChild(eventInfoSpan);
if (org_id == ev.organisationId) {
card.innerHTML += `
<div>
<button class="edit-btn mod-btn" data-id="${ev.eventId}" id="edit-btn">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path d="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z"/></svg>
</button>
<button class="remove-btn mod-btn" data-id="${ev.eventId}" id="remove-btn">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M280-440h400v-80H280v80ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>
</button>
</div>`;
const buttonsDiv = document.createElement("div");
buttonsDiv.className = "d-flex gap-2 mt-2";
const editBtn = document.createElement("button");
editBtn.className = "edit-btn mod-btn";
editBtn.id = "edit-btn";
editBtn.setAttribute("data-id", ev.eventId);
editBtn.title = "Edit event";
editBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path d="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z"/></svg>`;
const removeBtn = document.createElement("button");
removeBtn.className = "remove-btn mod-btn";
removeBtn.id = "remove-btn";
removeBtn.setAttribute("data-id", ev.eventId);
removeBtn.title = "Remove event";
removeBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M280-440h400v-80H280v80ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>`;
const sendMsgBtn = document.createElement("button");
sendMsgBtn.className = "btn btn-sm btn-info";
sendMsgBtn.textContent = "Send Message";
sendMsgBtn.setAttribute("data-id", ev.eventId);
sendMsgBtn.title = "Send message about this event";
sendMsgBtn.addEventListener("click", async () => {
await sendMessageForEvent(ev.eventId);
});
buttonsDiv.appendChild(editBtn);
buttonsDiv.appendChild(removeBtn);
buttonsDiv.appendChild(sendMsgBtn);
card.appendChild(buttonsDiv);
}
container.appendChild(card);
@@ -112,24 +182,27 @@ document.addEventListener("DOMContentLoaded", async () => {
unhideElementById(document, "logout-btn");
}
} catch {
// console.log("User not signed in. Failing gracefully.");
unhideElementById(document, "joinnow-btn");
unhideElementById(document, "signin-btn");
}
loadEvents(org_id);
// listen for clicks
const listSortToggleButton = document.getElementById("list-sort-btn");
if (listSortToggleButton) {
listSortToggleButton.addEventListener("click", () => toggleListSortOrder(org_id));
}
// and for enter in search bar
const optionsToggleButton = document.getElementById("optionsbtn");
if (optionsToggleButton) {
optionsToggleButton.addEventListener("click", () => toggleOptionsVisibility());
}
const searchBar = document.getElementById('searchbar') as HTMLInputElement;
searchBar.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
// console.log('Enter key pressed!');
var searchResults = getEvents(searchBar.value);
loadEvents(org_id, searchResults);
}
})
});
});

View File

@@ -25,6 +25,13 @@ export async function unhideElementById(document: Document, e: string) {
}
}
export async function hideElementById(document: Document, e: string) {
var element = document.getElementById(e);
if (element) {
element.classList.add('hidden-before-load');
}
}
export async function getEvent(id: string): Promise<EventData> {
const res = await fetch("/api/events/" + id);
if (!res.ok) {

View File

@@ -35,4 +35,4 @@ document.addEventListener("DOMContentLoaded", () => {
console.error(error);
}
});
});
});

103
WebApp/ts/messages.ts Normal file
View File

@@ -0,0 +1,103 @@
import { getMyAccount, unhideElementById } from './generalUseHelpers.js';
// messages.ts
async function getMyMessages() {
const res = await fetch('/api/messages/my', {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
});
if (!res.ok) throw new Error('Failed to load messages');
return await res.json();
}
function formatDate(dateStr: string): string {
const date = new Date(dateStr);
return date.toLocaleString(undefined, {
year: 'numeric', month: 'short', day: 'numeric',
hour: '2-digit', minute: '2-digit'
});
}
function createMessageCard(msg: any) {
const card = document.createElement('div');
card.className = 'messages-card';
const sender = msg.isMsgFromVolunteer
? `Volunteer #${msg.volunteerId}`
: `Organization #${msg.organizationId}`;
// Safely inject content as HTML because it contains links
const contentHtml = msg.content ?? '';
card.innerHTML = `
<button class="delete-btn" title="Delete message" data-id="${msg.messageId}">&times;</button>
<div class="message-header">${sender}</div>
<div class="message-date">${formatDate(msg.isoDate)}</div>
<div class="message-content">${contentHtml}</div>
<small><em>Regarding Event #${msg.eventType}</em></small>
`;
return card;
}
async function deleteMessage(messageId: number) {
if (!confirm('Are you sure you want to delete this message?')) return;
const res = await fetch(`/api/messages/${messageId}`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' }
});
if (!res.ok) {
alert('Failed to delete message.');
return;
}
// Reload messages after delete
loadMessages();
}
async function loadMessages() {
const container = document.getElementById('messagesContainer');
if (!container) return;
try {
const messages = await getMyMessages();
container.innerHTML = '';
if (messages.length === 0) {
container.innerHTML = `<p class="no-messages">No messages to display.</p>`;
return;
}
messages.forEach((msg: any) => {
const card = createMessageCard(msg);
container.appendChild(card);
});
// Attach delete handlers
container.querySelectorAll('.delete-btn').forEach(btn => {
btn.addEventListener('click', () => {
const idStr = btn.getAttribute('data-id');
if (idStr) deleteMessage(parseInt(idStr));
});
});
} catch (err) {
container.innerHTML = `<p class="no-messages text-danger">Failed to load messages.</p>`;
console.error(err);
}
}
document.addEventListener('DOMContentLoaded', async () => {
try {
var user = await getMyAccount();
if (user) {
unhideElementById(document, "logout-btn");
}
} catch {
unhideElementById(document, "joinnow-btn");
unhideElementById(document, "signin-btn");
}
loadMessages();
});

View File

@@ -1,10 +1,10 @@
import { getEvent, getMyAccount, unhideElementById, getMyRegisteredEventIds } from './generalUseHelpers.js';
var redirected = false;
var redirected = false;
document.addEventListener("DOMContentLoaded", async () => {
var container = document.getElementById("mainContainer");
var container = document.getElementById("mainContainer");
const modifyBtn = document.getElementById("editBtn");
const removeBtn = document.getElementById("removeBtn");
const applyBtn = document.getElementById("applyBtn");
@@ -28,7 +28,7 @@ document.addEventListener("DOMContentLoaded", async () => {
} else {
unhideElementById(document, "orgno");
}
} catch {
} catch (e) {
window.location.href = "login.html";
}
@@ -40,15 +40,15 @@ document.addEventListener("DOMContentLoaded", async () => {
if (container !== null) container.innerHTML = `<p class="text-danger">Błąd we wczytywaniu wydarzenia. <a href="/" style="color:#2898BD;">Powrót -></a></p>`;
} else {
const nameText = document.getElementById("nameText") as HTMLElement;
const orgnameText = document.getElementById( "orgname") as HTMLElement;
const dateText = document.getElementById("dateText") as HTMLElement;
const nameText = document.getElementById("nameText") as HTMLElement;
const orgnameText = document.getElementById("orgname") as HTMLElement;
const dateText = document.getElementById("dateText") as HTMLElement;
const newdateText = new Date(thisAccount.createdAt).toLocaleDateString('pl-PL');
const newtimeText = new Date(thisAccount.createdAt).toLocaleTimeString('pl-PL');
nameText.innerHTML = thisAccount.firstName + " " + thisAccount.lastName + " (" + thisAccount.email + ")";
dateText.innerHTML = "📅 Account creation date: " + newdateText + " " + newtimeText;
nameText.innerHTML = thisAccount.firstName + " " + thisAccount.lastName + " (" + thisAccount.email + ")";
dateText.innerHTML = "📅 Account creation date: " + newdateText + " " + newtimeText;
orgnameText.innerHTML = "👥 Organization: " + org_name;
if (org_id == -1) {
@@ -57,10 +57,10 @@ document.addEventListener("DOMContentLoaded", async () => {
// Użytkownik jest wolontariuszem
try {
const registeredIds = await getMyRegisteredEventIds();
} catch {
} catch (e) {
}
}
unhideElementById(document, "mainContainer");
@@ -75,9 +75,9 @@ window.onload = () => {
dropdown.addEventListener('change', () => {
const skillName = dropdown.options[dropdown.selectedIndex].text;
const skillId = dropdown.options[dropdown.selectedIndex].value;
const skillId = dropdown.options[dropdown.selectedIndex].value;
if (skillName) {
addSkill(skillName, skillId, false);
addSkill(skillName, Number(skillId), false);
dropdown.value = ''; // Reset dropdown
}
});

View File

@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8" />
<title>Event calendar</title>
<!-- Styles -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
<link href="/css/panel.css" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.8/index.global.min.css" rel="stylesheet" />
</head>
<body class="bg-light">
<div class="d-flex">
<!-- Sidebar -->
<div class="sidebar">
<nav class="sidebar d-flex flex-column align-items-center pt-3">
<div class="icon-box my-2">
<a href="index.html" class="nav-link text-info mb-3">
<!-- Home icon -->
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M240-200h120v-240h240v240h120v-360L480-740 240-560v360Zm-80 80v-480l320-240 320 240v480H520v-240h-80v240H160Zm320-350Z" /></svg>
<br /><h8 class="iconText">Home</h8>
</a>
</div>
<div class="icon-box my-2">
<a href="messages.html" class="nav-link text-info mb-3">
<!-- Chats icon -->
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M880-80 720-240H320q-33 0-56.5-23.5T240-320v-40h440q33 0 56.5-23.5T760-440v-280h40q33 0 56.5 23.5T880-640v560ZM160-473l47-47h393v-280H160v327ZM80-280v-520q0-33 23.5-56.5T160-880h440q33 0 56.5 23.5T680-800v280q0 33-23.5 56.5T600-440H240L80-280Zm80-240v-280 280Z" /></svg>
<br /><h8 class="iconText">Chats</h8>
</a>
</div>
<div class="icon-box my-2">
<a href="calendar.html" class="nav-link text-info mb-3">
<!-- Calendar icon -->
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Z" /></svg>
<br /><h8 class="iconText">Calendar</h8>
</a>
</div>
<div class="icon-box mt-auto mb-4">
<a href="user.html" class="nav-link text-info mb-3">
<!-- Settings icon -->
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="m370-80-16-128q-13-5-24.5-12T307-235l-119 50L78-375l103-78q-1-7-1-13.5v-27q0-6.5 1-13.5L78-585l110-190 119 50q11-8 23-15t24-12l16-128h220l16 128q13 5 24.5 12t22.5 15l119-50 110 190-103 78q1 7 1 13.5v27q0 6.5-2 13.5l103 78-110 190-118-50q-11 8-23 15t-24 12L590-80H370Zm70-80h79l14-106q31-8 57.5-23.5T639-327l99 41 39-68-86-65q5-14 7-29.5t2-31.5q0-16-2-31.5t-7-29.5l86-65-39-68-99 42q-22-23-48.5-38.5T533-694l-13-106h-79l-14 106q-31 8-57.5 23.5T321-633l-99-41-39 68 86 64q-5 15-7 30t-2 32q0 16 2 31t7 30l-86 65 39 68 99-42q22 23 48.5 38.5T427-266l13 106Zm42-180q58 0 99-41t41-99q0-58-41-99t-99-41q-59 0-99.5 41T342-480q0 58 40.5 99t99.5 41Zm-2-140Z" /></svg>
<br /><h8 class="iconText">Settings</h8>
</a>
</div>
</nav>
</div>
<!-- Top Nav -->
<div class="topnav d-flex justify-content-between align-items-center shadow">
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
<div>
<button class="button-join hidden-before-load" id="joinnow-btn">Join now</button>
<button class="button-sign hidden-before-load" id="signin-btn">Sign In</button>
<button class="button-sign hidden-before-load" id="logout-btn">Log out</button>
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
</div>
</div>
<!-- Main Content -->
<div class="main p-4">
<div class="events-card bg-white p-4 rounded-4 shadow position-relative">
<div class="d-flex justify-content-between align-items-center mb-3">
<h2 class="eventsText">My calendar</h2>
</div>
<div id="calendar"></div>
</div>
</div>
</div>
<!-- Scripts -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.8/index.global.min.js"></script>
<script type="module" src="/js/calendar.js"></script>
<script type="module" src="js/auth.js"></script>
</body>
</html>

View File

@@ -25,13 +25,13 @@
</a>
</div>
<div class="icon-box my-2">
<a href="#" class="nav-link text-info mb-3">
<a href="messages.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M880-80 720-240H320q-33 0-56.5-23.5T240-320v-40h440q33 0 56.5-23.5T760-440v-280h40q33 0 56.5 23.5T880-640v560ZM160-473l47-47h393v-280H160v327ZM80-280v-520q0-33 23.5-56.5T160-880h440q33 0 56.5 23.5T680-800v280q0 33-23.5 56.5T600-440H240L80-280Zm80-240v-280 280Z" /></svg>
<br /><h8 class="iconText">Chats</h8>
</a>
</div>
<div class="icon-box my-2">
<a href="#" class="nav-link text-info mb-3">
<a href="calendar.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z" /></svg>
<br /><h8 class="iconText">Calendar</h8>
</a>

View File

@@ -22,13 +22,13 @@
</a>
</div>
<div class="icon-box my-2">
<a href="#" class="nav-link text-info mb-3">
<a href="messages.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M880-80 720-240H320q-33 0-56.5-23.5T240-320v-40h440q33 0 56.5-23.5T760-440v-280h40q33 0 56.5 23.5T880-640v560ZM160-473l47-47h393v-280H160v327ZM80-280v-520q0-33 23.5-56.5T160-880h440q33 0 56.5 23.5T680-800v280q0 33-23.5 56.5T600-440H240L80-280Zm80-240v-280 280Z" /></svg>
<br /><h8 class="iconText">Chats</h8>
</a>
</div>
<div class="icon-box my-2">
<a href="#" class="nav-link text-info mb-3">
<a href="calendar.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z" /></svg>
<br /><h8 class="iconText">Calendar</h8>
</a>
@@ -69,7 +69,11 @@
<div class="d-flex justify-content-between align-items-center mb-3">
<h2 class="eventsText">Events</h2>
<span class="position-absolute end-0 translate-middle-y me-4" style="margin-top: 20px;">
<button class="btn btn-link" onclick="">
<label for="fDate" id="flabel" class="hidden-before-load">From </label>
<input type="date" id="fDate" name="fDate" class="hidden-before-load">
<label for="tDate" id="tlabel" class="hidden-before-load"> To </label>
<input type="date" id="tDate" name="tDate" class="hidden-before-load">
<button class="btn btn-link" onclick="" id="optionsbtn">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M440-120v-240h80v80h320v80H520v80h-80Zm-320-80v-80h240v80H120Zm160-160v-80H120v-80h160v-80h80v240h-80Zm160-80v-80h400v80H440Zm160-160v-240h80v80h160v80H680v80h-80Zm-480-80v-80h400v80H120Z" /></svg>
</button>
<button class="btn btn-link" id="list-sort-btn" onclick=""><svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M320-440v-287L217-624l-57-56 200-200 200 200-57 56-103-103v287h-80ZM600-80 400-280l57-56 103 103v-287h80v287l103-103 57 56L600-80Z" /></svg></button>

View File

@@ -0,0 +1,56 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { unhideElementById, getMyAccount } from './generalUseHelpers.js';
function getRegisteredEvents() {
return __awaiter(this, void 0, void 0, function* () {
const res = yield fetch("/api/events/registered");
if (!res.ok)
throw new Error("Couldn't load joined events");
const data = yield res.json();
return data.map((ev) => ({
title: ev.title,
start: ev.eventDate,
url: `/view.html?event=${ev.eventId}`
}));
});
}
document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, void 0, function* () {
try {
var user = yield getMyAccount();
if (user) {
unhideElementById(document, "logout-btn");
}
}
catch (_a) {
unhideElementById(document, "joinnow-btn");
unhideElementById(document, "signin-btn");
}
const calendarEl = document.getElementById("calendar");
if (!calendarEl)
return;
const events = yield getRegisteredEvents();
const calendar = new window.FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,listWeek'
},
themeSystem: 'bootstrap5',
events: events,
eventClick: function (info) {
if (info.event.url) {
window.location.href = info.event.url;
info.jsEvent.preventDefault();
}
}
});
calendar.render();
}));

View File

@@ -7,37 +7,93 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { getMyAccount, unhideElementById } from './generalUseHelpers.js';
import { getMyAccount, unhideElementById, hideElementById } from './generalUseHelpers.js';
var isAscending = false;
var optionsVisibility = false;
function toggleListSortOrder(org_id) {
isAscending = !isAscending;
loadEvents(org_id);
}
function toggleOptionsVisibility() {
optionsVisibility = !optionsVisibility;
if (optionsVisibility) {
unhideElementById(document, "fDate");
unhideElementById(document, "tDate");
unhideElementById(document, "flabel");
unhideElementById(document, "tlabel");
}
else {
hideElementById(document, "fDate");
hideElementById(document, "tDate");
hideElementById(document, "flabel");
hideElementById(document, "tlabel");
}
}
function getEvents(titleOrDescription, fDate, tDate) {
return __awaiter(this, void 0, void 0, function* () {
var res;
var searchbar = document.getElementById("searchbar");
var eventDateFrom = document.getElementById('fDate').value;
var eventDateTo = document.getElementById('tDate').value;
if (titleOrDescription == null) {
titleOrDescription = searchbar.value;
//res = await fetch("/api/events" + (isAscending ? "?sort=asc" : ""));
//if (!res.ok) throw new Error("Couldn't load events");
}
var payload = {
titleOrDescription,
fDate,
tDate
};
res = yield fetch('/api/events/search' + (isAscending ? "?sort=asc" : ""), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (!res.ok)
throw new Error("Failed to get search results");
if (optionsVisibility) {
var payload_visible = {
titleOrDescription,
eventDateFrom,
eventDateTo
};
res = yield fetch('/api/events/search' + (isAscending ? "?sort=asc" : ""), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload_visible)
});
if (!res.ok)
throw new Error("Failed to get search results");
}
else {
var payload_invisible = {
titleOrDescription
};
res = yield fetch('/api/events/search' + (isAscending ? "?sort=asc" : ""), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload_invisible)
});
if (!res.ok)
throw new Error("Failed to get search results");
}
const events = yield res.json();
return events;
});
}
function sendMessageForEvent(eventId) {
return __awaiter(this, void 0, void 0, function* () {
const messageContent = `Help me with <a href="/view.html?event=${eventId}">this event</a>`;
try {
const response = yield fetch('/api/messages/sendFromOrgToVolunteers', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ eventId, content: messageContent })
});
if (response.ok) {
alert('Message sent successfully to all volunteers!');
}
else {
let error = yield response.text();
if (!error)
error = `Status code: ${response.status}`;
alert('Failed to send message: ' + error);
console.error('Send message failed', response.status, error);
}
}
catch (error) {
alert('Error sending message: ' + error);
console.error('Fetch error:', error);
}
});
}
function loadEvents(org_id, evs) {
return __awaiter(this, void 0, void 0, function* () {
const container = document.getElementById("eventList");
@@ -55,10 +111,7 @@ function loadEvents(org_id, evs) {
container.innerHTML = "<p class='text-muted'>No events to display at this moment.</p>";
return;
}
// Wyczyść kontener przed dodaniem nowych
container.innerHTML = '';
const styleDefault = "color: #2898BD";
const styleHighlighted = "#2393BD";
for (const ev of events) {
const card = document.createElement("div");
card.className = "event-card filled";
@@ -66,23 +119,41 @@ function loadEvents(org_id, evs) {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric' // "1"
day: 'numeric'
}).format(new Date(ev.eventDate));
card.innerHTML = `
<span>
<a href="/view.html?event=${ev.eventId}" style="color: #2898BD">${ev.title}</a>
<p style="margin: 0">👥 ${ev.organisation} | 📍 ${ev.location} | 📅 ${formattedDate}</p>
</span>`;
const eventInfoSpan = document.createElement("span");
eventInfoSpan.innerHTML = `
<a href="/view.html?event=${ev.eventId}" style="color: #2898BD">${ev.title}</a>
<p style="margin: 0">👥 ${ev.organisation} | 📍 ${ev.location} | 📅 ${formattedDate}</p>
`;
card.appendChild(eventInfoSpan);
if (org_id == ev.organisationId) {
card.innerHTML += `
<div>
<button class="edit-btn mod-btn" data-id="${ev.eventId}" id="edit-btn">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path d="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z"/></svg>
</button>
<button class="remove-btn mod-btn" data-id="${ev.eventId}" id="remove-btn">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M280-440h400v-80H280v80ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>
</button>
</div>`;
const buttonsDiv = document.createElement("div");
buttonsDiv.className = "d-flex gap-2 mt-2";
const editBtn = document.createElement("button");
editBtn.className = "edit-btn mod-btn";
editBtn.id = "edit-btn";
editBtn.setAttribute("data-id", ev.eventId);
editBtn.title = "Edit event";
editBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path d="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z"/></svg>`;
const removeBtn = document.createElement("button");
removeBtn.className = "remove-btn mod-btn";
removeBtn.id = "remove-btn";
removeBtn.setAttribute("data-id", ev.eventId);
removeBtn.title = "Remove event";
removeBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M280-440h400v-80H280v80ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>`;
const sendMsgBtn = document.createElement("button");
sendMsgBtn.className = "btn btn-sm btn-info";
sendMsgBtn.textContent = "Send Message";
sendMsgBtn.setAttribute("data-id", ev.eventId);
sendMsgBtn.title = "Send message about this event";
sendMsgBtn.addEventListener("click", () => __awaiter(this, void 0, void 0, function* () {
yield sendMessageForEvent(ev.eventId);
}));
buttonsDiv.appendChild(editBtn);
buttonsDiv.appendChild(removeBtn);
buttonsDiv.appendChild(sendMsgBtn);
card.appendChild(buttonsDiv);
}
container.appendChild(card);
}
@@ -107,21 +178,21 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
}
}
catch (_a) {
// console.log("User not signed in. Failing gracefully.");
unhideElementById(document, "joinnow-btn");
unhideElementById(document, "signin-btn");
}
loadEvents(org_id);
// listen for clicks
const listSortToggleButton = document.getElementById("list-sort-btn");
if (listSortToggleButton) {
listSortToggleButton.addEventListener("click", () => toggleListSortOrder(org_id));
}
// and for enter in search bar
const optionsToggleButton = document.getElementById("optionsbtn");
if (optionsToggleButton) {
optionsToggleButton.addEventListener("click", () => toggleOptionsVisibility());
}
const searchBar = document.getElementById('searchbar');
searchBar.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
// console.log('Enter key pressed!');
var searchResults = getEvents(searchBar.value);
loadEvents(org_id, searchResults);
}

View File

@@ -15,6 +15,14 @@ export function unhideElementById(document, e) {
}
});
}
export function hideElementById(document, e) {
return __awaiter(this, void 0, void 0, function* () {
var element = document.getElementById(e);
if (element) {
element.classList.add('hidden-before-load');
}
});
}
export function getEvent(id) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield fetch("/api/events/" + id);

View File

@@ -0,0 +1,107 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { getMyAccount, unhideElementById } from './generalUseHelpers.js';
// messages.ts
function getMyMessages() {
return __awaiter(this, void 0, void 0, function* () {
const res = yield fetch('/api/messages/my', {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
});
if (!res.ok)
throw new Error('Failed to load messages');
return yield res.json();
});
}
function formatDate(dateStr) {
const date = new Date(dateStr);
return date.toLocaleString(undefined, {
year: 'numeric', month: 'short', day: 'numeric',
hour: '2-digit', minute: '2-digit'
});
}
function createMessageCard(msg) {
var _a;
const card = document.createElement('div');
card.className = 'messages-card';
const sender = msg.isMsgFromVolunteer
? `Volunteer #${msg.volunteerId}`
: `Organization #${msg.organizationId}`;
// Safely inject content as HTML because it contains links
const contentHtml = (_a = msg.content) !== null && _a !== void 0 ? _a : '';
card.innerHTML = `
<button class="delete-btn" title="Delete message" data-id="${msg.messageId}">&times;</button>
<div class="message-header">${sender}</div>
<div class="message-date">${formatDate(msg.isoDate)}</div>
<div class="message-content">${contentHtml}</div>
<small><em>Regarding Event #${msg.eventType}</em></small>
`;
return card;
}
function deleteMessage(messageId) {
return __awaiter(this, void 0, void 0, function* () {
if (!confirm('Are you sure you want to delete this message?'))
return;
const res = yield fetch(`/api/messages/${messageId}`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' }
});
if (!res.ok) {
alert('Failed to delete message.');
return;
}
// Reload messages after delete
loadMessages();
});
}
function loadMessages() {
return __awaiter(this, void 0, void 0, function* () {
const container = document.getElementById('messagesContainer');
if (!container)
return;
try {
const messages = yield getMyMessages();
container.innerHTML = '';
if (messages.length === 0) {
container.innerHTML = `<p class="no-messages">No messages to display.</p>`;
return;
}
messages.forEach((msg) => {
const card = createMessageCard(msg);
container.appendChild(card);
});
// Attach delete handlers
container.querySelectorAll('.delete-btn').forEach(btn => {
btn.addEventListener('click', () => {
const idStr = btn.getAttribute('data-id');
if (idStr)
deleteMessage(parseInt(idStr));
});
});
}
catch (err) {
container.innerHTML = `<p class="no-messages text-danger">Failed to load messages.</p>`;
console.error(err);
}
});
}
document.addEventListener('DOMContentLoaded', () => __awaiter(void 0, void 0, void 0, function* () {
try {
var user = yield getMyAccount();
if (user) {
unhideElementById(document, "logout-btn");
}
}
catch (_a) {
unhideElementById(document, "joinnow-btn");
unhideElementById(document, "signin-btn");
}
loadMessages();
}));

View File

@@ -35,7 +35,7 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
unhideElementById(document, "orgno");
}
}
catch (_a) {
catch (e) {
window.location.href = "login.html";
}
var thisAccount = null;
@@ -63,7 +63,7 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
try {
const registeredIds = yield getMyRegisteredEventIds();
}
catch (_b) {
catch (e) {
}
}
unhideElementById(document, "mainContainer");
@@ -76,7 +76,7 @@ window.onload = () => {
const skillName = dropdown.options[dropdown.selectedIndex].text;
const skillId = dropdown.options[dropdown.selectedIndex].value;
if (skillName) {
addSkill(skillName, skillId, false);
addSkill(skillName, Number(skillId), false);
dropdown.value = ''; // Reset dropdown
}
});

View File

@@ -31,13 +31,13 @@
</a>
</div>
<div class="icon-box my-2">
<a href="#" class="nav-link text-info mb-3">
<a href="calendar.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z" /></svg>
<br /><h8 class="iconText">Calendar</h8>
</a>
</div>
<div class="icon-box mt-auto mb-4">
<a href="#" class="nav-link text-info mb-3">
<a href="messages.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="m370-80-16-128q-13-5-24.5-12T307-235l-119 50L78-375l103-78q-1-7-1-13.5v-27q0-6.5 1-13.5L78-585l110-190 119 50q11-8 23-15t24-12l16-128h220l16 128q13 5 24.5 12t22.5 15l119-50 110 190-103 78q1 7 1 13.5v27q0 6.5-2 13.5l103 78-110 190-118-50q-11 8-23 15t-24 12L590-80H370Zm70-80h79l14-106q31-8 57.5-23.5T639-327l99 41 39-68-86-65q5-14 7-29.5t2-31.5q0-16-2-31.5t-7-29.5l86-65-39-68-99 42q-22-23-48.5-38.5T533-694l-13-106h-79l-14 106q-31 8-57.5 23.5T321-633l-99-41-39 68 86 64q-5 15-7 30t-2 32q0 16 2 31t7 30l-86 65 39 68 99-42q22 23 48.5 38.5T427-266l13 106Zm42-180q58 0 99-41t41-99q0-58-41-99t-99-41q-59 0-99.5 41T342-480q0 58 40.5 99t99.5 41Zm-2-140Z" /></svg>
<br /><h8 class="iconText">Settings</h8>
</a>

View File

@@ -0,0 +1,112 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8" />
<title>Messages Panel</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet" />
<link href="/css/panel.css" rel="stylesheet" />
<style>
body.bg-light {
background-color: #f8f9fa !important;
}
.messages-card {
background: white;
padding: 1.5rem;
border-radius: 15px;
box-shadow: 0 0 10px rgb(0 0 0 / 0.1);
margin-bottom: 1rem;
}
.message-header {
font-weight: 600;
margin-bottom: 0.25rem;
}
.message-date {
font-size: 0.9rem;
color: #888;
margin-bottom: 0.5rem;
}
.message-content a {
color: #2898BD;
text-decoration: underline;
}
.delete-btn {
float: right;
cursor: pointer;
border: none;
background: transparent;
color: #dc3545;
font-weight: bold;
font-size: 1.1rem;
}
.no-messages {
color: #777;
font-style: italic;
}
</style>
</head>
<body class="bg-light">
<div class="d-flex">
<!-- Sidebar (z index.html) -->
<div class="sidebar">
<div class="text-center mb-4"></div>
<nav class="sidebar d-flex flex-column align-items-center pt-3">
<div class="icon-box my-2">
<a href="index.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M240-200h120v-240h240v240h120v-360L480-740 240-560v360Zm-80 80v-480l320-240 320 240v480H520v-240h-80v240H160Zm320-350Z" /></svg>
<br /><h8 class="iconText">Home</h8>
</a>
</div>
<div class="icon-box my-2">
<a href="messages.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M880-80 720-240H320q-33 0-56.5-23.5T240-320v-40h440q33 0 56.5-23.5T760-440v-280h40q33 0 56.5 23.5T880-640v560ZM160-473l47-47h393v-280H160v327ZM80-280v-520q0-33 23.5-56.5T160-880h440q33 0 56.5 23.5T680-800v280q0 33-23.5 56.5T600-440H240L80-280Zm80-240v-280 280Z" /></svg>
<br /><h8 class="iconText">Chats</h8>
</a>
</div>
<div class="icon-box my-2">
<a href="calendar.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z" /></svg>
<br /><h8 class="iconText">Calendar</h8>
</a>
</div>
<div class="icon-box mt-auto mb-4">
<a href="user.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="m370-80-16-128q-13-5-24.5-12T307-235l-119 50L78-375l103-78q-1-7-1-13.5v-27q0-6.5 1-13.5L78-585l110-190 119 50q11-8 23-15t24-12l16-128h220l16 128q13 5 24.5 12t22.5 15l119-50 110 190-103 78q1 7 1 13.5v27q0 6.5-2 13.5l103 78-110 190-118-50q-11 8-23 15t-24 12L590-80H370Zm70-80h79l14-106q31-8 57.5-23.5T639-327l99 41 39-68-86-65q5-14 7-29.5t2-31.5q0-16-2-31.5t-7-29.5l86-65-39-68-99 42q-22-23-48.5-38.5T533-694l-13-106h-79l-14 106q-31 8-57.5 23.5T321-633l-99-41-39 68 86 64q-5 15-7 30t-2 32q0 16 2 31t7 30l-86 65 39 68 99-42q22 23 48.5 38.5T427-266l13 106Zm42-180q58 0 99-41t41-99q0-58-41-99t-99-41q-59 0-99.5 41T342-480q0 58 40.5 99t99.5 41Zm-2-140Z" /></svg>
<br /><h8 class="iconText">Settings</h8>
</a>
</div>
</nav>
</div>
<!-- Top Nav (z index.html) -->
<div class="topnav d-flex justify-content-between align-items-center shadow">
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
<div>
<button class="button-join hidden-before-load" id="joinnow-btn">Join now</button>
<button class="button-sign hidden-before-load" id="signin-btn">Sign In</button>
<button class="button-sign hidden-before-load" id="logout-btn">Log out</button>
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
</div>
</div>
<!-- Main content (WIADOMOŚCI zamiast eventList) -->
<div class="main p-4">
<h2 class="mb-4">Messages</h2>
<div id="messagesContainer" class="messages-card">
<p class="no-messages">Loading messages... please wait.</p>
</div>
</div>
</div>
<script type="module" src="/js/messages.js"></script>
<script type="module" src="js/auth.js"></script>
</body>
</html>

View File

@@ -25,13 +25,13 @@
</a>
</div>
<div class="icon-box my-2">
<a href="#" class="nav-link text-info mb-3">
<a href="messages.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M880-80 720-240H320q-33 0-56.5-23.5T240-320v-40h440q33 0 56.5-23.5T760-440v-280h40q33 0 56.5 23.5T880-640v560ZM160-473l47-47h393v-280H160v327ZM80-280v-520q0-33 23.5-56.5T160-880h440q33 0 56.5 23.5T680-800v280q0 33-23.5 56.5T600-440H240L80-280Zm80-240v-280 280Z" /></svg>
<br /><h8 class="iconText">Chats</h8>
</a>
</div>
<div class="icon-box my-2">
<a href="#" class="nav-link text-info mb-3">
<a href="calendar.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z" /></svg>
<br /><h8 class="iconText">Calendar</h8>
</a>

View File

@@ -24,13 +24,13 @@
</a>
</div>
<div class="icon-box my-2">
<a href="#" class="nav-link text-info mb-3">
<a href="messages.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M880-80 720-240H320q-33 0-56.5-23.5T240-320v-40h440q33 0 56.5-23.5T760-440v-280h40q33 0 56.5 23.5T880-640v560ZM160-473l47-47h393v-280H160v327ZM80-280v-520q0-33 23.5-56.5T160-880h440q33 0 56.5 23.5T680-800v280q0 33-23.5 56.5T600-440H240L80-280Zm80-240v-280 280Z" /></svg>
<br /><h8 class="iconText">Chats</h8>
</a>
</div>
<div class="icon-box my-2">
<a href="#" class="nav-link text-info mb-3">
<a href="calendar.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z" /></svg>
<br /><h8 class="iconText">Calendar</h8>
</a>
@@ -75,7 +75,7 @@
<script type="module" src="/js/userSkills.js"></script>
<script type="module" src="/js/generalUseHelpers.js"></script>
<script type="module" src="/js/auth.js"></script>
<script type="module" src="/js/auth.js" defer></script>
</body>

View File

@@ -24,13 +24,13 @@
</a>
</div>
<div class="icon-box my-2">
<a href="#" class="nav-link text-info mb-3">
<a href="messages.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M880-80 720-240H320q-33 0-56.5-23.5T240-320v-40h440q33 0 56.5-23.5T760-440v-280h40q33 0 56.5 23.5T880-640v560ZM160-473l47-47h393v-280H160v327ZM80-280v-520q0-33 23.5-56.5T160-880h440q33 0 56.5 23.5T680-800v280q0 33-23.5 56.5T600-440H240L80-280Zm80-240v-280 280Z" /></svg>
<br /><h8 class="iconText">Chats</h8>
</a>
</div>
<div class="icon-box my-2">
<a href="#" class="nav-link text-info mb-3">
<a href="calendar.html" class="nav-link text-info mb-3">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z" /></svg>
<br /><h8 class="iconText">Calendar</h8>
</a>