refactor Search
This commit is contained in:
parent
b0ff34f097
commit
a25df086f3
@ -104,6 +104,7 @@ export const Headline = (prop: {
|
||||
<Divider />
|
||||
{prop.menu}
|
||||
</>);
|
||||
|
||||
return (<div style={{ display: 'flex' }}>
|
||||
<CssBaseline />
|
||||
<AppBar position="fixed" sx={{
|
||||
@ -141,18 +142,13 @@ export const Headline = (prop: {
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center'
|
||||
}}>
|
||||
<SearchIcon onClick={() => navigate(`/search?word=${encodeURIComponent(search)}`)} />
|
||||
<SearchIcon onClick={() => navSearch(search)} />
|
||||
</div>
|
||||
<StyledInputBase placeholder="search"
|
||||
onChange={(e) => 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}></StyledInputBase>
|
||||
@ -207,6 +203,14 @@ export const Headline = (prop: {
|
||||
{prop.children}
|
||||
</main>
|
||||
</div>);
|
||||
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;
|
Loading…
Reference in New Issue
Block a user