This commit is contained in:
parent
0040bc4d28
commit
011ad3ce28
|
@ -27,6 +27,14 @@
|
||||||
<form id="search">
|
<form id="search">
|
||||||
<input name="query" type="text" placeholder="Query">
|
<input name="query" type="text" placeholder="Query">
|
||||||
<input type="submit" value="Search">
|
<input type="submit" value="Search">
|
||||||
|
<input type="radio" id="search-category-all" name="category" value="all" checked>
|
||||||
|
<label for="search-category-all">All</label>
|
||||||
|
<input type="radio" id="search-category-images" name="category" value="images">
|
||||||
|
<label for="search-category-images">Images</label>
|
||||||
|
<input type="radio" id="search-category-news" name="category" value="news">
|
||||||
|
<label for="search-category-news">News</label>
|
||||||
|
<input type="radio" id="search-category-videos" name="category" value="videos">
|
||||||
|
<label for="search-category-videos">Videos</label>
|
||||||
</form>
|
</form>
|
||||||
<p id="info"></p>
|
<p id="info"></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
15
index.js
15
index.js
|
@ -23,6 +23,9 @@ function buildSearchURL (opts = {}) {
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
q: opts.query
|
q: opts.query
|
||||||
})
|
})
|
||||||
|
if (opts.category && opts.category !== 'all') {
|
||||||
|
params.append(`category_${opts.category}`, '')
|
||||||
|
}
|
||||||
const url = `${instanceURL}?${params.toString()}`
|
const url = `${instanceURL}?${params.toString()}`
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
@ -31,7 +34,8 @@ function buildSearchURL (opts = {}) {
|
||||||
formEl.addEventListener('submit', (event) => {
|
formEl.addEventListener('submit', (event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
location.assign(buildSearchURL({
|
location.assign(buildSearchURL({
|
||||||
query: formEl.query.value
|
query: formEl.query.value,
|
||||||
|
category: formEl.category.value
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -92,14 +96,13 @@ if (location.search.length > 0) {
|
||||||
const searchParams = new URLSearchParams(location.search.slice(1))
|
const searchParams = new URLSearchParams(location.search.slice(1))
|
||||||
if (searchParams.has('q')) {
|
if (searchParams.has('q')) {
|
||||||
location.assign(buildSearchURL({
|
location.assign(buildSearchURL({
|
||||||
query: searchParams.get('q')
|
query: searchParams.get('q'),
|
||||||
|
category: searchParams.get('in') ?? 'all'
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
infoEl.textContent = `${data.instances.length} instances`
|
||||||
if (data.instances.length > 0) {
|
if (data.instances.length > 0) {
|
||||||
infoEl.textContent = `${data.instances.length} instances`
|
|
||||||
} else {
|
|
||||||
infoEl.classList.add('error')
|
infoEl.classList.add('error')
|
||||||
infoEl.textContent = '0 instances'
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user