2020-02-16 18:30:00 +00:00
|
|
|
import Vue from 'vue'
|
2021-05-11 15:28:26 +00:00
|
|
|
import { mapActions } from 'vuex'
|
2020-02-16 18:30:00 +00:00
|
|
|
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-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,
|
2021-05-25 17:54:27 +00:00
|
|
|
searchFilterValueChanged: false,
|
2020-08-05 02:18:39 +00:00
|
|
|
searchSuggestionsDataList: []
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2021-05-21 23:49:48 +00:00
|
|
|
usingElectron: function () {
|
|
|
|
return this.$store.getters.getUsingElectron
|
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2021-07-03 01:55:56 +00:00
|
|
|
currentInvidiousInstance: function () {
|
|
|
|
return this.$store.getters.getCurrentInvidiousInstance
|
2020-06-02 02:42:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
backendFallback: function () {
|
|
|
|
return this.$store.getters.getBackendFallback
|
|
|
|
},
|
|
|
|
|
|
|
|
backendPreference: function () {
|
|
|
|
return this.$store.getters.getBackendPreference
|
2021-04-30 21:18:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
forwardText: function () {
|
|
|
|
return this.$t('Forward')
|
|
|
|
},
|
|
|
|
|
|
|
|
backwardText: function () {
|
|
|
|
return this.$t('Backward')
|
|
|
|
},
|
|
|
|
|
|
|
|
newWindowText: function () {
|
|
|
|
return this.$t('Open New Window')
|
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-05-21 23:56:32 +00:00
|
|
|
this.getYoutubeUrlInfo(query).then((result) => {
|
2021-04-28 17:21:16 +00:00
|
|
|
switch (result.urlType) {
|
|
|
|
case 'video': {
|
2021-05-31 11:23:35 +00:00
|
|
|
const { videoId, timestamp, playlistId } = result
|
2021-01-15 16:34:44 +00:00
|
|
|
|
2021-05-31 11:23:35 +00:00
|
|
|
const query = {}
|
|
|
|
if (timestamp) {
|
|
|
|
query.timestamp = timestamp
|
|
|
|
}
|
|
|
|
if (playlistId && playlistId.length > 0) {
|
|
|
|
query.playlistId = playlistId
|
|
|
|
}
|
2021-04-28 17:21:16 +00:00
|
|
|
this.$router.push({
|
|
|
|
path: `/watch/${videoId}`,
|
2021-05-31 11:23:35 +00:00
|
|
|
query: query
|
2021-04-28 17:21:16 +00:00
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
2021-01-15 16:34:44 +00:00
|
|
|
|
2021-04-28 17:21:16 +00:00
|
|
|
case 'playlist': {
|
|
|
|
const { playlistId, query } = result
|
|
|
|
|
|
|
|
this.$router.push({
|
|
|
|
path: `/playlist/${playlistId}`,
|
|
|
|
query
|
|
|
|
})
|
|
|
|
break
|
2021-01-15 16:34:44 +00:00
|
|
|
}
|
2020-04-14 02:59:25 +00:00
|
|
|
|
2021-04-28 17:21:16 +00:00
|
|
|
case 'search': {
|
|
|
|
const { searchQuery, query } = result
|
|
|
|
|
|
|
|
this.$router.push({
|
|
|
|
path: `/search/${encodeURIComponent(searchQuery)}`,
|
|
|
|
query
|
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'hashtag': {
|
|
|
|
// TODO: Implement a hashtag related view
|
|
|
|
let message = 'Hashtags have not yet been implemented, try again later'
|
2021-04-30 21:18:45 +00:00
|
|
|
if (this.$t(message) && this.$t(message) !== '') {
|
2021-04-28 17:21:16 +00:00
|
|
|
message = this.$t(message)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.showToast({
|
|
|
|
message: message
|
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'channel': {
|
|
|
|
const { channelId } = result
|
|
|
|
|
|
|
|
this.$router.push({
|
|
|
|
path: `/channel/${channelId}`
|
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'invalid_url':
|
|
|
|
default: {
|
|
|
|
this.$router.push({
|
|
|
|
path: `/search/${encodeURIComponent(query)}`,
|
|
|
|
query: {
|
|
|
|
sortBy: this.searchSettings.sortBy,
|
|
|
|
time: this.searchSettings.time,
|
|
|
|
type: this.searchSettings.type,
|
|
|
|
duration: this.searchSettings.duration
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Close the filter panel
|
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
|
|
|
}
|
|
|
|
|
2021-05-21 23:56:32 +00:00
|
|
|
this.invidiousAPICall(searchPayload).then((results) => {
|
2020-09-21 01:59:59 +00:00
|
|
|
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
|
|
|
|
},
|
|
|
|
|
2021-05-25 17:54:27 +00:00
|
|
|
handleSearchFilterValueChanged: function(filterValueChanged) {
|
|
|
|
this.searchFilterValueChanged = filterValueChanged
|
|
|
|
},
|
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
historyBack: function () {
|
|
|
|
window.history.back()
|
|
|
|
},
|
|
|
|
|
|
|
|
historyForward: function () {
|
|
|
|
window.history.forward()
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleSideNav: function () {
|
|
|
|
this.$store.commit('toggleSideNav')
|
2021-04-15 18:28:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
createNewWindow: function () {
|
2021-05-21 23:49:48 +00:00
|
|
|
if (this.usingElectron) {
|
|
|
|
const { ipcRenderer } = require('electron')
|
|
|
|
ipcRenderer.send('createNewWindow')
|
|
|
|
} else {
|
|
|
|
// Web placeholder
|
|
|
|
}
|
2021-05-11 15:28:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
...mapActions([
|
2021-05-21 23:56:32 +00:00
|
|
|
'showToast',
|
|
|
|
'getYoutubeUrlInfo',
|
|
|
|
'invidiousAPICall'
|
2021-05-11 15:28:26 +00:00
|
|
|
])
|
2020-08-05 02:18:39 +00:00
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
})
|