-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
166 additions
and
3 deletions.
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
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,71 @@ | ||
.search-section { | ||
width: 20%; | ||
margin: auto; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
min-width: 200px; | ||
position: absolute; | ||
top: 25%; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
} | ||
|
||
.search-input-wrapper { | ||
background-color: white; | ||
width: 100%; | ||
border-radius: 10px; | ||
height: 2.5rem; | ||
padding: 0 15px; | ||
box-shadow: 0px 0px 8px #ddd; | ||
display: flex; | ||
align-items: center; | ||
position: relative; | ||
} | ||
|
||
.search { | ||
flex: 1; | ||
padding: 0 20px; | ||
font-size: 20px; | ||
background-color: transparent; | ||
border: none; | ||
} | ||
|
||
.search:focus { | ||
outline: none; | ||
} | ||
|
||
.search-icon { | ||
cursor: pointer; | ||
} | ||
|
||
.search-result { | ||
width: 100%; | ||
background-color: white; | ||
display: flex; | ||
flex-direction: column; | ||
box-shadow: 0px 0px 8px #ddd; | ||
border-radius: 10px; | ||
margin-top: 1rem; | ||
max-height: 300px; | ||
overflow-y: scroll; | ||
position: absolute; | ||
top: 75%; | ||
z-index: 10; | ||
} | ||
|
||
.search-result::-webkit-scrollbar { | ||
display: none; | ||
} | ||
|
||
.search-suggestion-line { | ||
text-decoration: none; | ||
color: black; | ||
flex-direction: column; | ||
padding: 10px 20px; | ||
transition: background-color 0.2s ease-in-out; | ||
} | ||
|
||
.search-suggestion-line:hover { | ||
background: #efefef; | ||
} |
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,66 @@ | ||
import React, {useState, useEffect} from 'react'; | ||
import { FaSearch } from 'react-icons/fa'; | ||
import { ImCross } from 'react-icons/im'; | ||
|
||
import './Search.css'; | ||
|
||
|
||
export const Search = () => { | ||
const [search, setSearch] = useState(''); | ||
const [searchData, setSearchData] = useState([]); | ||
|
||
const handleChange = e => { | ||
setSearch(e.target.value) | ||
}; | ||
|
||
const handleClose = () => { | ||
setSearch(''); | ||
setSearchData([]); | ||
} | ||
|
||
useEffect(() => { | ||
if(search !== '') { | ||
fetch(`http://127.0.0.1:5000/search?q=${search}`) | ||
.then((res) => res.json()) | ||
.then((data) => setSearchData(data)); | ||
} else { | ||
setSearchData([]); | ||
} | ||
}, [search]) | ||
|
||
return ( | ||
<div className='search-section'> | ||
<div className='search-input-wrapper'> | ||
<div className='search-icon' > | ||
{search === '' ? ( | ||
<FaSearch /> | ||
) : ( | ||
<ImCross onClick={handleClose} /> | ||
)} | ||
</div> | ||
<input | ||
type='text' | ||
className='search' | ||
placeholder='Search...' | ||
autoComplete='off' | ||
onChange={handleChange} | ||
value={search} | ||
/> | ||
</div> | ||
<div className='search-result'> | ||
{searchData.map((data, index) => { | ||
return ( | ||
<a | ||
href={data.username} | ||
key={index} | ||
target='_blank' | ||
className='search-suggestion-line'> | ||
{data.username} | ||
</a> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
export default Search; |
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
Binary file not shown.
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