Improve search form submission logic (#107)

Refactor search logic to trim input and auto-append region if necessary. Standardize URL format for search queries.
This commit is contained in:
Alex 2026-01-05 12:31:29 +00:00 committed by GitHub
parent c36bdcba2b
commit 44978549ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -102,7 +102,6 @@ export default {
watch: { watch: {
open(newVal) { open(newVal) {
// Search Dropdown open
if (newVal) { if (newVal) {
this.dropDownOpening() this.dropDownOpening()
} else { } else {
@ -147,17 +146,33 @@ export default {
} }
document.body.style.overflow = 'hidden' document.body.style.overflow = 'hidden'
}, },
// UPDATED SEARCH LOGIC
formSubmit() { formSubmit() {
const search = this.summoner.split(' ').join('').replaceAll('+', ' ').replaceAll('#', '-') let query = this.summoner.trim()
if (search.length) {
if (query.length) {
// If the user didn't include a tagline (# or -), auto-append the region
if (!query.includes('#') && !query.includes('-')) {
query = `${query}-${this.selectedRegion.toUpperCase()}`
}
// Standardize the URL format (project uses '-' instead of '#')
const search = query
.split(' ')
.join('')
.replaceAll('+', ' ')
.replaceAll('#', '-')
this.$emit('formSubmit', search, this.selectedRegion) this.$emit('formSubmit', search, this.selectedRegion)
} }
}, },
getScrollbarWidth() { getScrollbarWidth() {
const outer = document.createElement('div') const outer = document.createElement('div')
outer.style.visibility = 'hidden' outer.style.visibility = 'hidden'
outer.style.overflow = 'scroll' // forcing scrollbar to appear outer.style.overflow = 'scroll'
outer.style.msOverflowStyle = 'scrollbar' // needed for WinJS apps outer.style.msOverflowStyle = 'scrollbar'
document.body.appendChild(outer) document.body.appendChild(outer)
const inner = document.createElement('div') const inner = document.createElement('div')