From 2325d12395e0a7e7f944165e7de4d9e88915b4d6 Mon Sep 17 00:00:00 2001
From: Santo Cariotti <santo@dcariotti.me>
Date: Thu, 13 Oct 2022 22:35:20 +0200
Subject: Add pagination on admin cp

---
 pages/admin/index.vue | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

(limited to 'pages/admin/index.vue')

diff --git a/pages/admin/index.vue b/pages/admin/index.vue
index 679f82f..e08f819 100644
--- a/pages/admin/index.vue
+++ b/pages/admin/index.vue
@@ -10,12 +10,14 @@
           :fields="users"
           path="/users/"
         )
+        pagination(:page="page" :pages="pages" v-if="count" path="/admin")
 </template>
 
 <script>
 import { mapGetters } from "vuex";
 
 import AdminSidebar from "@/components/AdminSidebar.vue";
+import Pagination from "@/components/Pagination.vue";
 import VTable from "@/components/VTable.vue";
 
 export default {
@@ -23,9 +25,19 @@ export default {
   head: { title: "Admin panel · Verden" },
   computed: {
     ...mapGetters("auth", ["isLogged", "me"]),
-    ...mapGetters("users", ["users"]),
+    ...mapGetters("users", ["users", "count"]),
+  },
+  data() {
+    return {
+      page: 0,
+      pages: 0,
+    };
+  },
+  components: {
+    AdminSidebar,
+    pagination: Pagination,
+    "v-table": VTable,
   },
-  components: { AdminSidebar, "v-table": VTable },
   async mounted() {
     await this.$store.dispatch("auth/findMe");
 
@@ -33,7 +45,10 @@ export default {
       window.location.href = "/";
     }
 
-    this.$store.dispatch("users/getUsers", { page: 0 });
+    this.page = this.$route.query.page ?? 0;
+    this.$store.dispatch("users/getUsers", this.page).then(() => {
+      this.pages = Math.ceil(this.count / 20);
+    });
   },
 };
 </script>
-- 
cgit v1.2.3-18-g5258

