Skip to content

Commit

Permalink
Merge pull request #42 from BerkeAras/feature/41
Browse files Browse the repository at this point in the history
Feature/41
  • Loading branch information
BerkeAras authored May 1, 2021
2 parents 019742c + 07e348f commit 694924d
Show file tree
Hide file tree
Showing 7 changed files with 13,030 additions and 39,446 deletions.
39,412 changes: 0 additions & 39,412 deletions package-lock.json

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"autolinker": "^3.14.2",
"axios": "^0.21.1",
"firebase": "^8.2.0",
"focus-trap-react": "^8.5.0",
"linkifyjs": "^2.1.9",
"react": "^17.0.1",
"react-dom": "^17.0.1",
Expand Down
3 changes: 3 additions & 0 deletions src/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MoreVertical, Menu, X } from 'react-feather'

// Components
import HeaderDropdown from '../HeaderDropdown'
import SearchField from '../_Header_Searchfield'

class Header extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -43,6 +44,8 @@ class Header extends React.Component {
<img src={logo} alt="Logo" />
</NavLink>

<SearchField />

<div tabIndex={0} onClick={this.showHeaderDropdown} className="header__dropdown-button">
<MoreVertical></MoreVertical>
</div>
Expand Down
120 changes: 120 additions & 0 deletions src/components/_Header_Searchfield/index.jsx
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
190 changes: 190 additions & 0 deletions src/components/_Header_Searchfield/style.scss
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;
}
}
Loading

0 comments on commit 694924d

Please sign in to comment.