2020-06-29 18:23:56 +00:00
|
|
|
<template>
|
|
|
|
<header id="search">
|
|
|
|
<div class="search__icon">
|
|
|
|
<i class="material-icons">search</i>
|
|
|
|
</div>
|
|
|
|
<input
|
|
|
|
id="searchbar"
|
|
|
|
autocomplete="off"
|
|
|
|
type="search"
|
|
|
|
name="searchbar"
|
|
|
|
value=""
|
2020-07-18 20:44:27 +00:00
|
|
|
:placeholder="$t('searchbar')"
|
2020-06-29 18:23:56 +00:00
|
|
|
autofocus
|
2020-07-06 19:55:28 +00:00
|
|
|
ref="searchbar"
|
2020-09-16 16:59:25 +00:00
|
|
|
@keyup="handleSearchBarKeyup($event)"
|
2020-06-29 18:23:56 +00:00
|
|
|
/>
|
2020-09-16 16:59:25 +00:00
|
|
|
<!-- @keyup.enter.exact="onEnter"
|
|
|
|
@keyup.ctrl.enter="onCTRLEnter" -->
|
2020-06-29 18:23:56 +00:00
|
|
|
</header>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-07-16 22:11:28 +00:00
|
|
|
import { isValidURL } from '@/utils/utils'
|
|
|
|
import Downloads from '@/utils/downloads'
|
2020-07-14 20:27:48 +00:00
|
|
|
|
2020-07-16 22:11:28 +00:00
|
|
|
import EventBus from '@/utils/EventBus.js'
|
|
|
|
import { socket } from '@/utils/socket'
|
2020-07-06 19:55:28 +00:00
|
|
|
|
|
|
|
export default {
|
2020-09-15 20:44:29 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
lastTextSearch: ''
|
|
|
|
}
|
|
|
|
},
|
2020-07-06 19:55:28 +00:00
|
|
|
methods: {
|
2020-09-16 16:59:25 +00:00
|
|
|
test() {
|
|
|
|
console.log('test passato')
|
|
|
|
},
|
2020-09-15 20:44:29 +00:00
|
|
|
async handleSearchBarKeyup(keyEvent) {
|
|
|
|
let isEnterPressed = keyEvent.keyCode === 13
|
|
|
|
|
|
|
|
// If not enter do nothing
|
|
|
|
if (!isEnterPressed) return
|
2020-07-06 19:55:28 +00:00
|
|
|
|
|
|
|
let term = this.$refs.searchbar.value
|
2020-09-15 20:44:29 +00:00
|
|
|
let isEmptySearch = term === ''
|
|
|
|
|
|
|
|
// If empty do nothing
|
|
|
|
if (isEmptySearch) return
|
|
|
|
|
|
|
|
let isSearchingURL = isValidURL(term)
|
|
|
|
let isCtrlPressed = keyEvent.ctrlKey
|
|
|
|
let isShowingAnalyzer = this.$route.name === 'Link Analyzer'
|
|
|
|
let isShowingSearch = this.$route.name === 'Search'
|
|
|
|
let sameAsLastSearch = term === this.lastTextSearch
|
2020-07-06 19:55:28 +00:00
|
|
|
|
2020-09-15 20:44:29 +00:00
|
|
|
if (isSearchingURL) {
|
|
|
|
if (isCtrlPressed) {
|
2020-07-06 19:55:28 +00:00
|
|
|
this.$root.$emit('QualityModal:open', term)
|
|
|
|
} else {
|
2020-09-15 20:44:29 +00:00
|
|
|
if (isShowingAnalyzer) {
|
2020-07-14 20:27:48 +00:00
|
|
|
EventBus.$emit('linkAnalyzerTab:reset')
|
|
|
|
socket.emit('analyzeLink', term)
|
2020-07-06 19:55:28 +00:00
|
|
|
} else {
|
2020-09-15 20:44:29 +00:00
|
|
|
// ? Open downloads tab ?
|
2020-07-06 19:55:28 +00:00
|
|
|
Downloads.sendAddToQueue(term)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2020-09-15 20:44:29 +00:00
|
|
|
if (isShowingSearch && sameAsLastSearch) return
|
|
|
|
|
|
|
|
if (!isShowingSearch) {
|
|
|
|
await this.$router.push({
|
|
|
|
name: 'Search'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sameAsLastSearch) {
|
|
|
|
this.$root.$emit('updateSearchLoadingState', true)
|
|
|
|
this.lastTextSearch = term
|
|
|
|
}
|
2020-07-06 19:55:28 +00:00
|
|
|
|
2020-09-15 20:44:29 +00:00
|
|
|
this.$root.$emit('mainSearch:showNewResults', term, window.main_selected)
|
2020-07-06 19:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-29 18:23:56 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
</style>
|