From a25df086f3c43b1e23dc4181f23f35afff53a4ec Mon Sep 17 00:00:00 2001 From: monoid Date: Tue, 21 Jun 2022 14:41:33 +0900 Subject: [PATCH] refactor Search --- src/client/component/headline.tsx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/client/component/headline.tsx b/src/client/component/headline.tsx index b742439..3b35eda 100644 --- a/src/client/component/headline.tsx +++ b/src/client/component/headline.tsx @@ -104,6 +104,7 @@ export const Headline = (prop: { {prop.menu} ); + return (
- navigate(`/search?word=${encodeURIComponent(search)}`)} /> + navSearch(search)} />
setSearch(e.target.value)} onKeyUp={(e) => { if (e.key === "Enter") { - let words = search.includes("&") ? search.split("&") : [search]; - words = words.map(w => w.trim()) - .map(w => w.includes(":") ? - `allow_tag=${w}` - : `word=${encodeURIComponent(w)}`); - navigate(`/search?${words.join("&")}`); + navSearch(search); } }} value={search}> @@ -207,6 +203,14 @@ export const Headline = (prop: { {prop.children} ); + function navSearch(search: string){ + let words = search.includes("&") ? search.split("&") : [search]; + words = words.map(w => w.trim()) + .map(w => w.includes(":") ? + `allow_tag=${w}` + : `word=${encodeURIComponent(w)}`); + navigate(`/search?${words.join("&")}`); + } }; export default Headline; \ No newline at end of file