From fb6a8d999c7406559f65c22cbbb399b217ef047d Mon Sep 17 00:00:00 2001 From: venashial Date: Fri, 2 Jul 2021 17:04:08 +0000 Subject: [PATCH] Mod search fixes (#249) * Remove all uses of `process.env.domain` * Revert "Remove all uses of `process.env.domain`" This reverts commit 5af9b83091f395d3a0f954cf6776494c1cfe7a04. * Increase minimum amount of pages for pagination Fixes modrinth/knossos#231 * Detect mod search query removal Fixes modrinth/knossos#240 * Increase margin on project card categories mobile Fixes modrinth/knossos#230 --- components/ui/ProjectCard.vue | 2 +- pages/mods.vue | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/components/ui/ProjectCard.vue b/components/ui/ProjectCard.vue index b25a352dd..836f7b40d 100644 --- a/components/ui/ProjectCard.vue +++ b/components/ui/ProjectCard.vue @@ -288,7 +288,7 @@ export default { @media screen and (max-width: 560px) { .left-categories { display: flex; - margin: 0 0 0.75rem 0.75rem; + margin: 0 0.75rem 0.75rem 0.75rem; width: 7rem; } .right-categories { diff --git a/pages/mods.vue b/pages/mods.vue index 3ca787ccf..3b213248e 100644 --- a/pages/mods.vue +++ b/pages/mods.vue @@ -453,6 +453,25 @@ export default { maxResults: 20, } }, + watch: { + async '$route.query'(to, from) { + // Detects when the query is removed from the URL + if (Object.keys(to).length === 0 && Object.keys(from).length !== 0) { + this.query = '' + this.displayLicense = '' + this.selectedLicense = '' + this.showSnapshots = false + this.selectedVersions = [] + this.selectedEnvironments = [] + this.facets = [] + this.currentPage = 1 + this.sortType = { display: 'Relevance', name: 'relevance' } + this.maxResults = 20 + + await this.onSearchChange(1) + } + }, + }, methods: { async fillVersions() { try { @@ -613,7 +632,7 @@ export default { const pageAmount = Math.ceil(res.data.total_hits / res.data.limit) this.currentPage = newPageNumber - if (pageAmount > 4) { + if (pageAmount > 7) { if (this.currentPage + 3 >= pageAmount) { this.pages = [ 1, @@ -657,7 +676,12 @@ export default { if (this.maxResults > 20) url += `&m=${encodeURIComponent(this.maxResults)}` - window.history.replaceState(new Date(), 'Mods', url) + // Check if URL needs to be changed, ignoring browser `,` to `%2C` changes + if ( + url.replace(/%2C|,/g, '') !== + this.$route.fullPath.substring(1).replace(/%2C|,/g, '') + ) + this.$router.replace(url) } } catch (err) { // eslint-disable-next-line no-console