-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Advanced search #2199
Closed
Closed
Advanced search #2199
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
43fa87c
updated
d5785de
deleted files
f013330
minor change, remove hover effect, only focus effect
94e3602
added advanced search, NOT YET
9a5e871
small fix
6e816c2
close dialog when hit search
8104a61
do not search when input is empty
41fbab1
changes
3211390
changes
a7be9a6
changes
38d6778
updated
d50f9a5
update
503a101
update
7e3adde
update
185d051
update state from SearchProvider
dfecd99
use Route in local component
4dce0d0
fix
070b7d8
update
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
import CloseIcon from '@material-ui/icons/Close'; | ||
import { Dialog, DialogContent, DialogTitle, IconButton } from '@material-ui/core'; | ||
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'; | ||
import FormControl from '@material-ui/core/FormControl'; | ||
import FormGroup from '@material-ui/core/FormGroup'; | ||
import FormControlLabel from '@material-ui/core/FormControlLabel'; | ||
import Checkbox from '@material-ui/core/Checkbox'; | ||
import React, { useState } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
|
||
interface Props { | ||
setOpenDialog: Function; | ||
openDialog: boolean; | ||
} | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
root: { | ||
position: 'absolute', | ||
top: '50%', | ||
transform: 'translateY(-120%)', | ||
}, | ||
dialogTitle: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
width: '600px', | ||
[theme.breakpoints.down('xs')]: { | ||
width: 'calc(100vw - 80px)', | ||
}, | ||
height: '25px', | ||
padding: 15, | ||
background: '#eeeeee', | ||
overflow: 'hidden', | ||
}, | ||
dialogContent: { | ||
background: '#eeeeee', | ||
height: '300px', | ||
color: 'black', | ||
fontSize: '1.8rem', | ||
'& p': { | ||
color: '#999999', | ||
}, | ||
}, | ||
input: { | ||
width: '100%', | ||
boxSizing: 'border-box', | ||
borderRadius: '20px', | ||
padding: '10px 15px', | ||
outline: 'none', | ||
border: 'solid 1px #999', | ||
marginBottom: '15px', | ||
}, | ||
closeIcon: { | ||
fontSize: '2.8rem', | ||
position: 'absolute', | ||
padding: '10px', | ||
color: '#999999', | ||
}, | ||
searchButton: { | ||
padding: '10px 25px', | ||
position: 'absolute', | ||
right: '10px', | ||
top: '10px', | ||
border: 'solid 1px #1ea0f0', | ||
borderRadius: '20px', | ||
outline: 'none', | ||
cursor: 'pointer', | ||
color: '#fff', | ||
background: '#1ea0f0', | ||
transition: 'background .2s', | ||
fontWeight: 'bold', | ||
'&:hover': { | ||
background: '#3da8e8', | ||
}, | ||
}, | ||
title: { | ||
display: 'inline', | ||
position: 'absolute', | ||
top: 0, | ||
marginLeft: '20px', | ||
overflow: 'hidden', | ||
fontSize: '1.6rem', | ||
color: '#999999', | ||
}, | ||
formControl: { | ||
padding: 0, | ||
margin: 0, | ||
}, | ||
formLabel: { | ||
fontSize: '1.8rem', | ||
color: 'black', | ||
}, | ||
}) | ||
); | ||
|
||
const AdvancedSearchDialog = (props: Props) => { | ||
const router = useRouter(); | ||
const classes = useStyles(); | ||
|
||
const [newSearchTerm, setnewSearchTerm] = useState(''); | ||
const [advancedSearchInAuthor, setAdvancedSearchInAuthor] = useState(false); | ||
|
||
const handleClose = () => { | ||
props.setOpenDialog(false); | ||
setAdvancedSearchInAuthor(false); | ||
}; | ||
|
||
const handleCheckboxChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setAdvancedSearchInAuthor(e.target.checked); | ||
}; | ||
|
||
const handleSearch = (searchTerm: string) => { | ||
if (advancedSearchInAuthor) router.push(`/search?text=${searchTerm}&filter=author`); | ||
else router.push(`/search?text=${searchTerm}&filter=post`); | ||
}; | ||
|
||
return ( | ||
<Dialog | ||
maxWidth="md" | ||
open={props.openDialog} | ||
onClose={handleClose} | ||
classes={{ | ||
paper: classes.root, | ||
}} | ||
> | ||
<DialogTitle className={classes.dialogTitle}> | ||
<IconButton onClick={handleClose} aria-label="search"> | ||
<CloseIcon className={classes.closeIcon} /> | ||
</IconButton> | ||
|
||
<p className={classes.title}>Advanced Search</p> | ||
|
||
<button | ||
className={classes.searchButton} | ||
onClick={(e) => { | ||
if (newSearchTerm) { | ||
e.preventDefault(); | ||
handleSearch(newSearchTerm); | ||
} | ||
handleClose(); | ||
}} | ||
> | ||
Search | ||
</button> | ||
</DialogTitle> | ||
|
||
<DialogContent className={classes.dialogContent}> | ||
<form | ||
onSubmit={(e) => { | ||
if (newSearchTerm) { | ||
e.preventDefault(); | ||
handleSearch(newSearchTerm); | ||
} | ||
handleClose(); | ||
}} | ||
> | ||
<input | ||
huyxgit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
autoFocus | ||
type="text" | ||
value={newSearchTerm} | ||
onChange={(e) => setnewSearchTerm(e.target.value)} | ||
className={classes.input} | ||
/> | ||
</form> | ||
<FormControl component="fieldset" className={classes.formControl}> | ||
<p>Filters</p> | ||
<FormGroup> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox checked={advancedSearchInAuthor} onChange={handleCheckboxChange} /> | ||
} | ||
label="Search in Authors" | ||
/> | ||
</FormGroup> | ||
</FormControl> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default AdvancedSearchDialog; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using
black
you can use#000000
instead.