From 87f70d16367ddf94948ba68231c45034177ce307 Mon Sep 17 00:00:00 2001
From: "Henrik.Askjer" <henrik.askjer@uib.no>
Date: Mon, 30 Aug 2021 10:23:38 +0200
Subject: [PATCH] Get article IDs

---
 src/components/Autocomplete.vue | 36 +++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/src/components/Autocomplete.vue b/src/components/Autocomplete.vue
index 9e754e4a..f8d07d61 100644
--- a/src/components/Autocomplete.vue
+++ b/src/components/Autocomplete.vue
@@ -61,7 +61,7 @@
 
                                     let hits = []
                                     response.data.forEach((item, i) => {
-                                      let hit = {q: q, match: item[0], label: item[0]}
+                                      let hit = {q: q, match: item[0], label: item[0], articles: []}
                                       hit.lang = item[1]
                                       hits.push(hit)
 
@@ -87,13 +87,36 @@
       select(item) {
         if (item) {
           if (typeof item != 'string') {
-            this.$emit('submit', item)
-            
             let self = this
+            console.log(item.lang)
+            axios.get(self.endpoint + 'articles?', {params: {lord: item.match,
+                                                             dict: item.lang.join(",")}})
+              .then(
+                function(response) {
+                  if (item.articles) {
+                    console.log(item)
+                    ['bob', 'nob'].forEach((dict_tag) => {
+                      alert(dict_tag)
+                      response[dict_tag].forEach((article_id) => {
+                        let article = {}
+                        article.article_id = article_id
+                        article.dictionary = dict_tag
+                        item.articles.push(article)
+
+                      })
+                    })
+                  }
+                  console.log(item)
+
+                  self.$emit('submit', item)
+                  this.items = []
+                  this.suggesting = false
+
+                }
+                )
+
             setTimeout(() => {
               self.$refs.autocomplete.$refs.input.select()
-              this.items = []
-              this.suggesting = false
               }, 1)
           }
           // If blurred
@@ -115,7 +138,8 @@
           }
         }
         this.debounced(q, this)
-      }
+      },
+
     },
   }
 </script>
-- 
GitLab