Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
SergiiNikolayev committed Jun 28, 2018
2 parents a9cb036 + 94a35b4 commit f16c4bc
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 43 deletions.
63 changes: 33 additions & 30 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@ class App extends Component {
this.props.onItemDone(id);
};

sortDoneHandler = ( filter ) => {
console.log("filter: " + filter);
this.props.onItemSortDone( filter );
};

sortUnDoneHandler = (filter) => {
console.log(filter);
this.props.onItemSortUnDone(filter);
};

sortAllHandler = (filter) => {
console.log(filter);
this.props.onItemSortAll(filter)
};
/* sortDoneHandler = ( filter ) => {
console.log(filter);
this.props.onItemSortDone( filter );
};
sortUnDoneHandler = (filter) => {
console.log(filter);
this.props.onItemSortUnDone(filter);
};
sortAllHandler = (filter) => {
console.log(filter);
this.props.onItemSortAll(filter)
};*/

render() {
return (
Expand All @@ -52,9 +50,9 @@ class App extends Component {
/>
<Controls
userClick={this.itemAddHandler}
userClickFilterOne={e => this.sortDoneHandler(VisibilityFilters.SORT_RED)}
userClickFilterTwo={e => this.sortUnDoneHandler(VisibilityFilters.SORT_BLACK)}
userClickFilterThree={e => this.sortAllHandler(VisibilityFilters.SORT_ALL)}
userClickFilterOne={e => this.props.changeFilter(VisibilityFilters.SORT_RED)}
userClickFilterTwo={e => this.props.changeFilter(VisibilityFilters.SORT_BLACK)}
userClickFilterThree={e => this.props.changeFilter(VisibilityFilters.SORT_ALL)}
/>
<ol>
{
Expand All @@ -75,7 +73,7 @@ class App extends Component {

export default connect(
state => ({
//todoItems: state.items,
//odoItems: state.items,
todoItems: getFilteredItems(state) //store
}),
dispatch => ({
Expand All @@ -92,19 +90,24 @@ export default connect(
type: 'MARK_DONE', id
})
},
onItemSortDone: ( filter ) => {
dispatch({
type: filter
})
},
onItemSortUnDone: ( filter ) => {
dispatch({
type: filter
})
},
onItemSortAll: (filter) => {
/* onItemSortDone: ( filter ) => {
dispatch({
type: filter
})
},
onItemSortUnDone: ( filter ) => {
dispatch({
type: filter
})
},
onItemSortAll: (filter) => {
dispatch({
type: filter
})
},*/
changeFilter: (filter) => {
dispatch({
type: filter
type: 'CHANGE_FILTER', filter
})
}
})
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { createStore } from 'redux';

import './index.css';
import App from './App';
import reducerTodo from './store/reducer'
import rootReducer from './store/rootReducer'
/*import reducerFilter from './store/reducerFilter'
import reducerTodo from './store/reducer'*/

const store = createStore(reducerTodo,

const store = createStore(rootReducer,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);

Expand Down
2 changes: 1 addition & 1 deletion src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const MARK_DONE = 'MARK_DONE';
export const SORT_BLACKX = 'SORT_BLACKX';
export const SORT_ALLX = 'SORT_ALLX';*/

export const SET_VISIBILITY_FILTER = 'SET_VISIBILITY_FILTER';
export const CHANGE_FILTER = 'CHANGE_FILTER';

//другие константы

Expand Down
19 changes: 19 additions & 0 deletions src/store/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {CHANGE_FILTER, VisibilityFilters} from './actions';

const initialState = {
currentFilter: VisibilityFilters.SORT_ALL
}

const reducerFilter = (state = initialState, action) => {
switch (action.type) {
case CHANGE_FILTER:
return {
...state,
currentFilter: action.filter
};
default:
return state;
}
};

export default reducerFilter;
6 changes: 3 additions & 3 deletions src/store/reducer.js → src/store/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as actionTypes from './actions';
import {VisibilityFilters} from './actions';

const initialState = {
items: [],
list: [],
};

const testState = {
Expand Down Expand Up @@ -39,7 +39,7 @@ const reducerTodo = (state = initialState, action) => {
case actionTypes.ADD:
return {
...state,
items: state.items.concat([
list: state.list.concat([
{
isDone: false,
/* currentFilter: VisibilityFilters.SORT_BLACK,*/
Expand All @@ -51,7 +51,7 @@ const reducerTodo = (state = initialState, action) => {

case actionTypes.MARK_DONE:
return {
items: state.items.map( element =>
list: state.list.map( element =>
(element.id === action.id )
? {...element, isDone: !element.isDone}
: { ...element})
Expand Down
8 changes: 8 additions & 0 deletions src/store/rootReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { combineReducers } from 'redux';
import items from './items';
import filter from './filter'

export default combineReducers({
items,
filter
})
13 changes: 6 additions & 7 deletions src/store/selects.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ export const getFilteredItems = (store) => {
return items.filter(item => item);
}*/

const currentFilter = store.currentFilter;// достаем текущий фильтр
const items = store.items;
const currentFilter = store.filter.currentFilter;// достаем текущий фильтр
const items = store.items.list;
console.log(currentFilter);

// в зависимости от того какой фильтр, производим соответсвующие действия
if (currentFilter === VisibilityFilters.SORT_RED) {
return items.filter(item => items.isDone);
return items.filter(item => item.isDone);
} else if (currentFilter === VisibilityFilters.SORT_BLACK) {
return items.filter(item => !items.isDone);
} else if (currentFilter === VisibilityFilters.SORT_ALL) {
return items.filter(item => item);
return items.filter(item => !item.isDone);
} else {
return items.filter(item => item);
return items;
}
};

0 comments on commit f16c4bc

Please sign in to comment.