forked from cypht-org/cypht
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(frontend): move from the legacy pagination links to a new compone…
…nt with enhanced user experience, and fix the pagination action, which previously responded with some latency (cypht-org#1413)
- Loading branch information
1 parent
0e8bec3
commit 33d7e11
Showing
12 changed files
with
160 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
function refreshNextButton(current) { | ||
const totalPages = $(".pagination .total").text(); | ||
if (current >= totalPages) { | ||
$(".pagination .next").prop('disabled', true); | ||
} else { | ||
$(".pagination .next").prop('disabled', false); | ||
} | ||
} | ||
|
||
function refreshPreviousButton(current) { | ||
if (current <= 1) { | ||
$(".pagination .prev").prop('disabled', true); | ||
} else { | ||
$(".pagination .prev").prop('disabled', false); | ||
} | ||
} | ||
|
||
async function nextPage() { | ||
const currentPage = $(".pagination .current").text(); | ||
|
||
const nextPage = parseInt(currentPage) + 1; | ||
|
||
await changePage(nextPage, this); | ||
} | ||
|
||
async function previousPage() { | ||
const currentPage = $(".pagination .current").text(); | ||
|
||
const previousPage = parseInt(currentPage) - 1; | ||
|
||
await changePage(previousPage, this); | ||
|
||
if (previousPage > 1) { | ||
$(this).prop('disabled', false); | ||
} | ||
} | ||
|
||
async function changePage(toPage, button) { | ||
$(button).prop('disabled', true); | ||
$(button).addClass('active'); | ||
|
||
const url = new URL(window.location.href); | ||
url.searchParams.set('list_page', toPage); | ||
history.pushState(history.state, "", url.toString()); | ||
window.location.next = url.search; | ||
|
||
const messagesStore = new Hm_MessagesStore(getListPathParam(), toPage); | ||
try { | ||
await messagesStore.load(); | ||
Hm_Utils.tbody().attr('id', messagesStore.list); | ||
display_imap_mailbox(messagesStore.rows, null, messagesStore.list); | ||
$(".pagination .current").text(toPage); | ||
} catch (error) { | ||
Hm_Utils.add_sys_message("Failed to fetch content", "danger"); | ||
} finally { | ||
$(button).removeClass('active'); | ||
refreshNextButton(toPage); | ||
refreshPreviousButton(toPage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const paginationMarkup = (totalPages) => { | ||
const currentPage = getParam('list_page') || 1; | ||
const markup = ` | ||
<div class="pagination d-flex align-items-center gap-2 mb-2"> | ||
<button class="btn btn-sm rounded-circle prev"> | ||
<i class="bi bi-chevron-left"></i> | ||
</button> | ||
<div> | ||
<span class="current">${currentPage}</span>/<span class="total">${totalPages}</span> | ||
</div> | ||
<button class="btn rounded-circle btn-sm next"> | ||
<i class="bi bi-chevron-right"></i> | ||
</button> | ||
</div> | ||
` | ||
|
||
return markup; | ||
} | ||
|
||
function handlePagination() { | ||
$(".pagination .next").on("click", nextPage); | ||
$(".pagination .prev").on("click", previousPage); | ||
} | ||
|
||
function showPagination (totalPages) { | ||
if ($('.message_list .pagination').length) { | ||
$('.message_list .pagination').remove(); | ||
} | ||
$(paginationMarkup(totalPages)).insertBefore('.message_table'); | ||
handlePagination(); | ||
refreshNextButton(getParam('list_page') || 1); | ||
refreshPreviousButton(getParam('list_page') || 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters