From b25e3ed3643d17fd9a97eb52f2a248d4fba3b5fc Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 14 Apr 2024 16:19:46 -0400 Subject: [PATCH] refac --- src/lib/components/common/Pagination.svelte | 42 +++ src/lib/components/common/Paginator.svelte | 254 ------------------- src/lib/components/icons/ChevronLeft.svelte | 15 ++ src/lib/components/icons/ChevronRight.svelte | 15 ++ src/routes/(app)/admin/+page.svelte | 42 ++- 5 files changed, 87 insertions(+), 281 deletions(-) create mode 100644 src/lib/components/common/Pagination.svelte delete mode 100644 src/lib/components/common/Paginator.svelte create mode 100644 src/lib/components/icons/ChevronLeft.svelte create mode 100644 src/lib/components/icons/ChevronRight.svelte diff --git a/src/lib/components/common/Pagination.svelte b/src/lib/components/common/Pagination.svelte new file mode 100644 index 00000000..9658e0d1 --- /dev/null +++ b/src/lib/components/common/Pagination.svelte @@ -0,0 +1,42 @@ + + +
+ +
+ + + +
+ {#each pages as page (page.key)} + {#if page.type === 'ellipsis'} +
...
+ {:else} + + {page.value} + + {/if} + {/each} +
+ + + +
+
+
diff --git a/src/lib/components/common/Paginator.svelte b/src/lib/components/common/Paginator.svelte deleted file mode 100644 index dd5c5296..00000000 --- a/src/lib/components/common/Paginator.svelte +++ /dev/null @@ -1,254 +0,0 @@ - - -
- - {#if settings.amounts.length} - - {/if} - -
- - {#if showFirstLastButtons} - - {/if} - - {#if showPreviousNextButtons} - - {/if} - - {#if showNumerals === false} - - - {:else} - - {#each controlPages as page} - - {/each} - {/if} - - {#if showPreviousNextButtons} - - {/if} - - {#if showFirstLastButtons} - - {/if} -
-
diff --git a/src/lib/components/icons/ChevronLeft.svelte b/src/lib/components/icons/ChevronLeft.svelte new file mode 100644 index 00000000..78ee64d2 --- /dev/null +++ b/src/lib/components/icons/ChevronLeft.svelte @@ -0,0 +1,15 @@ + + + + + diff --git a/src/lib/components/icons/ChevronRight.svelte b/src/lib/components/icons/ChevronRight.svelte new file mode 100644 index 00000000..7daf4a14 --- /dev/null +++ b/src/lib/components/icons/ChevronRight.svelte @@ -0,0 +1,15 @@ + + + + + diff --git a/src/routes/(app)/admin/+page.svelte b/src/routes/(app)/admin/+page.svelte index 6d153d8a..a3493cb6 100644 --- a/src/routes/(app)/admin/+page.svelte +++ b/src/routes/(app)/admin/+page.svelte @@ -12,7 +12,7 @@ import { getSignUpEnabledStatus, toggleSignUpEnabledStatus } from '$lib/apis/auths'; import EditUserModal from '$lib/components/admin/EditUserModal.svelte'; import SettingsModal from '$lib/components/admin/SettingsModal.svelte'; - import Paginator from '$lib/components/common/Paginator.svelte'; + import Pagination from '$lib/components/common/Pagination.svelte'; const i18n = getContext('i18n'); @@ -22,16 +22,11 @@ let search = ''; let selectedUser = null; + let page = 1; + let showSettingsModal = false; let showEditUserModal = false; - let paginatorSettings = { - page: 0, - limit: 5, - size: users.length, - amounts: [5, 10, 15, 20] - }; - const updateRoleHandler = async (id, role) => { const res = await updateUserRole(localStorage.token, id, role).catch((error) => { toast.error(error); @@ -72,23 +67,6 @@ } loaded = true; }); - - $: paginatedSource = users - .filter((user) => { - if (search === '') { - return true; - } else { - let name = user.name.toLowerCase(); - const query = search.toLowerCase(); - return name.includes(query); - } - }) - .slice( - paginatorSettings.page * paginatorSettings.limit, - paginatorSettings.page * paginatorSettings.limit + paginatorSettings.limit - ); - - $: paginatorSettings.size = users.length; @@ -184,7 +162,17 @@ - {#each paginatedSource as user} + {#each users + .filter((user) => { + if (search === '') { + return true; + } else { + let name = user.name.toLowerCase(); + const query = search.toLowerCase(); + return name.includes(query); + } + }) + .slice((page - 1) * 20, page * 20) as user}