From ccd376252482923728def9a81fcfc05db7bb24f7 Mon Sep 17 00:00:00 2001 From: Jukka Lampikoski Date: Sun, 8 Mar 2026 19:38:56 +0200 Subject: [PATCH] Add pagination to admin post list (20 per page) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shows 20 posts at a time with 'Näytä lisää' button. Search also filters by author/category and resets pagination. Co-Authored-By: Claude Opus 4.6 --- admin.html | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/admin.html b/admin.html index ecf8c44..f400685 100644 --- a/admin.html +++ b/admin.html @@ -402,10 +402,13 @@

Kaikki julkaisut

-
+
@@ -884,9 +887,13 @@ // =========================== // RENDER POST LIST // =========================== + const ADMIN_PER_PAGE = 20; + let adminVisible = ADMIN_PER_PAGE; + function renderPostList() { const posts = ADMIN.posts; const el = document.getElementById('postList'); + adminVisible = ADMIN_PER_PAGE; if (!posts.length) { el.innerHTML = `

${at('empty')}

`; return; } el.innerHTML = posts.map(p => `
@@ -901,14 +908,31 @@
`).join(''); + filterPostList(); } function filterPostList() { - const q = document.getElementById('postSearch').value.toLowerCase(); - document.querySelectorAll('#postList .post-item').forEach(el => { - const text = el.querySelector('h3').textContent.toLowerCase(); - el.style.display = text.includes(q) ? '' : 'none'; + const q = document.getElementById('postSearch')?.value.toLowerCase() || ''; + const items = document.querySelectorAll('#postList .post-item'); + let matched = 0, shown = 0; + items.forEach(el => { + const text = (el.querySelector('h3')?.textContent || '').toLowerCase() + + (el.querySelector('.post-item-info p')?.textContent || '').toLowerCase(); + if (!q || text.includes(q)) { + matched++; + el.style.display = matched <= adminVisible ? '' : 'none'; + if (matched <= adminVisible) shown++; + } else { + el.style.display = 'none'; + } }); + const wrap = document.getElementById('adminLoadMore'); + if (wrap) wrap.style.display = matched > shown ? '' : 'none'; + } + + function adminShowMore() { + adminVisible += ADMIN_PER_PAGE; + filterPostList(); } // ===========================