-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from BerkeAras/feature/41
Feature/41
- Loading branch information
Showing
7 changed files
with
13,030 additions
and
39,446 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,120 @@ | ||
import React, { useState, useEffect } from 'react' | ||
import { Input, Form } from 'semantic-ui-react' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { library } from '@fortawesome/fontawesome-svg-core' | ||
import { faUser, faUsers, faCalendarDay, faHashtag } from '@fortawesome/free-solid-svg-icons' | ||
import './style.scss' | ||
library.add(faUsers) | ||
library.add(faCalendarDay) | ||
library.add(faHashtag) | ||
|
||
const SearchField = () => { | ||
const [searchQuery, setSearchQuery] = useState('') | ||
const [userResult, setUserResult] = useState([]) | ||
const [topicResult, setTopicResult] = useState([]) | ||
const [isLoadingResults, setIsLoadingResults] = useState(false) | ||
|
||
const searchQueryChangeHandler = (event) => { | ||
setSearchQuery(event.target.value) | ||
const controller = new AbortController() | ||
const { signal } = controller | ||
|
||
if (event.target.value == '') { | ||
setUserResult([]) | ||
setTopicResult([]) | ||
setIsLoadingResults(false) | ||
} else { | ||
controller.abort() | ||
var tokenHeaders = new Headers() | ||
tokenHeaders.append('Authorization', 'Bearer ' + localStorage.getItem('token')) | ||
|
||
var requestOptions = { | ||
method: 'GET', | ||
headers: tokenHeaders, | ||
redirect: 'follow', | ||
} | ||
|
||
let popularItems = '' | ||
|
||
setIsLoadingResults(true) | ||
|
||
// eslint-disable-next-line no-undef | ||
fetch(process.env.REACT_APP_API_URL + '/api/search?query=' + event.target.value, requestOptions, { signal }) | ||
.then((response) => response.json()) | ||
.then((result) => { | ||
let userResult = result[0] | ||
let topicResult = result[1] | ||
|
||
setUserResult(userResult) | ||
setTopicResult(topicResult) | ||
|
||
setIsLoadingResults(false) | ||
}) | ||
.catch((error) => console.log('error', error)) | ||
} | ||
} | ||
|
||
const searchFieldFocus = () => { | ||
document.querySelector('.SearchFieldBackdrop').classList.add('SearchFieldBackdrop-visible') | ||
document.querySelector('.SearchField-Results').classList.add('SearchField-Results-visible') | ||
document.querySelector('.SearchField').classList.add('SearchField-expanded') | ||
} | ||
const searchFieldFocusOut = () => { | ||
setTimeout(function () { | ||
if (document.querySelector('.SearchField').contains(document.activeElement) == false) { | ||
document.querySelector('.SearchFieldBackdrop').classList.remove('SearchFieldBackdrop-visible') | ||
document.querySelector('.SearchField-Results').classList.remove('SearchField-Results-visible') | ||
document.querySelector('.SearchField').classList.remove('SearchField-expanded') | ||
} else { | ||
searchFieldFocus() | ||
} | ||
}, 10) | ||
} | ||
|
||
return ( | ||
<React.Fragment> | ||
<div className="SearchField" onBlur={searchFieldFocusOut}> | ||
<form> | ||
<input value={searchQuery} onFocus={searchFieldFocus} onChange={searchQueryChangeHandler} placeholder="Search for colleagues, groups, events and more..." /> | ||
{isLoadingResults && <span className="loader"></span>} | ||
</form> | ||
|
||
<div className="SearchField-Results" tabIndex="0"> | ||
<ul> | ||
{userResult.length > 0 && ( | ||
<React.Fragment> | ||
<span className="divider">Users</span> | ||
{userResult.map((user) => { | ||
return ( | ||
<li key={user.id}> | ||
<a href="#"> | ||
<FontAwesomeIcon icon="user" /> {user.name} <small>Rechtsabteilung</small> | ||
</a> | ||
</li> | ||
) | ||
})} | ||
</React.Fragment> | ||
)} | ||
{topicResult.length > 0 && ( | ||
<React.Fragment> | ||
<span className="divider">Topics</span> | ||
{topicResult.map((topic) => { | ||
return ( | ||
<li key={topic.id}> | ||
<a href="#"> | ||
<FontAwesomeIcon icon="hashtag" /> {topic.topic} | ||
</a> | ||
</li> | ||
) | ||
})} | ||
</React.Fragment> | ||
)} | ||
</ul> | ||
</div> | ||
</div> | ||
<div className="SearchFieldBackdrop" onClick={searchFieldFocusOut}></div> | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
export default SearchField |
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,190 @@ | ||
@import '../../scss/variables'; | ||
|
||
@keyframes around { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
.SearchField { | ||
height: 40px; | ||
width: 300px; | ||
float: left; | ||
margin: 5px 0 5px 25px; | ||
transition: all 0.3s; | ||
z-index: 11; | ||
position: relative; | ||
|
||
form { | ||
height: 100%; | ||
|
||
input { | ||
height: 100%; | ||
background: #f7f7f7; | ||
transition: all 0.25s; | ||
width: 100%; | ||
border-radius: 7px; | ||
padding: 1px 10px; | ||
outline: 0; | ||
font-family: 'Inter', sans-serif; | ||
box-shadow: 0 0 transparent; | ||
border: 2px solid white; | ||
|
||
&::placeholder { | ||
font-family: 'Inter', sans-serif; | ||
} | ||
&:focus { | ||
background: white; | ||
color: black; | ||
box-shadow: 0 3px 6px -4px #00182b6b; | ||
border: 2px solid $primary-color; | ||
} | ||
} | ||
.loader { | ||
height: 25px; | ||
width: 25px; | ||
display: inline-block; | ||
position: absolute; | ||
top: 7.5px; | ||
right: 7.5px; | ||
border: 2px solid #f3f3f3; | ||
border-radius: 50%; | ||
border-top: 2px solid $primary-color; | ||
animation: around 0.7s linear infinite; | ||
} | ||
} | ||
|
||
&-expanded { | ||
input { | ||
padding: 1px 37px 1px 10px !important; | ||
} | ||
} | ||
|
||
&:focus-within { | ||
width: 400px; | ||
|
||
input { | ||
background: white; | ||
color: black; | ||
box-shadow: 0 3px 6px -4px #00182b6b; | ||
border: 2px solid $primary-color; | ||
} | ||
} | ||
|
||
&-Results { | ||
outline: 0; | ||
display: none; | ||
width: calc(400px - 4px); | ||
max-height: 350px; | ||
overflow: auto; | ||
background: white; | ||
padding: 10px 5px; | ||
margin-top: 5px; | ||
margin-left: 2px; | ||
border-radius: 5px; | ||
box-shadow: 0 3px 8px 0px #00182b40; | ||
|
||
&-visible { | ||
display: block; | ||
} | ||
|
||
span.divider { | ||
font-size: 12px; | ||
display: inline-block; | ||
margin-left: 13px; | ||
padding: 1px 0; | ||
letter-spacing: 1px; | ||
text-transform: uppercase; | ||
font-weight: bold; | ||
color: #798288; | ||
margin-top: 6px; | ||
margin-bottom: 3px; | ||
} | ||
|
||
ul { | ||
margin: 0; | ||
padding: 0; | ||
list-style-type: none; | ||
|
||
a { | ||
position: relative; | ||
display: inline-block; | ||
width: 100%; | ||
line-height: 40px; | ||
padding: 0 15px; | ||
color: black; | ||
font-size: 16px; | ||
font-weight: 600; | ||
border-radius: 10px; | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
transition: all 0.2s; | ||
|
||
&:hover { | ||
background-color: #eeeeee; | ||
transform: scale(0.98); | ||
|
||
small { | ||
color: $primary-color; | ||
} | ||
} | ||
&:active { | ||
transform: scale(0.95); | ||
outline: none !important; | ||
} | ||
&:focus { | ||
outline: 1px dashed black !important; | ||
outline-offset: 2px !important; | ||
} | ||
|
||
svg { | ||
color: #a0b0b9; | ||
margin-right: 10px; | ||
width: 25px !important; | ||
} | ||
small { | ||
font-weight: 100; | ||
color: #868686; | ||
letter-spacing: 0.3px; | ||
margin-left: 5px; | ||
font-size: 12px; | ||
padding: 1px 8px; | ||
background: #efefef; | ||
display: inline-block; | ||
position: absolute; | ||
line-height: 20px; | ||
border-radius: 100px; | ||
text-align: center; | ||
top: calc((100% - 22px) / 2); | ||
right: 10px; | ||
} | ||
} | ||
} | ||
|
||
&-More { | ||
display: inline-block; | ||
width: 100%; | ||
text-align: center; | ||
padding: 7px 0px; | ||
color: $primary-color; | ||
|
||
&:hover { | ||
text-decoration: underline; | ||
} | ||
} | ||
} | ||
} | ||
.SearchFieldBackdrop { | ||
&-visible { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background: rgba(0, 0, 0, 0.4); | ||
z-index: 10; | ||
} | ||
} |
Oops, something went wrong.