[web-src] Use prefix to search by expression

Fixes inconsistency in searching by recent search term, improves
usability if switching between search by query and search by expression.
Ignores searches by expression when switching to Spotify search.
This commit is contained in:
chme 2020-04-11 20:32:03 +02:00
parent 52d37b883c
commit 4dac88ca1a
2 changed files with 12 additions and 11 deletions

View File

@ -13,14 +13,11 @@
<i class="mdi mdi-magnify"></i> <i class="mdi mdi-magnify"></i>
</span> </span>
</p> </p>
<p class="help has-text-centered">Tip: you can search by a smart playlist query language <a href="https://github.com/ejurgensen/forked-daapd/blob/master/README_SMARTPL.md" target="_blank">expression</a> if you prefix it
with <code>query:</code>.
</p>
</div> </div>
</form> </form>
<div>
<label class="checkbox is-size-7">
<input type="checkbox" v-model="smart_query" :checked=true>
SMART query
</label>
</div>
<div class="tags" style="margin-top: 16px;"> <div class="tags" style="margin-top: 16px;">
<a class="tag" v-for="recent_search in recent_searches" :key="recent_search" @click="open_recent_search(recent_search)">{{ recent_search }}</a> <a class="tag" v-for="recent_search in recent_searches" :key="recent_search" @click="open_recent_search(recent_search)">{{ recent_search }}</a>
</div> </div>
@ -154,7 +151,7 @@ export default {
data () { data () {
return { return {
search_query: '', search_query: '',
smart_query: false,
tracks: { items: [], total: 0 }, tracks: { items: [], total: 0 },
artists: { items: [], total: 0 }, artists: { items: [], total: 0 },
albums: { items: [], total: 0 }, albums: { items: [], total: 0 },
@ -218,11 +215,15 @@ export default {
var searchParams = { var searchParams = {
type: route.query.type, type: route.query.type,
query: this.smart_query ? undefined : route.query.query,
expression: this.smart_query ? route.query.query : undefined,
media_kind: 'music' media_kind: 'music'
} }
if (route.query.query.startsWith('query:')) {
searchParams.expression = route.query.query.replace(/^query:/, '').trim()
} else {
searchParams.query = route.query.query
}
if (route.query.limit) { if (route.query.limit) {
searchParams.limit = route.query.limit searchParams.limit = route.query.limit
searchParams.offset = route.query.offset searchParams.offset = route.query.offset

View File

@ -178,7 +178,7 @@ export default {
computed: { computed: {
recent_searches () { recent_searches () {
return this.$store.state.recent_searches return this.$store.state.recent_searches.filter(search => !search.startsWith('query:'))
}, },
show_tracks () { show_tracks () {
@ -222,7 +222,7 @@ export default {
this.reset() this.reset()
// If no search query present reset and focus search field // If no search query present reset and focus search field
if (!this.query.query || this.query.query === '') { if (!this.query.query || this.query.query === '' || this.query.query.startsWith('query:')) {
this.search_query = '' this.search_query = ''
this.$refs.search_field.focus() this.$refs.search_field.focus()
return return