# HG changeset patch # User Alexandre Segura # Date 1498205809 -7200 # Node ID 772b73e31069d2154f4e74a387856a5e6f752afb # Parent 49c5ea36d0a4bb9c828be127e12fc5bd9f92aaef Introduce note editing, allow deleting note. diff -r 49c5ea36d0a4 -r 772b73e31069 client/src/App.scss --- a/client/src/App.scss Thu Jun 22 12:37:53 2017 +0200 +++ b/client/src/App.scss Fri Jun 23 10:16:49 2017 +0200 @@ -132,22 +132,28 @@ .note { display: flex; position: relative; - padding-left: 70px; + padding: 10px 10px 10px 80px; margin-bottom: 20px; - min-height: ($line-height-computed * 3); + cursor: pointer; + min-height: ($line-height-computed * 4); + border: 1px solid transparent; &:before { content: ""; position: absolute; top: 0; bottom: 0; - left: 27px; + left: 37px; z-index: -1; display: block; width: 2px; background-color: #e6ebf1; } + &:hover { + border: 1px solid #efefef; + } + .start, .finish { position: absolute; background-color: #fff; @@ -156,10 +162,12 @@ .start { top: 0; left: 0; + padding: 10px 0 0 10px; } .finish { bottom: 0; left: 0; + padding: 0 0 10px 10px; } &-content { diff -r 49c5ea36d0a4 -r 772b73e31069 client/src/actions/notesActions.js --- a/client/src/actions/notesActions.js Thu Jun 22 12:37:53 2017 +0200 +++ b/client/src/actions/notesActions.js Fri Jun 23 10:16:49 2017 +0200 @@ -43,3 +43,10 @@ } }; } + +export const deleteNote = (note) => { + return { + type: types.DELETE_NOTE, + note + }; +} diff -r 49c5ea36d0a4 -r 772b73e31069 client/src/components/Note.js --- a/client/src/components/Note.js Thu Jun 22 12:37:53 2017 +0200 +++ b/client/src/components/Note.js Fri Jun 23 10:16:49 2017 +0200 @@ -1,22 +1,80 @@ -import React from 'react'; +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; import PropTypes from 'prop-types'; -import {formatTimestamp} from '../utils'; +import { formatTimestamp } from '../utils'; +import SlateEditor from './SlateEditor'; +import * as notesActions from '../actions/notesActions'; + +class Note extends Component { + + state = { + edit: false + } + + toggleEditMode = () => { + const { edit } = this.state; + this.setState({ edit: !edit }) + } + + onClickDelete = (e) => { + e.preventDefault(); + e.stopPropagation(); + + this.props.notesActions.deleteNote(this.props.note); + } -const Note = ({note}) => { - return ( -
- {formatTimestamp(note.startedAt)} - {formatTimestamp(note.finishedAt)} -
-
- { note.marginComment } + renderNoteContent() { + if (this.state.edit) { + return ( +
+ +
+ ) + } + + return ( +
+ ) + } + + render() { + return ( +
+ { formatTimestamp(this.props.note.startedAt) } + { formatTimestamp(this.props.note.finishedAt) } + { this.renderNoteContent() } +
+ { this.props.note.marginComment } +
+ + delete +
-
- ); -}; + ); + }; +} Note.propTypes = { note: PropTypes.object.isRequired }; -export default Note; +function mapStateToProps(state, props) { + return props; +} + +function mapDispatchToProps(dispatch) { + return { + notesActions: bindActionCreators(notesActions, dispatch), + } +} + +export default connect(mapStateToProps, mapDispatchToProps)(Note); diff -r 49c5ea36d0a4 -r 772b73e31069 client/src/components/NoteInput.js --- a/client/src/components/NoteInput.js Thu Jun 22 12:37:53 2017 +0200 +++ b/client/src/components/NoteInput.js Fri Jun 23 10:16:49 2017 +0200 @@ -68,7 +68,8 @@ onButtonClick={this.onAddNoteClick} onCheckboxChange={this.onCheckboxChange} isChecked={this.props.autoSubmit} - isButtonDisabled={this.state.buttonDisabled} /> + isButtonDisabled={this.state.buttonDisabled} + withButtons={true} />
-
- -
- -
+ + {this.renderToolbarButtons()}
) } + renderToolbarButtons = () => { + if (!this.props.withButtons) { + return ( +
+ ) + } + + return ( +
+
+ +
+ +
+ ); + } + /** * Render a mark-toggling toolbar button. * diff -r 49c5ea36d0a4 -r 772b73e31069 client/src/constants/actionTypes.js --- a/client/src/constants/actionTypes.js Thu Jun 22 12:37:53 2017 +0200 +++ b/client/src/constants/actionTypes.js Fri Jun 23 10:16:49 2017 +0200 @@ -1,6 +1,7 @@ export const NOOP = 'NOOP'; export const ADD_NOTE = 'ADD_NOTE'; +export const DELETE_NOTE = 'DELETE_NOTE'; export const CREATE_SESSION = 'CREATE_SESSION'; export const UPDATE_SESSION = 'UPDATE_SESSION'; diff -r 49c5ea36d0a4 -r 772b73e31069 client/src/reducers/notesReducer.js --- a/client/src/reducers/notesReducer.js Thu Jun 22 12:37:53 2017 +0200 +++ b/client/src/reducers/notesReducer.js Fri Jun 23 10:16:49 2017 +0200 @@ -6,6 +6,9 @@ switch (action.type) { case types.ADD_NOTE: return state.push(new NoteRecord(action.note)); + case types.DELETE_NOTE: + const noteIndex = state.findIndex((note) => note.get('_id') === action.note.get('_id')); + return state.delete(noteIndex); default: return state; }