From 6b519381b58384ef6d13df960f9613d6b75141fa Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sun, 8 Mar 2026 19:23:15 +0900 Subject: [PATCH] #68 --- frontend/src/components/TagSearch.tsx | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/TagSearch.tsx b/frontend/src/components/TagSearch.tsx index 6e7a8bd..c46905b 100644 --- a/frontend/src/components/TagSearch.tsx +++ b/frontend/src/components/TagSearch.tsx @@ -54,8 +54,11 @@ export default (() => { if (activeIndex < 0) break ev.preventDefault () - const selected = suggestions[activeIndex] - selected && handleTagSelect (selected) + { + const selected = suggestions[activeIndex] + if (selected) + handleTagSelect (selected) + } break case 'Escape': @@ -65,14 +68,25 @@ export default (() => { } if (ev.key === 'Enter' && (!(suggestionsVsbl) || activeIndex < 0)) { - navigate (`/posts?${ (new URLSearchParams ({ tags: search })).toString () }`) + const parts = search.split (' ') + const match = parts.map (t => t.toLowerCase ()).includes ('type:or') ? 'any' : 'all' + navigate (`/posts?${ + (new URLSearchParams ({ + tags: parts.map (t => t.toLowerCase ()) + .filter (t => t !== 'type:or') + .join (' '), + match })) + .toString () }`) setSuggestionsVsbl (false) } } const handleTagSelect = (tag: Tag) => { const parts = search.split (' ') - parts[parts.length - 1] = tag.name + parts[parts.length - 1] = ( + (parts[parts.length - 1].slice(0, 4).toLowerCase () === 'not:') + ? ('not:' + tag.name) + : tag.name) setSearch (parts.join (' ') + ' ') setSuggestions ([]) setActiveIndex (-1) @@ -80,7 +94,8 @@ export default (() => { useEffect (() => { const query = new URLSearchParams (location.search) - const tagsQuery = query.get ('tags') ?? '' + const anyFlg = query.get ('match') === 'any' + const tagsQuery = `${ query.get ('tags') ?? '' }${ anyFlg ? ' type:or' : '' }` setSearch (tagsQuery) }, [location.search])