Skip to content

Commit

Permalink
abstracting is not always needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsierens committed Sep 23, 2016
1 parent 939b200 commit e5cd6d4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/components/CreateTodo.js
@@ -1,7 +1,7 @@
import React, { PropTypes } from 'react';
import * as rules from '../rules';

const handleSubmit = (nameInput, noteInput, onCreate) => {
const handleFormSubmit = (nameInput, noteInput, onCreate) => {
const name = nameInput.value;
const note = noteInput.value;

Expand Down Expand Up @@ -40,7 +40,7 @@ const CreateTodo = ({ onCreate }) => {
type="submit"
onClick={(e) => {
e.preventDefault();
handleSubmit(nameInput, noteInput, onCreate);
handleFormSubmit(nameInput, noteInput, onCreate);
}}>

SUBMIT
Expand Down
45 changes: 29 additions & 16 deletions app/components/TodoDetail.js
Expand Up @@ -4,6 +4,20 @@ import handleUpdateTodo from '../helpers/handleUpdateTodo';
import withExit from '../helpers/withExit';
import * as rules from '../rules';

const handleSave = (router, nameInput, noteInput, params) => {
const newName = nameInput.value;
const newNote = noteInput.value;

if (!newName || !newNote) return;

params.push({
name: newName,
note: newNote
});

withExit(handleUpdateTodo)(router, '/', params);
};

const TodoDetail = ({ todo, updateTodo, onRemove, router }) => {
const { name, note, _id, completed, updatedAt } = todo;
const time = new Date(updatedAt);
Expand All @@ -13,19 +27,21 @@ const TodoDetail = ({ todo, updateTodo, onRemove, router }) => {

return (
<div className={`todo todo-detail ${ completed ? 'done' : ''}`}>
<input
type="text"
value={name}
maxLength={`${rules.NAME_LENGTH}`}
ref={(ref) => { nameInput = ref; }}/>
<form>
<input
type="text"
defaultValue={name}
maxLength={`${rules.NAME_LENGTH}`}
ref={(ref) => { nameInput = ref; }}/>

<textarea
rows="10"
cols="50"
defaultValue={note}
maxLength={`${rules.NOTE_LENGTH}`}
ref={(ref) => { noteInput = ref; }}/>
</form>

<textarea
rows="10"
cols="50"
maxLength={`${rules.NOTE_LENGTH}`}
ref={(ref) => { noteInput = ref; }}>
{ note }
</textarea>
<div>
<button
className="btn-status"
Expand All @@ -41,10 +57,7 @@ const TodoDetail = ({ todo, updateTodo, onRemove, router }) => {
</div>
<button
className="btn-save"
onClick={(e) => withExit(handleUpdateTodo)(router, '/', [e, updateTodo, _id, {
name: nameInput.value,
note: noteInput.value
}])}>
onClick={(e) => handleSave(router, nameInput, noteInput, [e, updateTodo, _id])}>

SAVE
</button>
Expand Down

0 comments on commit e5cd6d4

Please sign in to comment.