var pageItems; const galleryLimit = 100; async function galleryPageMain() { // set up the preview modal to work on our page PreviewModal.prev = async (currentItem) => { // TODO: These don't play nicely when semantic_text is filled out, is there a better way to do these? const params = galleryFilterParams("prev", currentItem); // params.limit = 1; // params.sort = null; // let backend use smart sort // if ($('#filter-sort').value == "ASC") { // params.end_timestamp = currentItem.timestamp; // } else { // params.start_timestamp = currentItem.timestamp; // } const results = await app.SearchItems(params); console.log("PREV RESULTS:", results, currentItem); return results.items?.[0]; }; PreviewModal.next = async (currentItem) => { const params = galleryFilterParams("next", currentItem); // params.limit = 1; // params.sort = null; // let backend use smart sort // if ($('#filter-sort').value == "ASC") { // params.start_timestamp = currentItem.timestamp; // } else { // params.end_timestamp = currentItem.timestamp; // } const results = await app.SearchItems(params); console.log("NEXT RESULTS:", results, currentItem); return results.items?.[0]; }; // perform search const results = await app.SearchItems(galleryFilterParams()); console.log("RESULTS:", results) // configure pagination links: enable next if we overflowed the search results limit, // and enable prev if we are not on page 1; otherwise disable prev/next link(s) for (const elem of $$('.pagination .page-next')) { if (results.items?.length > galleryLimit) { elem.classList.remove('disabled'); let newQS = new URLSearchParams(window.location.search); newQS.set('page', currentPageNum() + 1); elem.href = '?'+newQS.toString(); } else { elem.classList.add('disabled'); elem.href = ''; } } for (const elem of $$('.pagination .page-prev')) { if (currentPageNum() > 1) { elem.classList.remove('disabled'); let newQS = new URLSearchParams(window.location.search); if (currentPageNum() == 2) { newQS.delete('page'); } else { newQS.set('page', currentPageNum() - 1); } elem.href = '?'+newQS.toString(); } else { elem.classList.add('disabled'); elem.href = ''; } } if (!results.items) { return; } results.items.splice(galleryLimit); // strip the extra item that is only used for pagination purposes // reset items pageItems = {}; $('.filter-results').replaceChildren(); // render each item for (let item of results.items) { const elem = cloneTemplate('#tpl-media'); elem.id = `item-${item.id}`; let mediaElem = itemContentElement(item, { thumbnail: true }); mediaElem.classList.add('card-img-top', 'overflow-hidden'); // overflow-hidden is needed for obfuscation mode... /* TODO: I kind of like this dreamy glow effect around each video (maybe image too?) -- maybe just on hover though?