2020-06-29 18:23:56 +00:00
|
|
|
<template>
|
2020-09-23 15:25:27 +00:00
|
|
|
<header id="search" aria-label="searchbar">
|
2020-06-29 18:23:56 +00:00
|
|
|
<div class="search__icon">
|
|
|
|
<i class="material-icons">search</i>
|
|
|
|
</div>
|
2020-10-16 21:02:34 +00:00
|
|
|
|
2020-06-29 18:23:56 +00:00
|
|
|
<input
|
|
|
|
id="searchbar"
|
2020-10-16 21:02:34 +00:00
|
|
|
class="w-full"
|
2020-06-29 18:23:56 +00:00
|
|
|
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-17 21:55:57 +00:00
|
|
|
@keyup="handleSearchBarKeyup($event)"
|
2020-06-29 18:23:56 +00:00
|
|
|
/>
|
2020-09-17 21:55:57 +00:00
|
|
|
<!-- @keyup.enter.exact="onEnter"
|
2020-09-16 16:59:25 +00:00
|
|
|
@keyup.ctrl.enter="onCTRLEnter" -->
|
2020-06-29 18:23:56 +00:00
|
|
|
</header>
|
|
|
|
</template>
|
|
|
|
|
2020-09-26 19:48:55 +00:00
|
|
|
<style lang="scss">
|
|
|
|
$icon-dimension: 2rem;
|
|
|
|
$searchbar-height: 45px;
|
|
|
|
|
|
|
|
#search {
|
|
|
|
background-color: var(--secondary-background);
|
|
|
|
padding: 0 1em;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
border: 1px solid transparent;
|
|
|
|
transition: border 200ms ease-in-out;
|
|
|
|
border-radius: 15px;
|
|
|
|
margin: 10px 10px 20px 10px;
|
|
|
|
|
|
|
|
&:focus-within {
|
|
|
|
border: 1px solid var(--foreground);
|
|
|
|
}
|
|
|
|
|
|
|
|
.search__icon {
|
|
|
|
width: $icon-dimension;
|
|
|
|
height: $icon-dimension;
|
|
|
|
|
|
|
|
i {
|
|
|
|
font-size: $icon-dimension;
|
|
|
|
color: var(--foreground);
|
2020-10-14 20:18:13 +00:00
|
|
|
|
|
|
|
&::selection {
|
|
|
|
background: none;
|
|
|
|
}
|
2020-09-26 19:48:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#searchbar {
|
|
|
|
height: $searchbar-height;
|
|
|
|
padding-left: 0.5em;
|
|
|
|
border: 0px;
|
|
|
|
border-radius: 0px;
|
|
|
|
background-color: var(--secondary-background);
|
|
|
|
color: var(--foreground);
|
|
|
|
font-size: 1.2rem;
|
|
|
|
font-family: 'Open Sans';
|
|
|
|
font-weight: 300;
|
|
|
|
margin-bottom: 0;
|
|
|
|
|
|
|
|
&:focus {
|
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Removing Chrome autofill color
|
|
|
|
&:-webkit-autofill,
|
|
|
|
&:-webkit-autofill:hover,
|
|
|
|
&:-webkit-autofill:focus,
|
|
|
|
&:-webkit-autofill:active {
|
|
|
|
-webkit-box-shadow: 0 0 0 $searchbar-height var(--secondary-background) inset !important;
|
|
|
|
box-shadow: 0 0 0 $searchbar-height var(--secondary-background) inset !important;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2020-06-29 18:23:56 +00:00
|
|
|
<script>
|
2020-07-16 22:11:28 +00:00
|
|
|
import { isValidURL } from '@/utils/utils'
|
2020-09-26 15:53:25 +00:00
|
|
|
import { sendAddToQueue } from '@/utils/downloads'
|
|
|
|
import EventBus from '@/utils/EventBus'
|
2020-07-16 22:11:28 +00:00
|
|
|
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-09-26 15:53:25 +00:00
|
|
|
created() {
|
|
|
|
const focusSearchBar = keyEvent => {
|
|
|
|
if (keyEvent.keyCode === 70 && keyEvent.ctrlKey) {
|
|
|
|
keyEvent.preventDefault()
|
|
|
|
this.$refs.searchbar.focus()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const deleteSearchBarContent = keyEvent => {
|
2020-09-23 15:02:26 +00:00
|
|
|
if (!(keyEvent.key == 'Backspace' && keyEvent.ctrlKey && keyEvent.shiftKey)) return
|
2020-09-17 21:55:57 +00:00
|
|
|
|
|
|
|
this.$refs.searchbar.value = ''
|
|
|
|
this.$refs.searchbar.focus()
|
2020-09-26 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('keydown', focusSearchBar)
|
|
|
|
document.addEventListener('keyup', deleteSearchBarContent)
|
|
|
|
|
|
|
|
this.$on('hook:destroyed', () => {
|
|
|
|
document.removeEventListener('keydown', focusSearchBar)
|
|
|
|
document.removeEventListener('keyup', deleteSearchBarContent)
|
2020-09-17 21:55:57 +00:00
|
|
|
})
|
|
|
|
},
|
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-09-19 12:20:15 +00:00
|
|
|
// EventBus.$emit('linkAnalyzerTab:reset')
|
2020-07-14 20:27:48 +00:00
|
|
|
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-09-26 15:53:25 +00:00
|
|
|
sendAddToQueue(term)
|
2020-07-06 19:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2020-09-26 15:53:25 +00:00
|
|
|
if (isShowingSearch && sameAsLastSearch) {
|
2020-09-24 13:14:47 +00:00
|
|
|
this.$root.$emit('mainSearch:updateResults', term)
|
2020-09-24 11:48:37 +00:00
|
|
|
return
|
|
|
|
}
|
2020-09-15 20:44:29 +00:00
|
|
|
|
|
|
|
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-26 17:48:30 +00:00
|
|
|
this.$root.$emit('mainSearch:showNewResults', term)
|
2020-07-06 19:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-29 18:23:56 +00:00
|
|
|
</script>
|
|
|
|
|
2020-09-26 19:48:55 +00:00
|
|
|
|