${escapeHtml(msg.content)}`}
let currentQuery = 'tag:inbox'; let isLoading = false; async function api(endpoint) { console.log('API call:', endpoint); const res = await fetch(`/api/${endpoint}`); console.log('Response status:', res.status); if (!res.ok) { const text = await res.text(); console.error('API error response:', text); throw new Error(`API error: ${res.status}`); } const data = await res.json(); console.log('API response:', data); return data; } function setStatus(state) { const status = document.getElementById('status'); status.className = state === 'loading' ? 'status-loading' : state === 'ok' ? 'status-ok' : 'status-error'; } function setLoading(loading) { isLoading = loading; const btn = document.querySelector('.search-bar button'); btn.disabled = loading; btn.textContent = loading ? 'Loading...' : 'Search'; } async function search() { if (isLoading) return; const query = document.getElementById('search').value; currentQuery = query; history.pushState({ query }, '', `/?q=${encodeURIComponent(query)}`); await loadThreads(query); } async function loadThreads(query) { setLoading(true); setStatus('loading'); const list = document.getElementById('thread-list'); try { const threads = await api(`query/${encodeURIComponent(query)}`); if (!threads || threads.length === 0) { list.innerHTML = '
${escapeHtml(msg.content)}`}