Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #178 from TailorDev/checkboxes
Browse files Browse the repository at this point in the history
[WIP] Support checkboxes/task lists
  • Loading branch information
willdurand committed Aug 18, 2016
2 parents 8f0fdea + b97cf84 commit c77c15e
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 25 deletions.
29 changes: 10 additions & 19 deletions app/components/Editor/__tests__/Editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('<Editor />', () => {
onUpdateContent={() => {}}
template={''}
forceUpdate={false}
onClickCheckbox={() => {}}
/>
);
expect(wrapper.find(Markdown)).to.have.length(1);
Expand All @@ -35,30 +36,12 @@ describe('<Editor />', () => {
onUpdateContent={() => {}}
template={''}
forceUpdate={false}
onClickCheckbox={() => {}}
/>
);
expect(wrapper.find(Preview)).to.have.length(1);
});

it('calls onUpdateContent() when text is entered in Markdown component', () => {
const spy = sinon.spy();

const wrapper = shallow(
<Editor
loaded
content={''}
onUpdateContent={spy}
template={''}
forceUpdate={false}
/>
);
const content = 'Hello, World';

wrapper.find('Markdown').simulate('change', content);

expect(spy.calledOnce).to.be.true;
});

it('renders a Loader component', () => {
const wrapper = shallow(
<Editor
Expand All @@ -67,6 +50,7 @@ describe('<Editor />', () => {
onUpdateContent={() => {}}
template={''}
forceUpdate={false}
onClickCheckbox={() => {}}
/>
);

Expand All @@ -81,6 +65,7 @@ describe('<Editor />', () => {
onUpdateContent={() => {}}
template={''}
forceUpdate={false}
onClickCheckbox={() => {}}
/>
);

Expand All @@ -95,6 +80,7 @@ describe('<Editor />', () => {
onUpdateContent={() => {}}
template={''}
forceUpdate={false}
onClickCheckbox={() => {}}
/>
);

Expand All @@ -110,6 +96,7 @@ describe('<Editor />', () => {
onUpdateContent={spy}
template={''}
forceUpdate={false}
onClickCheckbox={() => {}}
/>
);

Expand All @@ -126,6 +113,7 @@ describe('<Editor />', () => {
onUpdateContent={() => {}}
template={''}
forceUpdate={false}
onClickCheckbox={() => {}}
/>
);
const verticalHandlerWrapper = wrapper.find('VerticalHandler').shallow();
Expand All @@ -146,6 +134,7 @@ describe('<Editor />', () => {
onUpdateContent={() => {}}
template={''}
forceUpdate={false}
onClickCheckbox={() => {}}
/>
);
const verticalHandlerWrapper = wrapper.find('VerticalHandler').shallow();
Expand All @@ -172,6 +161,7 @@ describe('<Editor />', () => {
onUpdateContent={() => {}}
template={''}
forceUpdate={false}
onClickCheckbox={() => {}}
/>
);
const verticalHandlerWrapper = wrapper.find('VerticalHandler').shallow();
Expand All @@ -192,6 +182,7 @@ describe('<Editor />', () => {
onUpdateContent={() => {}}
template={''}
forceUpdate={false}
onClickCheckbox={() => {}}
/>
);
const verticalHandlerWrapper = wrapper.find('VerticalHandler').shallow();
Expand Down
12 changes: 11 additions & 1 deletion app/components/Editor/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { connect } from 'react-redux';
import Editor from './presenter';
import { updateContent } from '../../modules/documents';
import {
updateContent,
toggleTaskListItem,
} from '../../modules/documents';


const mapStateToProps = (state) => {
Expand All @@ -18,6 +21,13 @@ const mapDispatchToProps = (dispatch) => ({
onUpdateContent: (content) => {
dispatch(updateContent(content));
},
onClickCheckbox: (index) => {
const idx = parseInt(index, 10);

if (!isNaN(idx)) {
dispatch(toggleTaskListItem(idx));
}
},
});

export default connect(mapStateToProps, mapDispatchToProps)(Editor);
2 changes: 2 additions & 0 deletions app/components/Editor/presenter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default class Editor extends Component {
content={this.props.content}
position={this.state.position}
template={this.props.template}
onClickCheckbox={this.props.onClickCheckbox}
/>
</Loader>
);
Expand All @@ -86,5 +87,6 @@ Editor.propTypes = {
content: PropTypes.string.isRequired,
template: PropTypes.string.isRequired,
onUpdateContent: PropTypes.func.isRequired,
onClickCheckbox: PropTypes.func.isRequired,
forceUpdate: PropTypes.bool.isRequired,
};
Loading

0 comments on commit c77c15e

Please sign in to comment.