feat(card): search spotlight

This commit is contained in:
root
2026-06-02 22:46:47 +10:00
parent c78203f8e4
commit 449e849f4d
3 changed files with 32 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
// public/views/cards/search.js
import { el, mount } from '../../dom.js';
import { api } from '../../api.js';
import { navigate } from '../../router.js';
const ROUTE = { page: id => '#/page/' + id, ref: id => '#/ref/' + id, source_doc: () => '#/', message: () => '#/' };
let body, input, results, deb;
async function run(q) {
if (!q) { mount(results); return; }
try {
const hits = await api.get('/api/search?q=' + encodeURIComponent(q));
mount(results, (hits || []).slice(0, 6).map(h =>
el('div', { class: 'sv-row', style: { cursor: 'pointer' },
onclick: () => { const r = ROUTE[h.kind]; if (r) navigate(r(h.id)); } },
el('span', {}, h.title_or_snippet || '(untitled)'), el('span', { class: 'k' }, h.kind))
));
} catch { mount(results, el('span', { class: 'muted' }, 'Search failed')); }
}
export default {
id: 'search', title: 'Spotlight', size: 'l',
mount(el_) {
body = el_;
input = el('input', { class: 'sv-search-input', placeholder: 'Search the Void…',
oninput: e => { clearTimeout(deb); const q = e.target.value.trim(); deb = setTimeout(() => run(q), 250); } });
results = el('div', { style: { marginTop: '10px' } });
mount(body, input, results);
},
start() {}, stop() { body = null; }
};

View File

@@ -8,8 +8,9 @@ import weather from './cards/weather.js';
import hostPerf from './cards/host_perf.js';
import jobs from './cards/jobs.js';
import inbox from './cards/inbox.js';
import search from './cards/search.js';
const CARD_MODULES = [clock, weather, hostPerf, jobs, inbox]; // grows in later tasks
const CARD_MODULES = [clock, weather, hostPerf, jobs, inbox, search]; // grows in later tasks
let active = []; // mounted cards needing stop()
export async function render(main) {