From 36b5f74414413e7270d47f52df387697698aeeaf Mon Sep 17 00:00:00 2001
From: Santo Cariotti <santo@dcariotti.me>
Date: Tue, 4 Oct 2022 22:31:35 +0200
Subject: Add pagination

---
 pages/search.vue | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

(limited to 'pages/search.vue')

diff --git a/pages/search.vue b/pages/search.vue
index 1c09e3b..6f448af 100644
--- a/pages/search.vue
+++ b/pages/search.vue
@@ -21,11 +21,13 @@
           :key="model.id"
           :model="model"
         )
+      pagination(:page="page" :pages="pages" v-if="count")
 </template>
 
 <script>
 import ModelLoading from "@/components/ModelLoading.vue";
 import ModelBoxCard from "@/components/ModelBoxCard.vue";
+import Pagination from "@/components/Pagination.vue";
 
 import { mapGetters } from "vuex";
 
@@ -40,20 +42,28 @@ export default {
   data() {
     return {
       q: "",
+      page: 0,
+      pages: 0,
     };
   },
   components: {
     "model-loading": ModelLoading,
     "model-box-card": ModelBoxCard,
+    pagination: Pagination,
   },
   computed: {
     ...mapGetters(["isLoading"]),
     ...mapGetters("auth", ["isLogged"]),
-    ...mapGetters("models", ["models"]),
+    ...mapGetters("models", ["models", "count"]),
   },
   created() {
     this.q = this.$route.query["q"];
-    this.$store.dispatch("models/filter", { q: this.q });
+    this.page = this.$route.query.page ?? 0;
+    this.$store
+      .dispatch("models/filter", { q: this.q, page: this.page })
+      .then(() => {
+        this.pages = Math.ceil(this.count / 20);
+      });
   },
 };
 </script>
-- 
cgit v1.2.3-18-g5258

