diff --git a/webapp/components/generic/SearchableInput/SearchableInput.vue b/webapp/components/generic/SearchableInput/SearchableInput.vue index 5ec97d573..b448f941c 100644 --- a/webapp/components/generic/SearchableInput/SearchableInput.vue +++ b/webapp/components/generic/SearchableInput/SearchableInput.vue @@ -100,6 +100,7 @@ export default { }, this.delay) }, onEnter(event) { + if (this.$router.history.current.path === '/search/search-results') { this.$store.commit('search/SET_VALUE', { searchValue: this.unprocessedSearchInput, @@ -111,10 +112,12 @@ export default { }) this.clear() } else { + if (this.options.length === 0 ) return this.$router.replace({ path: '/search/search-results', query: { item: this.unprocessedSearchInput }, }) + this.clear() } }, onDelete(event) { diff --git a/webapp/graphql/Search.js b/webapp/graphql/Search.js index 22babb452..a4eff5619 100644 --- a/webapp/graphql/Search.js +++ b/webapp/graphql/Search.js @@ -6,8 +6,8 @@ export const findResourcesQuery = gql` ${postFragment} ${tagsCategoriesAndPinnedFragment} - query($query: String!) { - findResources(query: $query, limit: 5) { + query($query: String!, $limit: Int = 5) { + findResources(query: $query, limit: $limit) { __typename ... on Post { ...post diff --git a/webapp/pages/search/search-results.vue b/webapp/pages/search/search-results.vue index 54a5b7cb7..e72285207 100644 --- a/webapp/pages/search/search-results.vue +++ b/webapp/pages/search/search-results.vue @@ -1,14 +1,21 @@ @@ -124,37 +122,36 @@ export default { return { loading: true, value: '', - pending: false, searchResults: [], - users: [], - posts: [], userOnly: true, postOnly: true, } }, - computed: { ...mapGetters({ searchValue: 'search/searchValue', orderOptions: 'posts/orderOptions', sortingIcon: 'posts/orderIcon', }), - sortingOptions() { - return this.orderOptions(this) + posts() { + return this.searchResults.filter(result => result.__typename === 'Post') + }, + users() { + return this.searchResults.filter(result => result.__typename === 'User') }, }, mounted() { + if (this.$route.query.item){ this.value = this.$route.query.item this.query(this.value) + } else { + this.$router.replace('/') + } }, - watch: { - searchValue: function(val) { - this.users = [] - this.posts = [] - this.value = val - this.query(this.value) + searchValue(value) { + this.query(value) }, }, methods: { @@ -167,18 +164,12 @@ export default { query: findResourcesQuery, variables: { query: value, + limit: 37, }, }) - for (var i = 0; i < findResources.length; i++) { - if (findResources[i].__typename === 'User') { - this.users.push(findResources[i]) - } - if (findResources[i].__typename === 'Post') { - this.posts.push(findResources[i]) - } - } // console.log('users', this.users) // console.log('posts', this.posts) + console.log("findResources",findResources) this.searchResults = findResources } catch (error) { this.searchResults = [] @@ -192,5 +183,4 @@ export default { }, } - - + \ No newline at end of file