yayy now it works
This commit is contained in:
@@ -18,8 +18,7 @@ public class WebServer {
|
|||||||
|
|
||||||
@GetMapping("/api/fuzzy")
|
@GetMapping("/api/fuzzy")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ArrayList<BonusItem> index(@RequestParam(value = "q", required = true) String fuzzySearch, Model model){
|
public ArrayList<BonusItem> fuzzySearch(@RequestParam(value = "q", required = false, defaultValue = "") String fuzzySearch){
|
||||||
// Call your BonusManager or service to get items
|
|
||||||
ArrayList<BonusItem> items = BonusManager.getBonusItems(fuzzySearch);
|
ArrayList<BonusItem> items = BonusManager.getBonusItems(fuzzySearch);
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,18 +134,16 @@
|
|||||||
const resultCount = document.getElementById('resultCount');
|
const resultCount = document.getElementById('resultCount');
|
||||||
let debounceTimer;
|
let debounceTimer;
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
performFuzzySearch('');
|
||||||
|
});
|
||||||
|
|
||||||
searchInput.addEventListener('input', (e) => {
|
searchInput.addEventListener('input', (e) => {
|
||||||
clearTimeout(debounceTimer);
|
clearTimeout(debounceTimer);
|
||||||
const query = e.target.value.trim();
|
const query = e.target.value.trim();
|
||||||
|
|
||||||
// Debounce: wait 300ms before searching
|
|
||||||
debounceTimer = setTimeout(() => {
|
debounceTimer = setTimeout(() => {
|
||||||
if (query.length === 0) {
|
performFuzzySearch(query); // Always call API, even for empty string
|
||||||
// Reset to all items
|
|
||||||
location.reload();
|
|
||||||
} else {
|
|
||||||
performFuzzySearch(query);
|
|
||||||
}
|
|
||||||
}, 300);
|
}, 300);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user