diff --git a/src/renderer/components/top-nav/top-nav.js b/src/renderer/components/top-nav/top-nav.js index 59cc2ec8a..035321d67 100644 --- a/src/renderer/components/top-nav/top-nav.js +++ b/src/renderer/components/top-nav/top-nav.js @@ -77,7 +77,7 @@ export default Vue.extend({ this.debounceSearchResults = debounce(this.getSearchSuggestions, 200) }, methods: { - goToSearch: function (query) { + goToSearch: async function (query) { const appWidth = $(window).width() if (appWidth <= 680) { @@ -89,23 +89,30 @@ export default Vue.extend({ searchInput.blur() } - this.$store.dispatch('getVideoIdFromUrl', query).then((result) => { - if (result) { - this.$router.push({ - path: `/watch/${result}` - }) - } else { - router.push({ - path: `/search/${encodeURIComponent(query)}`, - query: { - sortBy: this.searchSettings.sortBy, - time: this.searchSettings.time, - type: this.searchSettings.type, - duration: this.searchSettings.duration - } - }) - } - }) + 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 + } + }) + } this.showFilters = false }, diff --git a/src/renderer/store/modules/utils.js b/src/renderer/store/modules/utils.js index 16f28a9ec..2daf9dc21 100644 --- a/src/renderer/store/modules/utils.js +++ b/src/renderer/store/modules/utils.js @@ -229,6 +229,27 @@ const actions = { return extractors.reduce((a, c) => a || c(), null) || false }, + getPlaylistIdFromUrl (_, url) { + /** @type {URL} */ + let urlObject + try { + urlObject = new URL(url) + } catch (e) { + return false + } + + const extractors = [ + // anything with /playlist?list= + function() { + if (urlObject.pathname === '/playlist' && urlObject.searchParams.has('list')) { + return urlObject.searchParams.get('list') + } + } + ] + + return extractors.reduce((a, c) => a || c(), null) || false + }, + padNumberWithLeadingZeros(_, payload) { let numberString = payload.number.toString() while (numberString.length < payload.length) {