Skip to content

Commit 0325cd8

Browse files
committed
Add autocomplete.
TODO: Currently, searches that are not in OOC mode, have an empty autocomplete. Not the best solution. FIX!
1 parent ebed60d commit 0325cd8

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

Client/Components/SearchBar.razor

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
@using Humanizer
2+
@using Microsoft.Extensions.Configuration
3+
@inject IConfiguration Configuration
4+
25
@{
36
var searchModes = Enum.GetValues(typeof(Shared.SearchMode)).Cast<Shared.SearchMode>().ToList();
47
<div class="search-bar">
58
<div class="d-flex ms-auto">
6-
<input type="text" class="form-control" placeholder="Search for a replay..." onsubmit="search()" aria-label="Search">
9+
<input
10+
type="text"
11+
class="form-control"
12+
placeholder="Search for a replay..."
13+
onsubmit="search()"
14+
aria-label="Search"
15+
data-filter="@Configuration["ApiUrl"]api/Data/username-completion?username=#QUERY#"
16+
id="search"
17+
>
718
<button class="btn-secondary btn dropdown-toggle" type="button" id="searchModeButton" style="margin-left: 1rem; margin-right: 1rem;" data-bs-toggle="dropdown" aria-expanded="false">
819
@Shared.SearchMode.PlayerOocName.Humanize()
920
</button>
10-
<ul class="dropdown-menu">
21+
<ul class="dropdown-menu no-affect">
1122
@foreach (var mode in searchModes)
1223
{
1324
<li><a class="dropdown-item">@mode.Humanize()</a></li>
@@ -18,6 +29,20 @@
1829
</div>
1930
}
2031

32+
<style>
33+
/* this is a bit stupid
34+
so. the autocomplete plugin uses a div dropdown right? but that dropdown is placed directly ON the input,
35+
we want to move it down, but dont want to move the no-affect dropdown, so we move EVERY dropdown down, but not the no-affect one
36+
*/
37+
.dropdown-menu {
38+
margin-top: 2.5rem;
39+
}
40+
41+
.no-affect {
42+
margin-top: 0;
43+
}
44+
</style>
45+
2146
<script>
2247
// This is a script to make the dropdown change the text of the button
2348
const dropdowns = document.querySelectorAll('.dropdown-menu a');
@@ -50,4 +75,16 @@
5075
5176
// Set the value of the search input to the value of the query
5277
document.querySelector('.search-bar input').value = new URLSearchParams(window.location.search).get('query');
78+
79+
document.addEventListener('DOMContentLoaded', e => {
80+
$('#search').autocomplete({
81+
onItemRendered(el, item) {
82+
const currentSelectedSearchMode = document.getElementById('searchModeButton').textContent;
83+
if (currentSelectedSearchMode !== "@Shared.SearchMode.PlayerOocName.Humanize()") {
84+
// Currently, autocomplete only supports searching for player names. So delete the item
85+
item.remove();
86+
}
87+
}
88+
})
89+
}, false);
5390
</script>

0 commit comments

Comments
 (0)