ertuzaes
This commit is contained in:
parent
4cf3d03017
commit
2276946ef0
@ -1,16 +1,16 @@
|
||||
const CARDS_PER_PAGE = 12;
|
||||
|
||||
const RACES = [
|
||||
{ id: "menschen", label: "Menschen", icon: "⚔️" },
|
||||
{ id: "elfen", label: "Elfen", icon: "🌿" },
|
||||
{ id: "zwerge", label: "Zwerge", icon: "⛏️" },
|
||||
{ id: "orks", label: "Orks", icon: "💀" },
|
||||
{ id: "untote", label: "Untote", icon: "💀" },
|
||||
{ id: "drachen", label: "Drachen", icon: "🐉" },
|
||||
{ id: "ritter", label: "Ritter", icon: "⚔️" },
|
||||
{ id: "elfen", label: "Elfen", icon: "🌿" },
|
||||
{ id: "zwerge", label: "Zwerge", icon: "⛏️" },
|
||||
{ id: "orks", label: "Orks", icon: "💀" },
|
||||
{ id: "untote", label: "Untote", icon: "💀" },
|
||||
{ id: "drachen", label: "Drachen", icon: "🐉" },
|
||||
];
|
||||
|
||||
let currentRace = RACES[0].id;
|
||||
let currentPage = 1;
|
||||
let currentPage = 1;
|
||||
|
||||
export async function loadLuckyBox() {
|
||||
const body = document.getElementById("qm-body-glucksbox");
|
||||
@ -23,12 +23,14 @@ export async function loadLuckyBox() {
|
||||
|
||||
/* ── HTML-Grundstruktur ─────────────────────── */
|
||||
function renderShell() {
|
||||
const tabs = RACES.map((r, i) => `
|
||||
const tabs = RACES.map(
|
||||
(r, i) => `
|
||||
<button class="kd-tab ${i === 0 ? "kd-tab-active" : ""}" data-race="${r.id}">
|
||||
<span class="kd-tab-icon">${r.icon}</span>
|
||||
<span class="kd-tab-label">${r.label}</span>
|
||||
</button>
|
||||
`).join("");
|
||||
`,
|
||||
).join("");
|
||||
|
||||
return `
|
||||
<div class="kd-wrap">
|
||||
@ -258,7 +260,9 @@ function renderShell() {
|
||||
function attachTabEvents() {
|
||||
document.querySelectorAll(".kd-tab").forEach((btn) => {
|
||||
btn.addEventListener("click", async () => {
|
||||
document.querySelectorAll(".kd-tab").forEach((b) => b.classList.remove("kd-tab-active"));
|
||||
document
|
||||
.querySelectorAll(".kd-tab")
|
||||
.forEach((b) => b.classList.remove("kd-tab-active"));
|
||||
btn.classList.add("kd-tab-active");
|
||||
currentRace = btn.dataset.race;
|
||||
currentPage = 1;
|
||||
@ -269,7 +273,7 @@ function attachTabEvents() {
|
||||
|
||||
/* ── Karten laden ───────────────────────────── */
|
||||
async function loadCards() {
|
||||
const grid = document.getElementById("kd-grid");
|
||||
const grid = document.getElementById("kd-grid");
|
||||
const pagination = document.getElementById("kd-pagination");
|
||||
if (!grid) return;
|
||||
|
||||
@ -277,7 +281,9 @@ async function loadCards() {
|
||||
pagination.innerHTML = "";
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/cards?race=${currentRace}&page=${currentPage}&limit=${CARDS_PER_PAGE}`);
|
||||
const res = await fetch(
|
||||
`/api/cards?race=${currentRace}&page=${currentPage}&limit=${CARDS_PER_PAGE}`,
|
||||
);
|
||||
if (!res.ok) throw new Error("API Fehler");
|
||||
const data = await res.json();
|
||||
// data = { cards: [...], total: N, page: N, totalPages: N }
|
||||
@ -296,15 +302,19 @@ function renderGrid(grid, cards) {
|
||||
return;
|
||||
}
|
||||
|
||||
grid.innerHTML = cards.map((c) => `
|
||||
grid.innerHTML = cards
|
||||
.map(
|
||||
(c) => `
|
||||
<div class="kd-card" title="${c.name}">
|
||||
<img src="/images/cards/${c.image}" alt="${c.name}"
|
||||
onerror="this.src='/images/cards/placeholder.png'">
|
||||
${c.attack !== undefined ? `<span class="kd-stat-atk">${c.attack}</span>` : ""}
|
||||
${c.attack !== undefined ? `<span class="kd-stat-atk">${c.attack}</span>` : ""}
|
||||
${c.defense !== undefined ? `<span class="kd-stat-def">${c.defense}</span>` : ""}
|
||||
<div class="kd-card-name">${c.name}</div>
|
||||
</div>
|
||||
`).join("");
|
||||
`,
|
||||
)
|
||||
.join("");
|
||||
}
|
||||
|
||||
/* ── Pagination rendern ─────────────────────── */
|
||||
@ -315,18 +325,28 @@ function renderPagination(pagination, totalPages, total) {
|
||||
|
||||
pagination.innerHTML = `
|
||||
<button class="kd-page-btn" id="kd-prev" ${currentPage === 1 ? "disabled" : ""}>◀</button>
|
||||
${pages.map((p) => `
|
||||
${pages
|
||||
.map(
|
||||
(p) => `
|
||||
<button class="kd-page-btn ${p === currentPage ? "kd-page-active" : ""}" data-page="${p}">${p}</button>
|
||||
`).join("")}
|
||||
`,
|
||||
)
|
||||
.join("")}
|
||||
<button class="kd-page-btn" id="kd-next" ${currentPage === totalPages ? "disabled" : ""}>▶</button>
|
||||
<span class="kd-page-info">${total} Karten</span>
|
||||
`;
|
||||
|
||||
document.getElementById("kd-prev")?.addEventListener("click", async () => {
|
||||
if (currentPage > 1) { currentPage--; await loadCards(); }
|
||||
if (currentPage > 1) {
|
||||
currentPage--;
|
||||
await loadCards();
|
||||
}
|
||||
});
|
||||
document.getElementById("kd-next")?.addEventListener("click", async () => {
|
||||
if (currentPage < totalPages) { currentPage++; await loadCards(); }
|
||||
if (currentPage < totalPages) {
|
||||
currentPage++;
|
||||
await loadCards();
|
||||
}
|
||||
});
|
||||
pagination.querySelectorAll("[data-page]").forEach((btn) => {
|
||||
btn.addEventListener("click", async () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user