MCPcopy Create free account
hub / github.com/Forward-Future/loopy / updateLibrary

Function updateLibrary

loop-library/site/script.js:248–298  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

246let currentPage = 1;
247let toastTimer;
248
249function normalize(value) {
250 return value.toLowerCase().trim();
251}
252
253function updateLibrary() {
254 if (!searchInput || !resultsCount || !emptyState) {
255 return;
256 }
257
258 const query = normalize(searchInput.value);
259 const matchingRows = loopRows.filter((row) => {
260 const searchableText = rowSearchText.get(row) ?? "";
261 const matchesSearch =
262 query.length === 0 || searchableText.includes(query);
263 const matchesCategory =
264 activeCategory === "all" || row.dataset.category === activeCategory;
265 return matchesSearch && matchesCategory;
266 });
267
268 const totalMatches = matchingRows.length;
269 const totalPages = Math.max(1, Math.ceil(totalMatches / PAGE_SIZE));
270 currentPage = Math.min(currentPage, totalPages);
271
272 const pageStart = (currentPage - 1) * PAGE_SIZE;
273 const pageEnd = Math.min(pageStart + PAGE_SIZE, totalMatches);
274 const pageRows = new Set(matchingRows.slice(pageStart, pageEnd));
275
276 loopRows.forEach((row) => {
277 row.hidden = !pageRows.has(row);
278 });
279
280 if (totalMatches === 0) {
281 resultsCount.textContent = "Showing 0 loops";
282 } else if (totalMatches === 1) {
283 resultsCount.textContent = "Showing 1 loop";
284 } else {
285 resultsCount.textContent = `Showing ${pageStart + 1}–${pageEnd} of ${totalMatches} loops`;
286 }
287
288 emptyState.hidden = totalMatches !== 0;
289
290 if (
291 pagination &&
292 paginationPrevious &&
293 paginationNext &&
294 paginationStatus
295 ) {
296 pagination.hidden = totalPages <= 1;
297 paginationPrevious.disabled = currentPage === 1;
298 paginationNext.disabled = currentPage === totalPages;
299 paginationStatus.textContent = `Page ${currentPage} of ${totalPages}`;
300 }
301

Callers 3

resetSearchPageFunction · 0.85
script.jsFile · 0.85
loadVotesFunction · 0.85

Calls 2

normalizeFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected