changes
All checks were successful
Build Org Website / build (push) Successful in 46s

This commit is contained in:
2026-05-09 16:33:36 +01:00
parent 63f260866e
commit 9623935ed0
15 changed files with 100 additions and 306 deletions

View File

@@ -3,8 +3,6 @@
const form = document.getElementById("notes-form");
const authorInput = document.getElementById("note-author");
const contentInput = document.getElementById("note-content");
const authorFilter = document.getElementById("notes-author-filter");
let notesCache = [];
if (!wall) return;
@@ -36,53 +34,6 @@
return el;
}
function normaliseAuthor(author) {
return (author || "").trim();
}
function populateAuthorFilter(notes) {
if (!authorFilter) return;
const previousValue = authorFilter.value;
const authors = Array.from(
new Set(notes.map(note => normaliseAuthor(note.author_name)).filter(Boolean))
).sort((a, b) => a.localeCompare(b, undefined, { sensitivity: "base" }));
authorFilter.innerHTML = '<option value="">All authors</option>';
authors.forEach(author => {
const option = document.createElement("option");
option.value = author;
option.textContent = author;
authorFilter.appendChild(option);
});
authorFilter.value = authors.includes(previousValue) ? previousValue : "";
}
function renderNotes() {
wall.innerHTML = "";
const selectedAuthor = authorFilter ? authorFilter.value : "";
const notes = selectedAuthor
? notesCache.filter(note => normaliseAuthor(note.author_name) === selectedAuthor)
: notesCache;
if (notesCache.length === 0) {
wall.innerHTML = "<p>No notes yet.</p>";
return;
}
if (notes.length === 0) {
wall.innerHTML = "<p>No notes for this author.</p>";
return;
}
notes.forEach(note => {
wall.appendChild(renderNote(note));
});
}
async function loadNotes() {
wall.innerHTML = "<p>Loading notes…</p>";
@@ -91,9 +42,16 @@
if (!res.ok) throw new Error("Failed to fetch notes");
const notes = await res.json();
notesCache = notes;
populateAuthorFilter(notesCache);
renderNotes();
wall.innerHTML = "";
if (notes.length === 0) {
wall.innerHTML = "<p>No notes yet.</p>";
return;
}
notes.forEach(note => {
wall.appendChild(renderNote(note));
});
} catch (err) {
console.error(err);
wall.innerHTML = "<p>Could not load notes.</p>";
@@ -140,9 +98,5 @@
form.addEventListener("submit", submitNote);
}
if (authorFilter) {
authorFilter.addEventListener("change", renderNotes);
}
loadNotes();
})();