Skip to content

Commit

Permalink
Merge cb59b5f into e657b9e
Browse files Browse the repository at this point in the history
  • Loading branch information
harerakalex committed Nov 12, 2019
2 parents e657b9e + cb59b5f commit 3877de3
Show file tree
Hide file tree
Showing 18 changed files with 637 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import UpdateProfile from '../feature/profile/update_profile/UpdateProfileCompon
import ForgotPassword from '../feature/Reset Password/forgot password/ForgotPasswordComponent';
import ResetPassword from '../feature/Reset Password/reset password/ResetPasswordComponent';
import UpdateArticle from '../feature/articles/updateArticle/UpdateArticleComponent';
import Search from '../feature/articles/SearchArticle/SearchComponent';
import '../../node_modules/font-awesome/css/font-awesome.min.css';

toast.configure();
Expand All @@ -41,6 +42,7 @@ function App() {
<Route exact path="/articles/:slug" component={GetSingleArticle} />
<ProtectedRoutes path="/create" component={CreateArticle} />
<ProtectedRoutes path="/article/:slug/update" component={UpdateArticle} />
<Route path="/search" component={Search} />
</section>
</Switch>
</BrowserRouter>
Expand Down
Binary file added src/app/common/images/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/app/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import commentReducer from '../../feature/comment/CommentReducer';
import socialReducer from '../../feature/auth/socialLogin/SocialReducer';
import bookmarkReducer from '../../feature/bookmark/bookmarkReducer';
import getSingleArticle from '../../feature/articles/getSingleArticle/GetSingleArticleReducer';
import searchResult from '../../feature/articles/SearchArticle/SearchReducer';

export default combineReducers({
login: loginReducer,
Expand All @@ -26,5 +27,6 @@ export default combineReducers({
getSingleArticle,
social: socialReducer,
comment: commentReducer,
bookmarking: bookmarkReducer
bookmarking: bookmarkReducer,
searchResult
});
8 changes: 6 additions & 2 deletions src/app/routes/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export class Navbar extends Component {
<div className="right">
<ul>
<li>
<Link to="/">Home</Link>
<Link to="/search">
<i className="fa fa-search" title="search" />
</Link>
</li>
<li>
<Link to="/login">Login</Link>
Expand All @@ -107,7 +109,9 @@ export class Navbar extends Component {
<div className="right" id="right">
<ul>
<li>
<Link to="/">Home</Link>
<Link to="/search">
<i className="fa fa-search" />
</Link>
</li>
<div className="notification-dropdown">
<li className="img-list-item notification-container">
Expand Down
101 changes: 101 additions & 0 deletions src/feature/articles/SearchArticle/Search.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
.result-container {
width: 60%;
margin: 30px auto;

.result-link {
text-decoration: none;
}

.result-article {
display: flex;
width: 100%;
height: 200px;
margin-bottom: 20px;

&__image {
width: 30%;

> img {
width: 100%;
height: 100%;
}
}

&__content {
width: 70%;

> h1 {
font-size: 20px;
margin: 0 0 10px 20px;
padding: 0;
color: black;
font-weight: bold;
}
> p {
margin: 0 0 0 20px;
color: #5c5a5a;
}

.description {
margin-bottom: 20px;
max-height: 42px;
overflow: hidden;
}

.time {
> span {
margin-right: 10px;
font-weight: bold;
}
}

.author {
margin-top: 15px;
> span {
font-weight: bold;
}
}
}
}
.article-not-found {
text-align: center;
> p {
font-weight: bold;
}
}
}
@media (min-width: 768px) and (max-width: 1024px) {
.result-container {
width: 85%;
}
}
@media (max-width: 700px) {
.result-container {
width: 90%;
.result-article {
display: flex;
flex-wrap: wrap;
height: 300px;
margin-bottom: 30px;
border-bottom: 1px solid #888888;

&__image {
width: 100%;
height: 130px;
margin-bottom: 10px;
}
&__content {
width: 100%;

> h1,
p {
margin: 0;
font-size: 12px;
}
.description {
height: 38px;
}
}
}
}
}
26 changes: 26 additions & 0 deletions src/feature/articles/SearchArticle/SearchAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable react/react-in-jsx-scope */
import axios from 'axios';
import * as searchActionTypes from './SearchConstants';
import { BACKEND_URL } from '../../../app/common/config/appConfig';

export const searchSuccess = data => ({
type: searchActionTypes.SEARCH_SUCCESS,
payload: data
});
export const searchError = error => ({
type: searchActionTypes.SEARCH_ERROR,
payload: error
});

export const search = (query, keyword) => async dispatch => {
try {
const response = await axios.get(
`${BACKEND_URL}/articles?${keyword}=${query}&limit=4`
);
const { data } = response;
dispatch(searchSuccess(data));
} catch (error) {
const { message } = error.response.data;
dispatch(searchError(message));
}
};
30 changes: 30 additions & 0 deletions src/feature/articles/SearchArticle/SearchComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import { connect } from 'react-redux';
import Form from './SearchForm';
import Result from './SearchResult';
import { search } from './SearchAction';
import './Search.scss';

export function SearchComponent(props) {
const { search, results } = props;
return (
<>
<Form
searchAction={search}
/>
<Result
results={results}
/>
</>
);
}

const mapStateToProps = (state) => ({
results: state.searchResult,
});

const mapDispatchToProps = {
search
};

export default connect(mapStateToProps, mapDispatchToProps)(SearchComponent);
2 changes: 2 additions & 0 deletions src/feature/articles/SearchArticle/SearchConstants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const SEARCH_SUCCESS = 'SEARCH_SUCCESS';
export const SEARCH_ERROR = 'SEARCH_ERROR';
78 changes: 78 additions & 0 deletions src/feature/articles/SearchArticle/SearchForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React, { Component } from 'react';
import './SearchForm.scss';

export class SearchForm extends Component {
constructor(props) {
super(props);
this.state = {
query: '',
keyword: 'title',
};
}

onChange = ({ target }) => {
this.setState({
query: target.value,
}, () => {
this.onChangeSearch();
});
}

onChangeSearch = () => {
const { query, keyword } = this.state;
if (query.length > 2) {
const { searchAction } = this.props;
searchAction(query, keyword);
}
}

onSelect = ({ target }) => {
this.setState({
keyword: target.value,
}, () => {
this.onChangeSearch();
});
}

onSearch = event => {
event.preventDefault();
const { query, keyword } = this.state;
console.log(query);
const { searchAction } = this.props;
searchAction(query, keyword);
}

render() {
const { keyword, query } = this.state;
return (
<form onSubmit={this.onSearch} className="search-container">
<div className="search-container__select-group">
<select
className="select-input"
value={keyword}
onChange={this.onSelect}
required
>
<option value="title">Search by title</option>
<option value="author">Search by author</option>
<option value="tags">Search by tag</option>
</select>
</div>
<div className="search-container__input-group">
<input
className="search-input"
type="text"
name="search"
value={query}
onChange={this.onChange}
placeholder="Search by title, author, or tags"
autoComplete="off"
required
/>
</div>
</form>
);
}
}

export default SearchForm;
75 changes: 75 additions & 0 deletions src/feature/articles/SearchArticle/SearchForm.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
.search-container {
display: flex;
width: 60%;
margin: auto;

&__select-group {
width: 30%;

.select-input {
width: 98%;
padding: 10px;
font-size: 15px;
height: 40px;
background: #ffffff;
outline: none;
border: 1px solid gray;
border-radius: 2px !important;
box-sizing: border-box;
}
}

&__input-group {
width: 70%;

.search-input {
background-image: url('../../../app/common/images/search.png');
background-color: #ffffff;
background-repeat: no-repeat;
background-size: 30px 30px;
background-position: right;
width: 98%;
padding: 10px;
font-size: 15px;
height: 40px;
border: 1px solid gray;
border-radius: 4px;
box-sizing: border-box;
}
}
}
@media (min-width: 768px) and (max-width: 1024px) {
.search-container {
width: 85%;
}
}
@media (max-width: 700px) {
.search-container {
display: flex;
flex-wrap: wrap;
width: 90%;
margin-top: 15vh;

&__select-group {
width: 100%;
margin-bottom: 15px;

.select-input {
font-size: 12px;
height: 30px;
padding: 5px;
}
}
&__input-group {
width: 100%;
margin-bottom: 15px;

.search-input {
background-size: 20px 20px;
font-size: 12px;
height: 30px;
padding: 5px;
}
}
}
}
Loading

0 comments on commit 3877de3

Please sign in to comment.