2019-03-09 05:51:02 +00:00
|
|
|
<template lang="pug">
|
2019-11-02 20:04:43 +00:00
|
|
|
.search-results(v-if='searchIsFocused || (search && search.length > 1)')
|
2019-03-09 05:51:02 +00:00
|
|
|
.search-results-container
|
2019-11-23 21:35:34 +00:00
|
|
|
.search-results-help(v-if='!search || (search && search.length < 2)')
|
2020-05-15 21:05:11 +00:00
|
|
|
img(src='/_assets/svg/icon-search-alt.svg')
|
2019-06-11 01:31:32 +00:00
|
|
|
.mt-4 {{$t('common:header.searchHint')}}
|
2019-11-02 20:04:43 +00:00
|
|
|
.search-results-loader(v-else-if='searchIsLoading && (!results || results.length < 1)')
|
2019-03-09 05:51:02 +00:00
|
|
|
orbit-spinner(
|
|
|
|
:animation-duration='1000'
|
|
|
|
:size='100'
|
|
|
|
color='#FFF'
|
|
|
|
)
|
2019-06-11 01:31:32 +00:00
|
|
|
.headline.mt-5 {{$t('common:header.searchLoading')}}
|
2019-11-02 20:04:43 +00:00
|
|
|
.search-results-none(v-else-if='!searchIsLoading && (!results || results.length < 1)')
|
2020-05-15 21:05:11 +00:00
|
|
|
img(src='/_assets/svg/icon-no-results.svg', alt='No Results')
|
2019-06-11 01:31:32 +00:00
|
|
|
.subheading {{$t('common:header.searchNoResult')}}
|
2019-11-02 20:04:43 +00:00
|
|
|
template(v-if='results && results.length > 0')
|
2019-06-11 01:31:32 +00:00
|
|
|
v-subheader.white--text {{$t('common:header.searchResultsCount', { total: response.totalHits })}}
|
2020-02-01 20:17:29 +00:00
|
|
|
v-list.search-results-items.radius-7.py-0(two-line, dense)
|
2019-03-09 05:51:02 +00:00
|
|
|
template(v-for='(item, idx) of results')
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item(@click='goToPage(item)', :key='item.id', :class='idx === cursor ? `highlighted` : ``')
|
|
|
|
v-list-item-avatar(tile)
|
2020-05-15 21:05:11 +00:00
|
|
|
img(src='/_assets/svg/icon-selective-highlighting.svg')
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-content
|
2020-10-23 22:49:25 +00:00
|
|
|
v-list-item-title(v-text='item.title')
|
|
|
|
v-list-item-subtitle.caption(v-text='item.description')
|
|
|
|
.caption.grey--text(v-text='item.path')
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-action
|
|
|
|
v-chip(label, outlined) {{item.locale.toUpperCase()}}
|
2019-03-09 05:51:02 +00:00
|
|
|
v-divider(v-if='idx < results.length - 1')
|
|
|
|
v-pagination.mt-3(
|
|
|
|
v-if='paginationLength > 1'
|
|
|
|
dark
|
|
|
|
v-model='pagination'
|
|
|
|
:length='paginationLength'
|
2020-02-01 20:17:29 +00:00
|
|
|
circle
|
2019-03-09 05:51:02 +00:00
|
|
|
)
|
2019-11-02 20:04:43 +00:00
|
|
|
template(v-if='suggestions && suggestions.length > 0')
|
2019-06-11 01:31:32 +00:00
|
|
|
v-subheader.white--text.mt-3 {{$t('common:header.searchDidYouMean')}}
|
2019-03-10 06:28:58 +00:00
|
|
|
v-list.search-results-suggestions.radius-7(dense, dark)
|
2019-03-09 05:51:02 +00:00
|
|
|
template(v-for='(term, idx) of suggestions')
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item(:key='term', @click='setSearchTerm(term)', :class='idx + results.length === cursor ? `highlighted` : ``')
|
|
|
|
v-list-item-avatar
|
|
|
|
v-icon mdi-magnify
|
|
|
|
v-list-item-content
|
2020-10-23 22:49:25 +00:00
|
|
|
v-list-item-title(v-text='term')
|
2019-03-09 05:51:02 +00:00
|
|
|
v-divider(v-if='idx < suggestions.length - 1')
|
2019-11-02 20:04:43 +00:00
|
|
|
.text-xs-center.pt-5(v-if='search && search.length > 1')
|
2019-08-25 18:23:56 +00:00
|
|
|
//- v-btn.mx-2(outlined, color='orange', @click='search = ``', v-if='results.length > 0')
|
|
|
|
//- v-icon(left) mdi-content-save
|
|
|
|
//- span {{$t('common:header.searchCopyLink')}}
|
2019-07-29 04:50:03 +00:00
|
|
|
v-btn.mx-2(outlined, color='pink', @click='search = ``')
|
|
|
|
v-icon(left) mdi-close
|
2019-06-11 01:31:32 +00:00
|
|
|
span {{$t('common:header.searchClose')}}
|
2019-03-09 05:51:02 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import _ from 'lodash'
|
2019-03-19 18:46:10 +00:00
|
|
|
import { sync } from 'vuex-pathify'
|
2019-03-09 05:51:02 +00:00
|
|
|
import { OrbitSpinner } from 'epic-spinners'
|
|
|
|
|
|
|
|
import searchPagesQuery from 'gql/common/common-pages-query-search.gql'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
OrbitSpinner
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2019-03-10 06:28:58 +00:00
|
|
|
cursor: 0,
|
2019-03-09 05:51:02 +00:00
|
|
|
pagination: 1,
|
2020-02-01 20:17:29 +00:00
|
|
|
perPage: 10,
|
2019-03-09 05:51:02 +00:00
|
|
|
response: {
|
|
|
|
results: [],
|
|
|
|
suggestions: [],
|
|
|
|
totalHits: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
search: sync('site/search'),
|
2019-03-09 23:43:32 +00:00
|
|
|
searchIsFocused: sync('site/searchIsFocused'),
|
2019-03-09 05:51:02 +00:00
|
|
|
searchIsLoading: sync('site/searchIsLoading'),
|
|
|
|
searchRestrictLocale: sync('site/searchRestrictLocale'),
|
|
|
|
searchRestrictPath: sync('site/searchRestrictPath'),
|
|
|
|
results() {
|
2020-02-01 20:17:29 +00:00
|
|
|
const currentIndex = (this.pagination - 1) * this.perPage
|
|
|
|
return this.response.results ? _.slice(this.response.results, currentIndex, currentIndex + this.perPage) : []
|
2019-03-09 05:51:02 +00:00
|
|
|
},
|
|
|
|
hits() {
|
|
|
|
return this.response.totalHits ? this.response.totalHits : 0
|
|
|
|
},
|
|
|
|
suggestions() {
|
|
|
|
return this.response.suggestions ? this.response.suggestions : []
|
|
|
|
},
|
|
|
|
paginationLength() {
|
2020-02-01 20:17:29 +00:00
|
|
|
return (this.response.totalHits > 0) ? Math.ceil(this.response.totalHits / this.perPage) : 0
|
2019-03-09 05:51:02 +00:00
|
|
|
}
|
|
|
|
},
|
2019-03-09 23:43:32 +00:00
|
|
|
watch: {
|
|
|
|
search(newValue, oldValue) {
|
2019-03-10 06:28:58 +00:00
|
|
|
this.cursor = 0
|
2020-06-02 01:35:10 +00:00
|
|
|
if (!newValue || (newValue && newValue.length < 2)) {
|
2019-03-09 23:43:32 +00:00
|
|
|
this.response.results = []
|
2019-03-10 06:28:58 +00:00
|
|
|
this.response.suggestions = []
|
2020-06-02 01:35:10 +00:00
|
|
|
this.searchIsLoading = false
|
2019-03-10 06:28:58 +00:00
|
|
|
} else {
|
|
|
|
this.searchIsLoading = true
|
2019-03-09 23:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-03-10 06:28:58 +00:00
|
|
|
mounted() {
|
|
|
|
this.$root.$on('searchMove', (dir) => {
|
2019-07-13 03:56:44 +00:00
|
|
|
this.cursor += ((dir === 'up') ? -1 : 1)
|
2019-03-10 06:28:58 +00:00
|
|
|
if (this.cursor < -1) {
|
|
|
|
this.cursor = -1
|
|
|
|
} else if (this.cursor > this.results.length + this.suggestions.length - 1) {
|
|
|
|
this.cursor = this.results.length + this.suggestions.length - 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.$root.$on('searchEnter', () => {
|
2019-11-02 20:04:43 +00:00
|
|
|
if (!this.results) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-03-10 06:28:58 +00:00
|
|
|
if (this.cursor >= 0 && this.cursor < this.results.length) {
|
|
|
|
this.goToPage(_.nth(this.results, this.cursor))
|
|
|
|
} else if (this.cursor >= 0) {
|
|
|
|
this.setSearchTerm(_.nth(this.suggestions, this.cursor - this.results.length))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2019-03-19 18:46:10 +00:00
|
|
|
methods: {
|
|
|
|
setSearchTerm(term) {
|
|
|
|
this.search = term
|
|
|
|
},
|
|
|
|
goToPage(item) {
|
|
|
|
window.location.assign(`/${item.locale}/${item.path}`)
|
|
|
|
}
|
|
|
|
},
|
2019-03-09 05:51:02 +00:00
|
|
|
apollo: {
|
|
|
|
response: {
|
|
|
|
query: searchPagesQuery,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
query: this.search
|
|
|
|
}
|
|
|
|
},
|
2019-03-09 23:43:32 +00:00
|
|
|
fetchPolicy: 'network-only',
|
|
|
|
debounce: 300,
|
2019-03-09 05:51:02 +00:00
|
|
|
throttle: 1000,
|
|
|
|
skip() {
|
|
|
|
return !this.search || this.search.length < 2
|
|
|
|
},
|
|
|
|
update: (data) => _.get(data, 'pages.search', {}),
|
|
|
|
watchLoading (isLoading) {
|
|
|
|
this.searchIsLoading = isLoading
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.search-results {
|
|
|
|
position: fixed;
|
|
|
|
top: 64px;
|
|
|
|
left: 0;
|
2020-08-15 17:35:11 +00:00
|
|
|
overflow-y: auto;
|
2019-03-09 05:51:02 +00:00
|
|
|
width: 100%;
|
|
|
|
height: calc(100% - 64px);
|
|
|
|
background-color: rgba(0,0,0,.9);
|
|
|
|
z-index: 100;
|
|
|
|
text-align: center;
|
|
|
|
animation: searchResultsReveal .6s ease;
|
|
|
|
|
|
|
|
@media #{map-get($display-breakpoints, 'sm-and-down')} {
|
|
|
|
top: 112px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-container {
|
|
|
|
margin: 12px auto;
|
|
|
|
width: 90vw;
|
|
|
|
max-width: 1024px;
|
|
|
|
}
|
|
|
|
|
2019-03-09 23:43:32 +00:00
|
|
|
&-help {
|
|
|
|
text-align: center;
|
|
|
|
padding: 32px 0;
|
|
|
|
font-size: 18px;
|
|
|
|
font-weight: 300;
|
|
|
|
color: #FFF;
|
|
|
|
|
|
|
|
img {
|
|
|
|
width: 104px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-09 05:51:02 +00:00
|
|
|
&-loader {
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
flex-direction: column;
|
|
|
|
padding: 32px 0;
|
|
|
|
color: #FFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-none {
|
|
|
|
color: #FFF;
|
|
|
|
|
|
|
|
img {
|
|
|
|
width: 200px;
|
|
|
|
}
|
|
|
|
}
|
2019-03-10 06:28:58 +00:00
|
|
|
|
|
|
|
&-items {
|
2019-07-29 04:50:03 +00:00
|
|
|
text-align: left;
|
|
|
|
|
2019-03-10 06:28:58 +00:00
|
|
|
.highlighted {
|
2019-03-11 04:47:27 +00:00
|
|
|
background: #FFF linear-gradient(to bottom, #FFF, mc('orange', '100'));
|
2019-09-16 03:20:40 +00:00
|
|
|
|
|
|
|
@at-root .theme--dark & {
|
|
|
|
background: mc('grey', '900') linear-gradient(to bottom, mc('orange', '900'), darken(mc('orange', '900'), 15%));
|
|
|
|
}
|
2019-03-10 06:28:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&-suggestions {
|
|
|
|
.highlighted {
|
2019-03-11 04:47:27 +00:00
|
|
|
background: transparent linear-gradient(to bottom, mc('blue', '500'), mc('blue', '700'));
|
2019-03-10 06:28:58 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-09 05:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@keyframes searchResultsReveal {
|
|
|
|
0% {
|
|
|
|
background-color: rgba(0,0,0,0);
|
|
|
|
padding-top: 32px;
|
|
|
|
}
|
|
|
|
100% {
|
|
|
|
background-color: rgba(0,0,0,.9);
|
|
|
|
padding-top: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|