|
24 | 24 | let refresh = getRefreshSignal(); |
25 | 25 | let selectedStatus = $state('all'); |
26 | 26 | let searchQuery = $state(''); |
| 27 | + let pageSize = 20; |
| 28 | + let visibleCount = $state(20); |
27 | 29 | /** @type {import('$lib/db/queries').Item | null} */ |
28 | 30 | let selectedItem = $state(null); |
29 | 31 |
|
|
102 | 104 | return result; |
103 | 105 | }); |
104 | 106 |
|
| 107 | + let paginatedItems = $derived(filteredItems.slice(0, visibleCount)); |
| 108 | + let hasMore = $derived(filteredItems.length > visibleCount); |
| 109 | +
|
| 110 | + function showMore() { |
| 111 | + visibleCount += pageSize; |
| 112 | + } |
| 113 | +
|
| 114 | + // Reset pagination when filters change |
| 115 | + $effect(() => { |
| 116 | + searchQuery; |
| 117 | + selectedCategoryId; |
| 118 | + selectedSubcategoryId; |
| 119 | + selectedStatus; |
| 120 | + visibleCount = pageSize; |
| 121 | + }); |
| 122 | +
|
105 | 123 | let statusCounts = $derived.by(() => { |
106 | 124 | const catItems = selectedCategoryId === 0 ? items : items.filter(i => i.category_id === selectedCategoryId); |
107 | 125 | const counts = { all: catItems.length, active: 0, used_up: 0, decluttered: 0 }; |
|
236 | 254 | </div> |
237 | 255 | {:else} |
238 | 256 | <div class="items-list"> |
239 | | - {#each filteredItems as item (item.id)} |
| 257 | + {#each paginatedItems as item (item.id)} |
240 | 258 | {#if selectMode} |
241 | 259 | <!-- svelte-ignore a11y_click_events_have_key_events --> |
242 | 260 | <!-- svelte-ignore a11y_no_static_element_interactions --> |
|
247 | 265 | <i class={item.category_icon ?? 'ri-box-3-line'}></i> |
248 | 266 | </div> |
249 | 267 | <div class="list-item-info"> |
250 | | - <h3 class="list-item-name">{item.name}</h3> |
| 268 | + <h3 class="list-item-name">{item.name}{#if item.quantity > 1} <span class="qty-badge">x{item.quantity}</span>{/if}</h3> |
251 | 269 | <span class="list-item-sub">{item.subcategory_name || item.category_name}</span> |
252 | 270 | </div> |
253 | 271 | <div class="list-item-right"> |
|
275 | 293 | <i class={item.category_icon ?? 'ri-box-3-line'}></i> |
276 | 294 | </div> |
277 | 295 | <div class="list-item-info"> |
278 | | - <h3 class="list-item-name">{item.name}</h3> |
| 296 | + <h3 class="list-item-name">{item.name}{#if item.quantity > 1} <span class="qty-badge">x{item.quantity}</span>{/if}</h3> |
279 | 297 | <span class="list-item-sub">{item.subcategory_name || item.category_name}</span> |
280 | 298 | </div> |
281 | 299 | <div class="list-item-right"> |
|
305 | 323 | </div> |
306 | 324 | {/each} |
307 | 325 | </div> |
| 326 | + {#if hasMore} |
| 327 | + <button class="show-more-btn" onclick={showMore}> |
| 328 | + {t.common.showMore} ({filteredItems.length - visibleCount} {t.common.remaining}) |
| 329 | + </button> |
| 330 | + {/if} |
308 | 331 | {/if} |
309 | 332 | </main> |
310 | 333 |
|
|
500 | 523 | margin: 0; |
501 | 524 | white-space: nowrap; overflow: hidden; text-overflow: ellipsis; |
502 | 525 | } |
| 526 | + .qty-badge { |
| 527 | + font-size: 11px; |
| 528 | + font-weight: 700; |
| 529 | + color: white; |
| 530 | + background: var(--accent-pink); |
| 531 | + padding: 1px 6px; |
| 532 | + border-radius: 50px; |
| 533 | + vertical-align: middle; |
| 534 | + } |
503 | 535 | .list-item-sub { |
504 | 536 | font-size: 11px; color: var(--text-soft); |
505 | 537 | text-transform: uppercase; letter-spacing: 0.3px; |
|
552 | 584 | color: var(--accent-pink); |
553 | 585 | transform: scale(0.85); |
554 | 586 | } |
| 587 | + .show-more-btn { |
| 588 | + width: 100%; |
| 589 | + padding: 14px; |
| 590 | + margin-top: 12px; |
| 591 | + border: 1px dashed rgba(0, 0, 0, 0.12); |
| 592 | + border-radius: var(--radius-s); |
| 593 | + background: transparent; |
| 594 | + font-family: 'Poppins', sans-serif; |
| 595 | + font-size: 13px; |
| 596 | + font-weight: 600; |
| 597 | + color: var(--accent-pink); |
| 598 | + cursor: pointer; |
| 599 | + transition: 0.2s; |
| 600 | + -webkit-tap-highlight-color: transparent; |
| 601 | + } |
| 602 | + .show-more-btn:active { |
| 603 | + transform: scale(0.97); |
| 604 | + background: rgba(255, 107, 129, 0.04); |
| 605 | + } |
555 | 606 | </style> |
0 commit comments