feat: Remove infinite scrolling from tags page and increase tags per page to 500.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import db from "../../inc/sql.mjs";
|
import db from "../../inc/sql.mjs";
|
||||||
import cfg from "../../inc/config.mjs";
|
import cfg from "../../inc/config.mjs";
|
||||||
|
|
||||||
const TAGS_PER_PAGE = 50;
|
const TAGS_PER_PAGE = 500;
|
||||||
|
|
||||||
export default (router, tpl) => {
|
export default (router, tpl) => {
|
||||||
// API endpoint for lazy loading tags
|
// API endpoint for lazy loading tags
|
||||||
|
|||||||
@@ -29,82 +29,6 @@
|
|||||||
@endeach
|
@endeach
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div id="tags-loader" style="text-align: center; padding: 20px; display: none;">
|
|
||||||
<span style="color: #888;">Loading more tags...</span>
|
|
||||||
</div>
|
|
||||||
<div id="tags-end" style="text-align: center; padding: 20px; display: none;">
|
|
||||||
<span style="color: #666;">No more tags</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
(function () {
|
|
||||||
let page = 1;
|
|
||||||
let loading = false;
|
|
||||||
let hasMore = true;
|
|
||||||
const container = document.getElementById('tags-container');
|
|
||||||
const loader = document.getElementById('tags-loader');
|
|
||||||
const endMsg = document.getElementById('tags-end');
|
|
||||||
|
|
||||||
const escapeHtml = (str) => {
|
|
||||||
const div = document.createElement('div');
|
|
||||||
div.textContent = str;
|
|
||||||
return div.innerHTML;
|
|
||||||
};
|
|
||||||
|
|
||||||
const loadMore = async () => {
|
|
||||||
if (loading || !hasMore) return;
|
|
||||||
loading = true;
|
|
||||||
loader.style.display = 'block';
|
|
||||||
page++;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await fetch(`/api/tags?page=${page}`);
|
|
||||||
const data = await res.json();
|
|
||||||
|
|
||||||
if (!data.tags || data.tags.length === 0) {
|
|
||||||
hasMore = false;
|
|
||||||
loader.style.display = 'none';
|
|
||||||
endMsg.style.display = 'block';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasMore = data.hasMore;
|
|
||||||
|
|
||||||
data.tags.forEach(tag => {
|
|
||||||
const escapedTag = escapeHtml(tag.tag);
|
|
||||||
const html = `
|
|
||||||
<a href="/tag/${encodeURIComponent(tag.tag)}" class="tag-card">
|
|
||||||
<div class="tag-card-image">
|
|
||||||
<img src="/tag_image/${encodeURIComponent(tag.tag)}" loading="lazy" alt="${escapedTag}">
|
|
||||||
</div>
|
|
||||||
<div class="tag-card-content">
|
|
||||||
<span class="tag-name">#${escapedTag}</span>
|
|
||||||
<span class="tag-count">${tag.total_items} posts</span>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
`;
|
|
||||||
container.insertAdjacentHTML('beforeend', html);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!hasMore) {
|
|
||||||
endMsg.style.display = 'block';
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to load tags:', e);
|
|
||||||
} finally {
|
|
||||||
loading = false;
|
|
||||||
loader.style.display = 'none';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Infinite scroll
|
|
||||||
window.addEventListener('scroll', () => {
|
|
||||||
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight - 500) {
|
|
||||||
loadMore();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
@include(snippets/footer)
|
@include(snippets/footer)
|
||||||
Reference in New Issue
Block a user