refactor Search
This commit is contained in:
		
							parent
							
								
									b0ff34f097
								
							
						
					
					
						commit
						a25df086f3
					
				
					 1 changed files with 11 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -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…
	
	Add table
		
		Reference in a new issue