From 8da25b9781a40a05aa81f9b37522574ad41b13ec Mon Sep 17 00:00:00 2001
From: Remi  PLANEL <rplanel@pasteur.fr>
Date: Tue, 2 Apr 2024 13:23:17 +0200
Subject: [PATCH] use client for serverDbtable

---
 components/ServerDbTable.vue | 17 ++++++++++++++---
 docker-compose.yml           |  2 +-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/components/ServerDbTable.vue b/components/ServerDbTable.vue
index 14eebd3e..5fc47a9c 100644
--- a/components/ServerDbTable.vue
+++ b/components/ServerDbTable.vue
@@ -7,6 +7,7 @@ import { useDisplay } from "vuetify";
 import { useThrottleFn } from '@vueuse/core'
 import type { FacetInputItem, FilterItem } from '@/components/AutocompleteMeiliFacets.vue'
 import { useMeiliSearch } from "#imports"
+import type { SearchResponse } from 'meilisearch'
 // import { saveAs } from "file-saver";
 export interface SortItem {
     key: string,
@@ -55,9 +56,11 @@ const props = withDefaults(defineProps<Props>(), {
     }
 });
 const slots = useSlots()
+const client = useMeiliSearchRef()
 const sortByRef = toRef(props.sortBy)
 const emit = defineEmits(["refresh:search"])
-const { search: msSearch, result: msResult } = useMeiliSearch(props.autocompleteMeiliFacetsProps.db)
+const msResult = ref()
+// const { search: msSearch, result: msResult } = useMeiliSearch(props.autocompleteMeiliFacetsProps.db)
 const search: Ref<string> = ref("");
 const filterOrSearch: Ref<FilterItem[] | null> = ref(null)
 const hitsPerPage: Ref<number> = ref(25)
@@ -118,7 +121,7 @@ watch([paginationParams, msSortBy, page], ([newParams, newSort, newPage]) => {
     }
 })
 
-onBeforeMount(async () => {
+onMounted(async () => {
     searchOrFilter()
     emitRefreshRes()
 })
@@ -214,7 +217,15 @@ async function searchOrFilter() {
         try {
             loading.value = true
             const q = search.value
-            await msSearch(q, { ...paginationParams.value, filter: toValue(computedFilter), sort: msSortBy.value })
+            const response = await client
+                .index(props.autocompleteMeiliFacetsProps.db)
+                .search(q, {
+                    ...paginationParams.value,
+                    filter: toValue(computedFilter),
+                    sort: msSortBy.value
+                })
+            // await msSearch(q, { ...paginationParams.value, filter: toValue(computedFilter), sort: msSortBy.value })
+            msResult.value = response
         } catch (error: any) {
             filterError.value = error
             console.log(error)
diff --git a/docker-compose.yml b/docker-compose.yml
index 6744c4e3..c9ab11ca 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -7,7 +7,7 @@ services:
       args:
         BASE_URL: /wiki
         MEILI_HOST: http://localhost:7700
-        MEILI_API_KEY: f5f5f1bc48e6379fc2509f5bf0aed1fce96c1bbf86e0a194c605b258d7cfe890
+        MEILI_API_KEY: 3534db2924c3938bab5fc878906aaf1b83f8f39867891c6d020b05043b04b1ef
         HOST_URL: http://localhost:8082
     container_name: nuxt
     environment:
-- 
GitLab