feat: show errors, sort tags
This commit is contained in:
@@ -70,6 +70,7 @@
|
|||||||
<label class="label">Search By Name</label>
|
<label class="label">Search By Name</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input ref="name" class="input" type="text" placeholder="Text input">
|
<input ref="name" class="input" type="text" placeholder="Text input">
|
||||||
|
<p v-if="error.length" class="help is-danger">{{error}}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -168,6 +169,12 @@
|
|||||||
// mitt = window.mitt
|
// mitt = window.mitt
|
||||||
(function ({ mitt, lunr }, data) {
|
(function ({ mitt, lunr }, data) {
|
||||||
const emitter = mitt();
|
const emitter = mitt();
|
||||||
|
const stringAscending = (a, b) => {
|
||||||
|
const aa = a.toLowerCase();
|
||||||
|
const bb = b.toLowerCase();
|
||||||
|
if (aa === bb) return 0;
|
||||||
|
return aa < bb ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
const getMultiValues = node => Array.from(node.selectedOptions).map(o => o.value);
|
const getMultiValues = node => Array.from(node.selectedOptions).map(o => o.value);
|
||||||
@@ -233,12 +240,16 @@
|
|||||||
el: '#search-form',
|
el: '#search-form',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
effects: data.effects,
|
effects: data.effects.sort(stringAscending),
|
||||||
uses: data.uses,
|
uses: data.uses.sort(stringAscending),
|
||||||
conditions: data.conditions,
|
conditions: data.conditions.sort(stringAscending),
|
||||||
flavors: data.flavors,
|
flavors: data.flavors.sort(stringAscending),
|
||||||
|
error: '',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
emitter.on('error', msg => this.error = msg);
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleSubmit() {
|
handleSubmit() {
|
||||||
const requirements = {
|
const requirements = {
|
||||||
@@ -249,6 +260,7 @@
|
|||||||
flavors: getMultiValues(this.$refs.flavors),
|
flavors: getMultiValues(this.$refs.flavors),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.error = '';
|
||||||
emitter.emit('search', requirements);
|
emitter.emit('search', requirements);
|
||||||
},
|
},
|
||||||
resetForm() {
|
resetForm() {
|
||||||
@@ -317,6 +329,7 @@
|
|||||||
this.requirements.conditions.forEach(t => searchParts.push(`+conditions:${t}`));
|
this.requirements.conditions.forEach(t => searchParts.push(`+conditions:${t}`));
|
||||||
this.requirements.flavors.forEach(t => searchParts.push(`+flavors:${t}`));
|
this.requirements.flavors.forEach(t => searchParts.push(`+flavors:${t}`));
|
||||||
|
|
||||||
|
try {
|
||||||
const hits = this.idx
|
const hits = this.idx
|
||||||
.search(searchParts.join(' '))
|
.search(searchParts.join(' '))
|
||||||
// .slice(0, limit);
|
// .slice(0, limit);
|
||||||
@@ -337,6 +350,10 @@
|
|||||||
}
|
}
|
||||||
return a.score > b.score ? -1 : 1;
|
return a.score > b.score ? -1 : 1;
|
||||||
});
|
});
|
||||||
|
} catch(err) {
|
||||||
|
this.strains = [];
|
||||||
|
emitter.emit('error', err.message);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user