Always show tags section with placeholder or error message

This commit is contained in:
2026-05-27 12:01:23 -04:00
parent 73593f5e89
commit fcf134d37e
+13 -6
View File
@@ -492,24 +492,31 @@
async _fetchSuggestions(prefix, vault) { async _fetchSuggestions(prefix, vault) {
suggestAbortController = new AbortController(); suggestAbortController = new AbortController();
// Fetch titles and tags independently so one failure doesn't block the other // Fetch titles
try { try {
const titlesRes = await api(`/api/suggest?q=${encodeURIComponent(prefix)}&vault=${encodeURIComponent(vault)}&limit=5`, { signal: suggestAbortController.signal }); const titlesRes = await api(`/api/suggest?q=${encodeURIComponent(prefix)}&vault=${encodeURIComponent(vault)}&limit=5`, { signal: suggestAbortController.signal });
this._renderTitles(titlesRes.suggestions || [], prefix); this._renderTitles(titlesRes.suggestions || [], prefix);
this._titlesSection.hidden = !(titlesRes.suggestions || []).length; this._titlesSection.hidden = !(titlesRes.suggestions || []).length;
if (titlesRes.suggestions?.length) this.show(); if (titlesRes.suggestions?.length) this.show();
} catch (err) { } catch (err) {
if (err.name === "AbortError") return; // new request superseded this one if (err.name === "AbortError") return;
this._titlesSection.hidden = true; this._titlesSection.hidden = true;
} }
// Fetch tags — keep section always visible to confirm it works
try { try {
const tagsRes = await api(`/api/tags/suggest?q=${encodeURIComponent(prefix)}&vault=${encodeURIComponent(vault)}&limit=5`, { signal: suggestAbortController.signal }); const tagsRes = await api(`/api/tags/suggest?q=${encodeURIComponent(prefix)}&vault=${encodeURIComponent(vault)}&limit=5`, { signal: suggestAbortController.signal });
this._renderTags(tagsRes.suggestions || [], prefix); const items = tagsRes.suggestions || [];
this._tagsSection.hidden = !(tagsRes.suggestions || []).length; if (items.length > 0) {
if (tagsRes.suggestions?.length) this.show(); this._renderTags(items, prefix);
} else {
this._tagsList.innerHTML = '<li class="search-dropdown__item" style="color:var(--text-muted);font-style:italic;padding:8px 12px">Aucun tag</li>';
}
this._tagsSection.hidden = false;
this.show();
} catch (err) { } catch (err) {
if (err.name === "AbortError") return; if (err.name === "AbortError") return;
this._tagsSection.hidden = true; this._tagsList.innerHTML = '<li class="search-dropdown__item" style="color:var(--text-error);padding:8px 12px">Erreur chargement</li>';
this._tagsSection.hidden = false;
} }
this._collectItems(); this._collectItems();
}, },