Skip to content
Snippets Groups Projects
Commit 3f98378e authored by Henrik Askjer's avatar Henrik Askjer
Browse files

Merge branch 'fix_missing_dropdown_on_slow_connection' into 'master'

Use timestamp to evaluate the need for verbatim suggestion

See merge request spraksamlingane/beta.ordbok.uib.no!59
parents 138b0433 6aa71596
No related branches found
No related tags found
No related merge requests found
......@@ -52,10 +52,11 @@
},
watch: {
search (val) {
const time = Date.now()
if (! val) {
this.items = []
} else {
this.run_query(val)
this.run_query(val, time)
}
},
select(item) {
......@@ -81,17 +82,17 @@
}
},
methods: {
run_query(q) {
run_query(q, time) {
this.suggesting = true
// Keep full text search in the list while requesting suggestions
if (this.items[0]) {
if (this.items[0].lang) {
this.items.unshift({q: q, label: q})
}
else {
this.items[0] = {q: q, label: q}
if (this.items[0].time < time) {
this.items.splice(0,1, {q: q, label: q, time: time})
}
}
else {
this.items.push({q: q, label: q, time: time})
}
let self = this
self.api.get('suggest?', {params: {q: q, dict: self.$parent.lang, n: 9}})
.then(async (response) => {
......@@ -100,7 +101,7 @@
let hits = []
response.data.forEach((item, i) => {
let match = item[0]
let hit = {q: q, match: match, label: match}
let hit = {q: q, match: match, label: match, time: time}
hit.article_promise = self.api.get('articles?', {params: {lord: match, dict: self.$parent.lang}})
......@@ -109,7 +110,7 @@
});
// whitespace necessary because duplicates aren't allowed in the dropdown
hits.push({q: q, label: q + ' '})
hits.push({q: q, label: q + ' ', time: time})
self.items = hits
}
self.loading = false
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment