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
|
|
|
|
Store Revamp / Full database synchronization across windows (#1833)
* History: Refactor history module
* Profiles: Refactor profiles module
* IPC: Move channel ids to their own file and make them constants
* IPC: Replace single sync channel for one channel per sync type
* Everywhere: Replace default profile id magic strings with constant ref
* Profiles: Refactor `activeProfile` property from store
This commit makes it so that `activeProfile`'s getter returns
the entire profile, while the related update function only needs
the profile id (instead of the previously used array index)
to change the currently active profile.
This change was made due to inconsistency regarding the active profile
when creating new profiles.
If a new profile coincidentally landed in the current active profile's
array index after sorting, the app would mistakenly change to it
without any action from the user apart from the profile's creation.
Turning the profile id into the selector instead solves this issue.
* Revert "Store: Implement history synchronization between windows"
This reverts commit 99b61e617873412eb393d8f4dfccd8f8c172021f.
This is necessary for an upcoming improved implementation of the
history synchronization.
* History: Remove unused mutation
* Everywhere: Create abstract database handlers
The project now utilizes abstract handlers to fetch, modify
or otherwise manipulate data from the database.
This facilitates 3 aspects of the app, in addition of
making them future proof:
- Switching database libraries is now trivial
Since most of the app utilizes the abstract handlers, it's incredibly
easily to change to a different DB library.
Hypothetically, all that would need to be done is to simply replace the
the file containing the base handlers, while the rest of the app
would go unchanged.
- Syncing logic between Electron and web is now properly separated
There are now two distinct DB handling APIs: the Electron one and
the web one.
The app doesn't need to manually choose the API, because it's detected
which platform is being utilized on import.
- All Electron windows now share the same database instance
This provides a single source of truth, improving consistency
regarding data manipulation and windows synchronization.
As a sidenote, syncing implementation has been left as is
(web unimplemented; Electron only syncs settings, remaining
datastore syncing will be implemented in the upcoming commits).
* Electron/History: Implement history synchronization
* Profiles: Implement suplementary profile creation logic
* ft-profile-edit: Small fix on profile name missing display
* Electron/Profiles: Implement profile synchronization
* Electron/Playlists: Implement playlist synchronization
2021-12-15 18:42:24 +00:00
|
|
|
import { IpcChannels } from '../../../constants'
|
|
|
|
|
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,
|
2021-09-16 22:58:03 +00:00
|
|
|
historyIndex: 1,
|
|
|
|
isForwardOrBack: 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': {
|
2021-11-02 11:45:50 +00:00
|
|
|
const { channelId, subPath } = result
|
2021-04-28 17:21:16 +00:00
|
|
|
|
|
|
|
this.$router.push({
|
2021-11-02 11:45:50 +00:00
|
|
|
path: `/channel/${channelId}/${subPath}`
|
2021-04-28 17:21:16 +00:00
|
|
|
})
|
|
|
|
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
|
|
|
|
},
|
|
|
|
|
2021-09-16 22:58:03 +00:00
|
|
|
navigateHistory: function() {
|
|
|
|
if (!this.isForwardOrBack) {
|
|
|
|
this.historyIndex = window.history.length
|
|
|
|
$('#historyArrowBack').removeClass('fa-arrow-left')
|
|
|
|
$('#historyArrowForward').addClass('fa-arrow-right')
|
|
|
|
} else {
|
|
|
|
this.isForwardOrBack = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
historyBack: function () {
|
2021-09-16 22:58:03 +00:00
|
|
|
this.isForwardOrBack = true
|
2020-02-16 18:30:00 +00:00
|
|
|
window.history.back()
|
2021-09-16 22:58:03 +00:00
|
|
|
|
|
|
|
if (this.historyIndex > 1) {
|
|
|
|
this.historyIndex--
|
|
|
|
$('#historyArrowForward').removeClass('fa-arrow-right')
|
|
|
|
if (this.historyIndex === 1) {
|
|
|
|
$('#historyArrowBack').addClass('fa-arrow-left')
|
|
|
|
}
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
historyForward: function () {
|
2021-09-16 22:58:03 +00:00
|
|
|
this.isForwardOrBack = true
|
2020-02-16 18:30:00 +00:00
|
|
|
window.history.forward()
|
2021-09-16 22:58:03 +00:00
|
|
|
|
|
|
|
if (this.historyIndex < window.history.length) {
|
|
|
|
this.historyIndex++
|
|
|
|
$('#historyArrowBack').removeClass('fa-arrow-left')
|
|
|
|
|
|
|
|
if (this.historyIndex === window.history.length) {
|
|
|
|
$('#historyArrowForward').addClass('fa-arrow-right')
|
|
|
|
}
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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')
|
Store Revamp / Full database synchronization across windows (#1833)
* History: Refactor history module
* Profiles: Refactor profiles module
* IPC: Move channel ids to their own file and make them constants
* IPC: Replace single sync channel for one channel per sync type
* Everywhere: Replace default profile id magic strings with constant ref
* Profiles: Refactor `activeProfile` property from store
This commit makes it so that `activeProfile`'s getter returns
the entire profile, while the related update function only needs
the profile id (instead of the previously used array index)
to change the currently active profile.
This change was made due to inconsistency regarding the active profile
when creating new profiles.
If a new profile coincidentally landed in the current active profile's
array index after sorting, the app would mistakenly change to it
without any action from the user apart from the profile's creation.
Turning the profile id into the selector instead solves this issue.
* Revert "Store: Implement history synchronization between windows"
This reverts commit 99b61e617873412eb393d8f4dfccd8f8c172021f.
This is necessary for an upcoming improved implementation of the
history synchronization.
* History: Remove unused mutation
* Everywhere: Create abstract database handlers
The project now utilizes abstract handlers to fetch, modify
or otherwise manipulate data from the database.
This facilitates 3 aspects of the app, in addition of
making them future proof:
- Switching database libraries is now trivial
Since most of the app utilizes the abstract handlers, it's incredibly
easily to change to a different DB library.
Hypothetically, all that would need to be done is to simply replace the
the file containing the base handlers, while the rest of the app
would go unchanged.
- Syncing logic between Electron and web is now properly separated
There are now two distinct DB handling APIs: the Electron one and
the web one.
The app doesn't need to manually choose the API, because it's detected
which platform is being utilized on import.
- All Electron windows now share the same database instance
This provides a single source of truth, improving consistency
regarding data manipulation and windows synchronization.
As a sidenote, syncing implementation has been left as is
(web unimplemented; Electron only syncs settings, remaining
datastore syncing will be implemented in the upcoming commits).
* Electron/History: Implement history synchronization
* Profiles: Implement suplementary profile creation logic
* ft-profile-edit: Small fix on profile name missing display
* Electron/Profiles: Implement profile synchronization
* Electron/Playlists: Implement playlist synchronization
2021-12-15 18:42:24 +00:00
|
|
|
ipcRenderer.send(IpcChannels.CREATE_NEW_WINDOW)
|
2021-05-21 23:49:48 +00:00
|
|
|
} else {
|
|
|
|
// Web placeholder
|
|
|
|
}
|
2021-05-11 15:28:26 +00:00
|
|
|
},
|
2021-08-24 22:14:37 +00:00
|
|
|
navigate: function (route) {
|
|
|
|
this.$router.push('/' + route)
|
|
|
|
},
|
2021-09-13 17:26:08 +00:00
|
|
|
hideFilters: function () {
|
|
|
|
this.showFilters = false
|
|
|
|
},
|
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
|
|
|
})
|