Skip to content

Commit

Permalink
v0.5.0: + Выделение писем
Browse files Browse the repository at this point in the history
  • Loading branch information
RubaXa committed Jun 16, 2016
1 parent fe02c07 commit 928ec5b
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-octavius",
"version": "0.4.1",
"version": "0.5.0",
"private": true,
"description": "Боль и унижение!",
"main": "index.js",
Expand Down
11 changes: 11 additions & 0 deletions src/actions/selection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {TOGGLE, SELECT_ALL} from '../constants/selection';

export const toggle = (id) => ({
type: TOGGLE,
id,
});

export const selectAll = (threads) => ({
type: SELECT_ALL,
threads
});
2 changes: 1 addition & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class App extends Component {

return <div ref="clickable" onClick={(evt) => this.handleGlobalClick(evt)}>
<Headline/>
<PortalMenu />
<PortalMenu threads={threads}/>
<Layout
bordered
left={<Scrollable content={sidebar}/>}
Expand Down
15 changes: 13 additions & 2 deletions src/components/Letters.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import classNames from 'classnames';
import React, {Component} from 'react';

import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';

import * as selectionActions from '../actions/selection';

import LettersItem from './LettersItem';

@connect(
(state) => state,
(dispatch) => ({
selectionActions: bindActionCreators(selectionActions, dispatch),
})
)
export default class Letters extends Component {
handleToggleSelect(evt, model) {
// todo
evt.preventDefault();
this.props.selectionActions.toggle(model.id);
}

render() {
Expand All @@ -25,7 +36,7 @@ export default class Letters extends Component {
return <LettersItem
key={model.id}
model={model}
selected={false}
selected={selection[model.id]}
onToggleSelect={(evt) => this.handleToggleSelect(evt, model)}
/>
})}</div>
Expand Down
10 changes: 10 additions & 0 deletions src/components/PortalMenu.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';

import * as selectionActions from '../actions/selection';

import Button from './Button';
import Layout from './Layout';

@connect(
({selection}) => ({selectedCount: Object.keys(selection).length}),
(dispatch) => ({
selectionActions: bindActionCreators(selectionActions, dispatch),
})
)
export default class ProtalMenu extends Component {
render() {
const {selectedCount, selectionActions, threads} = this.props;
Expand Down
2 changes: 2 additions & 0 deletions src/constants/selection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const TOGGLE = 'TOGGLE_SELECTED';
export const SELECT_ALL = 'SELECT_ALL';
2 changes: 2 additions & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import {routerReducer as routing} from 'react-router-redux';
import auth from './auth';
import folders from './folders';
import threads from './threads';
import selection from './selection';

export default combineReducers({
routing,
auth,
folders,
threads,
selection,
});
29 changes: 29 additions & 0 deletions src/reducers/selection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {TOGGLE, SELECT_ALL} from '../constants/selection';

export default (state = {}, {type, id, threads}) => {
switch (type) {
case TOGGLE:
state = {...state};
if (state[id]) {
delete state[id];
} else {
state[id] = true;
}
return state;

case SELECT_ALL:
if (Object.keys(state).length > 0) {
state = {};
} else {
state = {};
for (const thread of threads) {
state[thread.id] = true;
}
}

return state;

default:
return state;
}
};

0 comments on commit 928ec5b

Please sign in to comment.