encodeUriComponent search query before adding to router path

This commit is contained in:
Worble 2020-08-03 21:34:16 +01:00
parent 8576d0fddb
commit 0f1adf10c7
1 changed files with 33 additions and 32 deletions

View File

@ -10,14 +10,14 @@ export default Vue.extend({
name: 'TopNav', name: 'TopNav',
components: { components: {
FtInput, FtInput,
FtSearchFilters FtSearchFilters,
}, },
data: () => { data: () => {
return { return {
component: this, component: this,
windowWidth: 0, windowWidth: 0,
showFilters: false, showFilters: false,
searchSuggestionsDataList: [] searchSuggestionsDataList: [],
} }
}, },
computed: { computed: {
@ -57,7 +57,7 @@ export default Vue.extend({
searchContainer.style.display = 'none' searchContainer.style.display = 'none'
} }
window.addEventListener('resize', function(event) { window.addEventListener('resize', function (event) {
const width = event.srcElement.innerWidth const width = event.srcElement.innerWidth
const searchContainer = $('.searchContainer').get(0) const searchContainer = $('.searchContainer').get(0)
@ -82,23 +82,19 @@ export default Vue.extend({
this.$store.dispatch('getVideoIdFromUrl', query).then((result) => { this.$store.dispatch('getVideoIdFromUrl', query).then((result) => {
if (result) { if (result) {
this.$router.push( this.$router.push({
{
path: `/watch/${result}`, path: `/watch/${result}`,
} })
)
} else { } else {
router.push( router.push({
{ path: `/search/${encodeURIComponent(query)}`,
path: `/search/${query}`,
query: { query: {
sortBy: this.searchSettings.sortBy, sortBy: this.searchSettings.sortBy,
time: this.searchSettings.time, time: this.searchSettings.time,
type: this.searchSettings.type, type: this.searchSettings.type,
duration: this.searchSettings.duration duration: this.searchSettings.duration,
} },
} })
)
} }
}) })
@ -143,16 +139,21 @@ export default Vue.extend({
resource: 'search/suggestions', resource: 'search/suggestions',
id: '', id: '',
params: { params: {
q: query q: query,
} },
} }
this.$store.dispatch('invidiousAPICall', searchPayload).then((results) => { this.$store
.dispatch('invidiousAPICall', searchPayload)
.then((results) => {
this.searchSuggestionsDataList = results.suggestions this.searchSuggestionsDataList = results.suggestions
}).error((err) => { })
.error((err) => {
console.log(err) console.log(err)
if (this.backendFallback) { if (this.backendFallback) {
console.log('Error gettings search suggestions. Falling back to Local API') console.log(
'Error gettings search suggestions. Falling back to Local API'
)
this.getSearchSuggestionsLocal(query) this.getSearchSuggestionsLocal(query)
} }
}) })
@ -180,6 +181,6 @@ export default Vue.extend({
toggleSideNav: function () { toggleSideNav: function () {
this.$store.commit('toggleSideNav') this.$store.commit('toggleSideNav')
} },
} },
}) })