Add multi-tag selection support to tag-picker without client side JS

This commit is contained in:
2026-01-14 15:03:23 -08:00
parent 85946a2b40
commit 560020632f
2 changed files with 29 additions and 8 deletions

View File

@@ -19,15 +19,30 @@ export function TagPicker({ searchParams }: { searchParams?: URLSearchParams })
<h3>Tags</h3>
<ul className="tag-pills">
{tags.map(tag => {
const active = selectedTags.includes(tag.urlNormalized)
let active = selectedTags.includes(tag.urlNormalized)
let hyperlink = `/?tag=${tag.urlNormalized}`;
for (const existingTag of selectedTags) {
hyperlink += `&tag=${existingTag}`
}
// Remove the currently selected tag from the tag link url if applicable
if (active) {
hyperlink = hyperlink.split(`?tag=${tag.urlNormalized}`).join('')
hyperlink = hyperlink.split(`&tag=${tag.urlNormalized}`).join('')
}
// Make sure the hyperlink starts with a ? and not a & (or the root webpage)
hyperlink = '/?' + hyperlink.substring(2)
if(hyperlink.length == 2) hyperlink = '/'
return (
< li key={tag.name} >
<a
title={`${tag.post_count} post${tag.post_count !== 1 ? 's' : ''} (click to view)`}
title={active ? `Remove ${tag.name} from filter` : `Add ${tag.name} to filter`}
data-tag
className={`tag-pill ${active ? 'active' : ''}`}
href={`?tag=${tag.urlNormalized}`}
href={hyperlink}
>
{tag.name}
</a>