-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
done HT3 #28
Open
reyzele
wants to merge
4
commits into
romabelka:master
Choose a base branch
from
reyzele:HT3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
done HT3 #28
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import React, { Component } from 'react' | ||
import DateRange from './date-range' | ||
import SelectFilter from './select' | ||
import { connect } from 'react-redux' | ||
|
||
class Filters extends Component { | ||
static propTypes = {} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<SelectFilter articles={this.props.articles} /> | ||
<SelectFilter | ||
articles={this.props.articles} | ||
selected={this.props.filters.entities} | ||
/> | ||
<DateRange /> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default Filters | ||
export default connect((state) => ({ | ||
articles: state.articles, | ||
filters: state.filters | ||
}))(Filters) |
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 |
---|---|---|
@@ -1,15 +1,24 @@ | ||
import React, { Component } from 'react' | ||
import Select from 'react-select' | ||
import { connect } from 'react-redux' | ||
import { filterArticle } from '../../ac' | ||
|
||
class SelectFilter extends Component { | ||
state = { | ||
selected: null | ||
} | ||
handleChange = (selected) => { | ||
const { filterArticle } = this.props | ||
const filtersArr = [] | ||
|
||
selected.map((item) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Этого совсем не понял |
||
return filtersArr.push(item) | ||
}) | ||
|
||
handleChange = (selected) => this.setState({ selected }) | ||
return filterArticle(filtersArr) | ||
} | ||
|
||
get options() { | ||
return this.props.articles.map((article) => ({ | ||
const { articles } = this.props | ||
|
||
return articles.map((article) => ({ | ||
label: article.title, | ||
value: article.id | ||
})) | ||
|
@@ -19,12 +28,15 @@ class SelectFilter extends Component { | |
return ( | ||
<Select | ||
options={this.options} | ||
value={this.state.selected} | ||
value={this.props.selected} | ||
onChange={this.handleChange} | ||
isMulti | ||
/> | ||
) | ||
} | ||
} | ||
|
||
export default SelectFilter | ||
export default connect( | ||
null, | ||
{ filterArticle } | ||
)(SelectFilter) |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export const INCREMENT = 'INCREMENT' | ||
|
||
export const DELETE_ARTICLE = 'DELETE_ARTICLE' | ||
export const FILTER_ARTICLE = 'FILTER_ARTICLE' | ||
export const FILTER_DATE = 'FILTER_DATE' |
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,39 @@ | ||
import { FILTER_ARTICLE, DELETE_ARTICLE, FILTER_DATE } from '../constants' | ||
const initialState = { | ||
entities: [], | ||
date: { | ||
from: null, | ||
to: null | ||
} | ||
} | ||
|
||
export default (filtersState = initialState, action) => { | ||
const { type, payload } = action | ||
|
||
switch (type) { | ||
case FILTER_ARTICLE: | ||
return { | ||
...filtersState, | ||
entities: payload ? payload : initialState | ||
} | ||
case DELETE_ARTICLE: | ||
return { | ||
...filtersState, | ||
entities: filtersState.entities.filter( | ||
(item) => item.value !== payload.id | ||
) | ||
} | ||
case FILTER_DATE: | ||
const date = payload.date | ||
|
||
return { | ||
...filtersState, | ||
date: { | ||
from: date.from, | ||
to: date.to | ||
} | ||
} | ||
default: | ||
return filtersState | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { combineReducers } from 'redux' | ||
import counterReducer from './couter' | ||
import counter from './couter' | ||
import articles from './articles' | ||
import filters from './filters' | ||
|
||
export default combineReducers({ | ||
counter: counterReducer, | ||
articles | ||
counter, | ||
articles, | ||
filters | ||
}) |
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 @@ | ||
export const getDate = (state) => state.filters.date |
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,31 @@ | ||
export default (state) => { | ||
const { articles, filters } = state | ||
let result | ||
|
||
if (!filters.entities.length && (!filters.date.from && !filters.date.to)) | ||
return articles | ||
|
||
if (!filters.entities.length) { | ||
result = articles.filter((article) => { | ||
let date = new Date(article.date) | ||
|
||
return ( | ||
(filters.date.from ? date >= filters.date.from : true) && | ||
(filters.date.to ? date <= filters.date.to : true) | ||
) | ||
}) | ||
} else { | ||
result = articles | ||
.filter(({ id }) => filters.entities.some(({ value }) => id === value)) | ||
.filter((article) => { | ||
let date = new Date(article.date) | ||
|
||
return ( | ||
(filters.date.from ? date >= filters.date.from : true) && | ||
(filters.date.to ? date <= filters.date.to : true) | ||
) | ||
}) | ||
} | ||
|
||
return result | ||
} |
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,3 @@ | ||
export { default } from './filters' | ||
|
||
export { getDate } from './date' |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { createStore } from 'redux' | ||
import { createStore, compose } from 'redux' | ||
import reducer from '../reducer' | ||
|
||
const store = createStore(reducer) | ||
|
||
//dev only, no need in prod! | ||
window.store = store | ||
const store = createStore( | ||
reducer, | ||
compose( | ||
window.devToolsExtension ? window.__REDUX_DEVTOOLS_EXTENSION__() : (f) => f | ||
) | ||
) | ||
|
||
export default store |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Удобнее было на уровень ниже доставать