Add live topbar search for hosting accounts and sites.
Deploy Ladill Hosting / deploy (push) Successful in 20s

Wire a JSON /search endpoint and Alpine dropdown so customers can find accounts, linked domains, and orders from the hosting app header.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-06-06 18:06:58 +00:00
co-authored by Cursor
parent 5703a00862
commit a0bcf93e53
4 changed files with 180 additions and 6 deletions
+45
View File
@@ -50,5 +50,50 @@ Alpine.data('afia', (config = {}) => ({
},
}));
Alpine.data('topbarSearch', (config = {}) => ({
query: '',
results: [],
open: false,
loading: false,
active: 0,
_abort: null,
searchUrl: config.searchUrl || '/search',
onFocus() {
if (this.results.length > 0 || this.query.trim().length >= 2) this.open = true;
},
async search() {
const q = this.query.trim();
if (q.length < 2) { this.results = []; this.open = false; return; }
this.loading = true;
this.open = true;
this.active = 0;
if (this._abort) this._abort.abort();
this._abort = new AbortController();
try {
const res = await fetch(`${this.searchUrl}?q=${encodeURIComponent(q)}`, {
signal: this._abort.signal,
headers: { Accept: 'application/json', 'X-Requested-With': 'XMLHttpRequest' },
});
const data = await res.json();
this.results = data.results || [];
} catch (e) {
if (e.name !== 'AbortError') this.results = [];
} finally {
this.loading = false;
}
},
moveDown() { if (this.active < this.results.length - 1) this.active++; },
moveUp() { if (this.active > 0) this.active--; },
go() {
if (this.results[this.active]) window.location.href = this.results[this.active].url;
},
}));
window.Alpine = Alpine;
Alpine.start();