()
| 246 | let currentPage = 1; |
| 247 | let toastTimer; |
| 248 | |
| 249 | function normalize(value) { |
| 250 | return value.toLowerCase().trim(); |
| 251 | } |
| 252 | |
| 253 | function 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 |
no test coverage detected