fix: front-end improvements

makes some fields visible and other hidden depending on the result of
some API calls, e.g. visitor is logged in -> show "Log out" button
This commit is contained in:
2025-05-19 00:43:15 +02:00
parent e0e6fa0573
commit 5536a9ad7f
15 changed files with 465 additions and 22 deletions

View File

@@ -1,4 +1,3 @@
"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) {
@@ -8,21 +7,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { getMyAccount, unhideElementById } from './generalUseHelpers.js';
var isAscending = false;
function toggleListSortOrder() {
isAscending = !isAscending;
loadEvents();
}
function getEvents() {
return __awaiter(this, void 0, void 0, function* () {
const res = yield fetch("/api/events" + (isAscending ? "?sort=asc" : ""));
if (!res.ok)
throw new Error("Błąd pobierania wydarzeń");
const events = yield res.json();
return events;
});
}
function loadEvents() {
return __awaiter(this, void 0, void 0, function* () {
const container = document.getElementById("eventList");
if (!container)
return;
try {
const res = yield fetch("/api/events" + (isAscending ? "?sort=asc" : ""));
if (!res.ok)
throw new Error("Błąd pobierania wydarzeń");
const events = yield res.json();
var events = yield getEvents();
if (events.length === 0) {
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
return;
@@ -48,6 +54,18 @@ function loadEvents() {
});
}
document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, void 0, function* () {
var user = yield getMyAccount();
if (user) {
if (user.isOrganisation) {
unhideElementById(document, "mainContainer");
unhideElementById(document, "addnewevent-btn");
}
unhideElementById(document, "logout-btn");
}
else {
unhideElementById(document, "joinnow-btn");
unhideElementById(document, "signin-btn");
}
loadEvents();
// listen for clicks
const listSortToggleButton = document.getElementById("list-sort-btn");