Skip to content

A self-hosted media server and file management system

enable pagination

aminnausin96c2284db19e
diff --git a/resources/js/components/VideoTable.vue b/resources/js/components/VideoTable.vue
index 2c979070..b7ee27d1 100644
--- a/resources/js/components/VideoTable.vue
+++ b/resources/js/components/VideoTable.vue
@@ -4,14 +4,21 @@ import LabelledTextInput from './inputs/LabelledTextInput.vue';
import { useContentStore } from '../stores/ContentStore';
import { storeToRefs } from 'pinia';
-import { ref } from 'vue';
+import { computed, ref } from 'vue';
import TablePagination from './table/TablePagination.vue';
const ContentStore = useContentStore();
const { searchQuery, stateFilteredPlaylist, stateVideo } = storeToRefs(ContentStore);
const { playlistFind } = ContentStore;
+
const currentPage = ref(1);
+const itemsPerPage = ref(10);
+const filteredPage = computed(() => {
+ const minIndex = itemsPerPage.value * (currentPage.value - 1) + 1;
+ const maxIndex = Math.min(itemsPerPage.value * (currentPage.value), stateFilteredPlaylist.value.length);
+ return stateFilteredPlaylist.value.slice(minIndex, maxIndex);
+});
const handlePageChange = (page) => {
currentPage.value = page;
@@ -47,9 +54,7 @@ const tableColumnGroups = [
</thead>
<tbody
class="flex w-full flex-wrap gap-2">
- <!-- <VideoCard v-for="(video, index) in stateFilteredPlaylist.slice(videosPerPage * currentPage - videosPerPage, Math.min(videosPerPage * currentPage, stateFilteredPlaylist.length))" :key="index" :video="video" :index="index"
- :currentID="stateVideo.id" @playByID="playlistFind" /> -->
- <VideoCard v-for="(video, index) in stateFilteredPlaylist" :key="index" :video="video" :index="index"
+ <VideoCard v-for="(video, index) in filteredPage" :key="index" :video="video" :index="index"
:currentID="stateVideo?.id" @playByID="playlistFind" />
</tbody>
<hr >
@@ -68,6 +73,6 @@ const tableColumnGroups = [
</button>
</div>
</section> -->
- <TablePagination :listLength="stateFilteredPlaylist?.length ?? 0" :currentPage="currentPage" @setPage="handlePageChange"/>
+ <TablePagination :listLength="stateFilteredPlaylist?.length ?? 0" :itemsPerPage="itemsPerPage" :currentPage="currentPage" @setPage="handlePageChange"/>
</table>
</template>
\ No newline at end of file
diff --git a/resources/js/components/table/TablePagination.vue b/resources/js/components/table/TablePagination.vue
index f8ea80a2..e5db864d 100644
--- a/resources/js/components/table/TablePagination.vue
+++ b/resources/js/components/table/TablePagination.vue
@@ -1,19 +1,18 @@
<script setup>
-import { computed, ref } from 'vue';
+import { computed } from 'vue';
import TablePaginationButton from './TablePaginationButton.vue';
-const props = defineProps(['listLength', 'currentPage']);
-const itemsPerPage = ref(5);
-const pageCount = computed(() => { return Math.ceil(props.listLength / itemsPerPage.value); });
+const props = defineProps(['listLength', 'currentPage', 'itemsPerPage']);
+const pageCount = computed(() => { return Math.ceil(props.listLength / props.itemsPerPage); });
</script>
<template>
<div class="flex items-center flex-col sm:flex-row sm:justify-between flex-wrap gap-2">
<p class="text-gray-700 dark:text-neutral-100 line-clamp-1">
Showing
- <span class="font-medium">{{ itemsPerPage * (currentPage - 1) + 1 }}</span>
+ <span class="font-medium">{{ props.itemsPerPage * (currentPage - 1) + 1 }}</span>
to
- <span class="font-medium">{{ Math.min(itemsPerPage * (currentPage), props.listLength) }}</span>
+ <span class="font-medium">{{ Math.min(props.itemsPerPage * (currentPage), props.listLength) }}</span>
of
<span class="font-medium">{{ listLength }}</span>
Results