aboutsummaryrefslogtreecommitdiff
path: root/src/site/components
diff options
context:
space:
mode:
authorZephyrrus <[email protected]>2020-07-23 04:08:31 +0300
committerZephyrrus <[email protected]>2020-07-23 04:08:31 +0300
commit39e9941ded8de4e41048781daa80de0838c01c19 (patch)
tree13893d6bfbd34f59076278561bfd1de50e9dd018 /src/site/components
parentfeat: add new search input (diff)
downloadhost.fuwn.me-39e9941ded8de4e41048781daa80de0838c01c19.tar.xz
host.fuwn.me-39e9941ded8de4e41048781daa80de0838c01c19.zip
feat: Add hiding to recommendations as a prop
fix: change some of the regexes to remove , and ; as separator support because the query parser doesn't understad them and I don't feel like dealing with all the edge cases introduces by it
Diffstat (limited to 'src/site/components')
-rw-r--r--src/site/components/search/Search.vue35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/site/components/search/Search.vue b/src/site/components/search/Search.vue
index 57226a9..72a5707 100644
--- a/src/site/components/search/Search.vue
+++ b/src/site/components/search/Search.vue
@@ -12,7 +12,8 @@
placeholder="Search"
type="search"
open-on-focus
- @typing="handleTyping">
+ @typing="handleTyping"
+ @keydown.native.enter="onSubmit">
<template slot-scope="props">
<b>{{ props.option.name }}:</b>
<small>
@@ -37,6 +38,12 @@ export default {
components: {
SearchInput,
},
+ props: {
+ hiddenHints: {
+ type: Array,
+ default: () => [],
+ },
+ },
data() {
return {
query: '',
@@ -66,11 +73,17 @@ export default {
'valueFormat': 'specific date',
'hint': '',
},
+ {
+ 'name': 'file',
+ 'valueFormat': 'generated name',
+ 'hint': '',
+ },
],
filteredHints: [],
};
},
created() {
+ this.hints = this.hints.filter(({ name }) => this.hiddenHints.indexOf(name) === -1);
this.filteredHints = this.hints; // fixes the issue where on pageload, suggestions wont load
},
methods: {
@@ -83,15 +96,19 @@ export default {
handleTyping(qry) {
qry = qry || '';
// get the last word or group of words
- const lastWord = (qry.match(/("[^"]*")|[^;, ]+/g) || ['']).pop().toLowerCase();
+ let lastWord = (qry.match(/("[^"]*")|[^\s]+/g) || ['']).pop().toLowerCase();
// if there's an open/unbalanced quote, don't autosuggest
if (/^[^"]*("[^"]*"[^"]*)*(")[^"]*$/.test(qry)) { this.filteredHints = []; return; }
// don't autosuggest if we have an open query but no text yet
- if (/:[\s|;|,]?$/gi.test(qry)) { this.filteredHints = []; return; }
+ if (/:\s+$/gi.test(qry)) { this.filteredHints = []; return; }
// if the above query didn't match (all quotes are balanced
// and the previous tag has value
// check if we're about to start a new tag
- if (/[\s|;|,]+$/gi.test(qry)) { this.filteredHints = this.hints; return; }
+ if (/\s+$/gi.test(qry)) { this.filteredHints = this.hints; return; }
+
+ // ignore starting `-` from lastword, because - is used to
+ // exclude something, so -alb should autosuggest album
+ lastWord = lastWord.replace(/^-/, '');
// if we got here, then we handled all special cases
// now take last word, and check if we can autosuggest a tag
@@ -100,11 +117,11 @@ export default {
.toLowerCase()
.indexOf(lastWord) === 0);
},
- sanitizeQuery(qry) {
- // \w+:\s+? to transform 'tag: 123' into 'tag:123'
- },
- onSubmit() {
- this.$emit('search', this.query);
+ onSubmit(event) {
+ if (event.key === 'Enter') {
+ if (/:$/gi.test(this.query)) { return; }
+ }
+ this.$emit('search', this.query, event);
},
},
};