Skip to content

Commit

Permalink
Add posts to search
Browse files Browse the repository at this point in the history
  • Loading branch information
BerkeAras committed Mar 19, 2022
1 parent c93349b commit 390a8e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
29 changes: 26 additions & 3 deletions src/components/Header/HeaderSearchField/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ConfigContext from '../../../store/ConfigContext'
// Icons
import { library } from '@fortawesome/fontawesome-svg-core'
import { faUsers, faCalendarDay, faHashtag } from '@fortawesome/free-solid-svg-icons'
import { User, Search, Hash, Users, Zap, AlertTriangle, Folder, FileText } from 'react-feather'
import { User, Search, Hash, Users, Zap, AlertTriangle, Folder, FileText, BookOpen } from 'react-feather'
library.add(faUsers)
library.add(faCalendarDay)
library.add(faHashtag)
Expand All @@ -21,6 +21,7 @@ const SearchField = () => {
const [topicResult, setTopicResult] = useState([])
const [knowledgeBaseFoldersResult, setKnowledgeBaseFoldersResult] = useState([])
const [knowledgeBaseFilesResult, setKnowledgeBaseFilesResult] = useState([])
const [postsResult, setPostsResult] = useState([])
const [isLoadingResults, setIsLoadingResults] = useState(false)
const [minimumSearchLength, setMinimumSearchLength] = useState(3)

Expand Down Expand Up @@ -51,6 +52,7 @@ const SearchField = () => {
setTopicResult([])
setKnowledgeBaseFoldersResult([])
setKnowledgeBaseFilesResult([])
setPostsResult([])
setIsLoadingResults(false)
} else {
controller.abort()
Expand All @@ -76,12 +78,14 @@ const SearchField = () => {
let topicResult = result[2]
let knowledgeBaseFolders = result[3]
let knowledgeBaseFiles = result[4]
let postResult = result[5]

setUserResult(userResult)
setGroupResult(groupResult)
setTopicResult(topicResult)
setKnowledgeBaseFoldersResult(knowledgeBaseFolders)
setKnowledgeBaseFilesResult(knowledgeBaseFiles)
setPostsResult(Object.keys(postResult).map((key) => postResult[key]))

setIsLoadingResults(false)
})
Expand Down Expand Up @@ -123,7 +127,7 @@ const SearchField = () => {
value={searchQuery}
onFocus={searchFieldFocus}
onChange={searchQueryChangeHandler}
placeholder="Search for colleagues, groups, events and more..."
placeholder="Search for colleagues, groups, files and more..."
/>
{isLoadingResults && <span className="loader"></span>}
</form>
Expand Down Expand Up @@ -204,6 +208,23 @@ const SearchField = () => {
})}
</>
)}
{(postsResult && postsResult.length > 0) && (
<>
<span className="divider">Posts</span>
{postsResult.map((postResult) => {
return (
<li key={postResult.id}>
<Link
onClick={() => document.activeElement.blur()}
to={'/app/post/' + postResult.id}
>
<BookOpen size={18} strokeWidth={2.7} /> {postResult.post_content}
</Link>
</li>
)
})}
</>
)}

{userResult &&
groupResult &&
Expand All @@ -214,6 +235,7 @@ const SearchField = () => {
topicResult.length == 0 &&
knowledgeBaseFoldersResult.length == 0 &&
knowledgeBaseFilesResult.length == 0 &&
postsResult.length == 0 &&
searchQuery.length >= minimumSearchLength && (
<center className="search-error">
<AlertTriangle size={35} strokeWidth={2} />
Expand All @@ -227,12 +249,13 @@ const SearchField = () => {
topicResult.length == 0 &&
knowledgeBaseFoldersResult.length == 0 &&
knowledgeBaseFilesResult.length == 0 &&
postsResult.length == 0 &&
searchQuery.length < minimumSearchLength) ||
searchQuery.length == 0) && (
<center className="search-error">
<Zap size={35} strokeWidth={2} />
<br />
<span>Search for colleagues, groups, events and more...</span>
<span>Search for colleagues, groups, files and more...</span>
</center>
)}
</ul>
Expand Down
6 changes: 4 additions & 2 deletions src/views/App/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ body {
.app {
padding: 0;
background: #f0f5f7;
overflow: auto !important;
overflow-x: hidden;
overflow-y: auto !important;
}

.main_content {
padding: 0 calc((100% - 1200px) / 2);
}
Expand All @@ -28,4 +30,4 @@ body ::-webkit-scrollbar {

body ::-webkit-scrollbar-thumb {
background: $primary-color !important;
}
}

0 comments on commit 390a8e2

Please sign in to comment.