diff --git a/src/components/App.vue b/src/components/App.vue index 651cb1f..745c185 100755 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -19,12 +19,18 @@ AppMain, AppFooter }, - 'data': () => ({ - isLoading: false, - items: [], - filterData: undefined, - filters: undefined - }), + data(){ + const urlParams = new URLSearchParams(window.location.search); + const initialQuery = (urlParams.get('q') || urlParams.get('query') || '').trim(); + + return { + initialQuery, + isLoading: false, + items: [], + filterData: undefined, + filters: undefined + }; + }, computed: { apiUrl: () => apiUrl, filteredItems: function(){ @@ -67,8 +73,19 @@ } }, methods: { + updateSearchUrl: function(query){ + const url = new URL(window.location.href); + url.searchParams.delete('query'); + if(query) + url.searchParams.set('q', query); + else + url.searchParams.delete('q'); + window.history.replaceState(window.history.state, '', url); + }, search: async function(query){ + query = (query || '').trim(); this.isLoading = true; + this.updateSearchUrl(query); this.filterData = undefined; this.items.splice(0, this.items.length); try { @@ -133,12 +150,16 @@ } ); window._sentry = Sentry; + + if(this.initialQuery) + this.search(this.initialQuery); } };