feat(showtags): endpoint cookie + toggle nel menu utente

This commit is contained in:
2026-07-05 22:05:46 +02:00
parent 71cd1626e0
commit 842371604b
2 changed files with 34 additions and 2 deletions
+16 -2
View File
@@ -6,7 +6,7 @@ interface Props {
showTags: boolean;
canTags: boolean;
}
const { user, canTags } = Astro.props;
const { user, canTags, showTags } = Astro.props;
const path = Astro.url.pathname;
const loginHref = `/login?next=${encodeURIComponent(path)}`;
const areaHref = user?.role === 'superuser' ? '/admin/content' : '/admin';
@@ -26,7 +26,7 @@ const areaHref = user?.role === 'superuser' ? '/admin/content' : '/admin';
<div class="umenu__panel">
<a href={areaHref}>Area riservata</a>
{canTags && (
<button type="button" class="umenu__tags" id="toggle-tags" data-slot="tags">Mostra tag</button>
<button type="button" class="umenu__tags" id="toggle-tags" data-on={showTags ? '1' : '0'}>{showTags ? 'Nascondi tag' : 'Mostra tag'}</button>
)}
<a href="/admin/logout">Esci</a>
</div>
@@ -76,4 +76,18 @@ const areaHref = user?.role === 'superuser' ? '/admin/content' : '/admin';
const open = nav.classList.toggle('is-open');
toggle.setAttribute('aria-expanded', String(open));
});
const tagsBtn = document.getElementById('toggle-tags');
if (tagsBtn) {
const on = tagsBtn.dataset.on === '1';
tagsBtn.addEventListener('click', async () => {
const res = await fetch('/api/admin/showtags', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ on: !on }),
});
if (res.ok) location.reload();
else alert('Operazione non riuscita.');
});
}
</script>