Skip to content

Commit 4477804

Browse files
authored
chore: change to loadmore style (#379)
1 parent d1db367 commit 4477804

File tree

1 file changed

+21
-95
lines changed
  • platforms/pictique/src/routes/(protected)/messages

1 file changed

+21
-95
lines changed

platforms/pictique/src/routes/(protected)/messages/+page.svelte

Lines changed: 21 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
2424
// Pagination and loading state
2525
let isLoading = $state(true);
26+
let isLoadingMore = $state(false);
2627
let currentPage = $state(1);
2728
let totalPages = $state(1);
2829
let totalChats = $state(0);
@@ -91,21 +92,14 @@
9192
}
9293
}
9394
94-
async function loadNextPage() {
95-
if (hasMorePages && !isLoading) {
96-
await loadMessages(currentPage + 1, true);
97-
}
98-
}
99-
100-
async function loadPreviousPage() {
101-
if (currentPage > 1 && !isLoading) {
102-
await loadMessages(currentPage - 1, false);
103-
}
104-
}
105-
106-
async function goToPage(page: number) {
107-
if (page >= 1 && page <= totalPages && !isLoading) {
108-
await loadMessages(page, false);
95+
async function loadMoreMessages() {
96+
if (hasMorePages && !isLoadingMore) {
97+
isLoadingMore = true;
98+
try {
99+
await loadMessages(currentPage + 1, true);
100+
} finally {
101+
isLoadingMore = false;
102+
}
109103
}
110104
}
111105
@@ -287,94 +281,26 @@
287281
/>
288282
{/each}
289283

290-
<!-- Pagination Controls -->
291-
{#if totalPages > 1}
292-
<div class="mt-6 flex items-center justify-between">
293-
<Button
294-
variant="secondary"
295-
size="sm"
296-
callback={loadPreviousPage}
297-
disabled={currentPage <= 1 || isLoading}
298-
>
299-
Previous
300-
</Button>
301-
302-
<div class="flex items-center space-x-2">
303-
{#if totalPages <= 7}
304-
{#each Array.from({ length: totalPages }, (_, i) => i + 1) as page}
305-
<button
306-
class="rounded px-3 py-1 text-sm {page === currentPage
307-
? 'bg-blue-600 text-white'
308-
: 'bg-gray-200 text-gray-700 hover:bg-gray-300'}"
309-
onclick={() => goToPage(page)}
310-
disabled={isLoading}
311-
>
312-
{page}
313-
</button>
314-
{/each}
315-
{:else}
316-
<!-- Show first page -->
317-
<button
318-
class="rounded px-3 py-1 text-sm {1 === currentPage
319-
? 'bg-blue-600 text-white'
320-
: 'bg-gray-200 text-gray-700 hover:bg-gray-300'}"
321-
onclick={() => goToPage(1)}
322-
disabled={isLoading}
323-
>
324-
1
325-
</button>
326-
327-
{#if currentPage > 3}
328-
<span class="text-gray-500">...</span>
329-
{/if}
330-
331-
<!-- Show pages around current page -->
332-
{#each Array.from({ length: Math.min(3, totalPages - 2) }, (_, i) => {
333-
const start = Math.max(2, currentPage - 1);
334-
return Math.min(start + i, totalPages - 1);
335-
}).filter((page, index, arr) => arr.indexOf(page) === index) as page}
336-
<button
337-
class="rounded px-3 py-1 text-sm {page === currentPage
338-
? 'bg-blue-600 text-white'
339-
: 'bg-gray-200 text-gray-700 hover:bg-gray-300'}"
340-
onclick={() => goToPage(page)}
341-
disabled={isLoading}
342-
>
343-
{page}
344-
</button>
345-
{/each}
346-
347-
{#if currentPage < totalPages - 2}
348-
<span class="text-gray-500">...</span>
349-
{/if}
350-
351-
<!-- Show last page -->
352-
{#if totalPages > 1}
353-
<button
354-
class="rounded px-3 py-1 text-sm {totalPages === currentPage
355-
? 'bg-blue-600 text-white'
356-
: 'bg-gray-200 text-gray-700 hover:bg-gray-300'}"
357-
onclick={() => goToPage(totalPages)}
358-
disabled={isLoading}
359-
>
360-
{totalPages}
361-
</button>
362-
{/if}
363-
{/if}
364-
</div>
365-
284+
<!-- Load More Button -->
285+
{#if hasMorePages}
286+
<div class="mt-4 flex justify-center">
366287
<Button
367288
variant="secondary"
368289
size="sm"
369-
callback={loadNextPage}
370-
disabled={!hasMorePages || isLoading}
290+
callback={loadMoreMessages}
291+
disabled={isLoadingMore}
292+
isLoading={isLoadingMore}
371293
>
372-
Next
294+
Load More Chats
373295
</Button>
374296
</div>
375297

376298
<div class="mt-2 text-center text-sm text-gray-500">
377-
Page {currentPage} of {totalPages} • {totalChats} total chats
299+
Showing {messages.length} of {totalChats} chats
300+
</div>
301+
{:else if messages.length > 0}
302+
<div class="mt-2 text-center text-sm text-gray-500">
303+
All {totalChats} chats loaded
378304
</div>
379305
{/if}
380306
{:else if !isLoading}

0 commit comments

Comments
 (0)