2020-02-16 18:30:00 +00:00
|
|
|
import Vue from 'vue'
|
|
|
|
import FtInput from '../ft-input/ft-input.vue'
|
|
|
|
import FtSearchFilters from '../ft-search-filters/ft-search-filters.vue'
|
2020-08-31 21:35:22 +00:00
|
|
|
import FtProfileSelector from '../ft-profile-selector/ft-profile-selector.vue'
|
2020-03-24 13:22:29 +00:00
|
|
|
import $ from 'jquery'
|
2020-02-16 18:30:00 +00:00
|
|
|
import router from '../../router/index.js'
|
2020-06-02 02:42:29 +00:00
|
|
|
import debounce from 'lodash.debounce'
|
|
|
|
import ytSuggest from 'youtube-suggest'
|
2020-02-16 18:30:00 +00:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
name: 'TopNav',
|
|
|
|
components: {
|
|
|
|
FtInput,
|
2020-08-31 21:35:22 +00:00
|
|
|
FtSearchFilters,
|
|
|
|
FtProfileSelector
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
data: () => {
|
|
|
|
return {
|
|
|
|
component: this,
|
2020-04-14 02:59:25 +00:00
|
|
|
windowWidth: 0,
|
2020-06-02 02:42:29 +00:00
|
|
|
showFilters: false,
|
2020-08-05 02:18:39 +00:00
|
|
|
searchSuggestionsDataList: []
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2020-06-19 19:46:01 +00:00
|
|
|
enableSearchSuggestions: function () {
|
|
|
|
return this.$store.getters.getEnableSearchSuggestions
|
|
|
|
},
|
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
searchSettings: function () {
|
|
|
|
return this.$store.getters.getSearchSettings
|
|
|
|
},
|
|
|
|
|
|
|
|
isSideNavOpen: function () {
|
|
|
|
return this.$store.getters.getIsSideNavOpen
|
2020-02-27 03:10:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
barColor: function () {
|
|
|
|
return this.$store.getters.getBarColor
|
2020-06-02 02:42:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
invidiousInstance: function () {
|
|
|
|
return this.$store.getters.getInvidiousInstance
|
|
|
|
},
|
|
|
|
|
|
|
|
backendFallback: function () {
|
|
|
|
return this.$store.getters.getBackendFallback
|
|
|
|
},
|
|
|
|
|
|
|
|
backendPreference: function () {
|
|
|
|
return this.$store.getters.getBackendPreference
|
2020-08-05 02:18:39 +00:00
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
2020-03-24 13:22:29 +00:00
|
|
|
mounted: function () {
|
2020-04-14 02:59:25 +00:00
|
|
|
const appWidth = $(window).width()
|
|
|
|
|
|
|
|
if (appWidth <= 680) {
|
|
|
|
const searchContainer = $('.searchContainer').get(0)
|
|
|
|
searchContainer.style.display = 'none'
|
|
|
|
}
|
|
|
|
|
2020-10-06 15:53:54 +00:00
|
|
|
if (localStorage.getItem('expandSideBar') === 'true') {
|
|
|
|
this.toggleSideNav()
|
|
|
|
}
|
|
|
|
|
2020-08-03 20:34:16 +00:00
|
|
|
window.addEventListener('resize', function (event) {
|
2020-03-24 13:22:29 +00:00
|
|
|
const width = event.srcElement.innerWidth
|
|
|
|
const searchContainer = $('.searchContainer').get(0)
|
|
|
|
|
|
|
|
if (width > 680) {
|
2020-03-24 14:34:55 +00:00
|
|
|
searchContainer.style.display = ''
|
2020-03-24 13:22:29 +00:00
|
|
|
} else {
|
|
|
|
searchContainer.style.display = 'none'
|
|
|
|
}
|
|
|
|
})
|
2020-06-02 02:42:29 +00:00
|
|
|
|
2020-09-20 18:22:39 +00:00
|
|
|
this.debounceSearchResults = debounce(this.getSearchSuggestions, 200)
|
2020-03-24 13:22:29 +00:00
|
|
|
},
|
2020-02-16 18:30:00 +00:00
|
|
|
methods: {
|
2021-01-15 16:34:44 +00:00
|
|
|
goToSearch: async function (query) {
|
2020-03-24 13:22:29 +00:00
|
|
|
const appWidth = $(window).width()
|
|
|
|
|
|
|
|
if (appWidth <= 680) {
|
|
|
|
const searchContainer = $('.searchContainer').get(0)
|
2020-04-14 02:59:25 +00:00
|
|
|
searchContainer.blur()
|
2020-03-24 13:22:29 +00:00
|
|
|
searchContainer.style.display = 'none'
|
2020-08-24 22:04:59 +00:00
|
|
|
} else {
|
|
|
|
const searchInput = $('.searchInput input').get(0)
|
|
|
|
searchInput.blur()
|
2020-03-24 13:22:29 +00:00
|
|
|
}
|
|
|
|
|
2021-01-15 16:34:44 +00:00
|
|
|
const videoId = await this.$store.dispatch('getVideoIdFromUrl', query)
|
|
|
|
const playlistId = await this.$store.dispatch('getPlaylistIdFromUrl', query)
|
|
|
|
|
|
|
|
console.log(playlistId)
|
|
|
|
|
|
|
|
if (videoId) {
|
|
|
|
this.$router.push({
|
|
|
|
path: `/watch/${videoId}`
|
|
|
|
})
|
|
|
|
} else if (playlistId) {
|
|
|
|
this.$router.push({
|
|
|
|
path: `/playlist/${playlistId}`
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
router.push({
|
|
|
|
path: `/search/${encodeURIComponent(query)}`,
|
|
|
|
query: {
|
|
|
|
sortBy: this.searchSettings.sortBy,
|
|
|
|
time: this.searchSettings.time,
|
|
|
|
type: this.searchSettings.type,
|
|
|
|
duration: this.searchSettings.duration
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-04-14 02:59:25 +00:00
|
|
|
|
|
|
|
this.showFilters = false
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
|
2020-06-02 02:42:29 +00:00
|
|
|
getSearchSuggestionsDebounce: function (query) {
|
2020-06-19 19:46:01 +00:00
|
|
|
if (this.enableSearchSuggestions) {
|
|
|
|
this.debounceSearchResults(query)
|
|
|
|
}
|
2020-06-02 02:42:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getSearchSuggestions: function (query) {
|
|
|
|
switch (this.backendPreference) {
|
|
|
|
case 'local':
|
|
|
|
this.getSearchSuggestionsLocal(query)
|
|
|
|
break
|
|
|
|
case 'invidious':
|
|
|
|
this.getSearchSuggestionsInvidious(query)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getSearchSuggestionsLocal: function (query) {
|
|
|
|
if (query === '') {
|
|
|
|
this.searchSuggestionsDataList = []
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ytSuggest(query).then((results) => {
|
|
|
|
this.searchSuggestionsDataList = results
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
getSearchSuggestionsInvidious: function (query) {
|
|
|
|
if (query === '') {
|
|
|
|
this.searchSuggestionsDataList = []
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const searchPayload = {
|
|
|
|
resource: 'search/suggestions',
|
|
|
|
id: '',
|
|
|
|
params: {
|
2020-08-05 02:18:39 +00:00
|
|
|
q: query
|
|
|
|
}
|
2020-06-02 02:42:29 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 01:59:59 +00:00
|
|
|
this.$store.dispatch('invidiousAPICall', searchPayload).then((results) => {
|
|
|
|
this.searchSuggestionsDataList = results.suggestions
|
|
|
|
}).catch((err) => {
|
|
|
|
console.log(err)
|
|
|
|
if (this.backendFallback) {
|
|
|
|
console.log(
|
|
|
|
'Error gettings search suggestions. Falling back to Local API'
|
|
|
|
)
|
|
|
|
this.getSearchSuggestionsLocal(query)
|
|
|
|
}
|
|
|
|
})
|
2020-06-02 02:42:29 +00:00
|
|
|
},
|
|
|
|
|
2020-03-24 13:22:29 +00:00
|
|
|
toggleSearchContainer: function () {
|
|
|
|
const searchContainer = $('.searchContainer').get(0)
|
|
|
|
|
2020-03-24 14:34:55 +00:00
|
|
|
if (searchContainer.style.display === 'none') {
|
|
|
|
searchContainer.style.display = ''
|
2020-03-24 13:22:29 +00:00
|
|
|
} else {
|
|
|
|
searchContainer.style.display = 'none'
|
|
|
|
}
|
|
|
|
|
|
|
|
this.showFilters = false
|
|
|
|
},
|
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
historyBack: function () {
|
|
|
|
window.history.back()
|
|
|
|
},
|
|
|
|
|
|
|
|
historyForward: function () {
|
|
|
|
window.history.forward()
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleSideNav: function () {
|
|
|
|
this.$store.commit('toggleSideNav')
|
2020-08-05 02:18:39 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
})
|