Skip to content

New component #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
migrated new todo to separate component
  • Loading branch information
annapanana committed Mar 22, 2017
commit 565d67d64d855abaa093786c40513ac73e5c36b4
Binary file removed 3-flux/documentation/Untitled.pdf
Binary file not shown.
Binary file added 3-flux/documentation/data-flow.graffle
Binary file not shown.
Binary file modified 3-flux/documentation/data-flow.pdf
Binary file not shown.
15 changes: 11 additions & 4 deletions 3-flux/src/assets/icon_done.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions 3-flux/src/assets/icon_not_done.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions 3-flux/src/js/actions/TodoActions.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import dispatcher from "../dispatcher";

export function createTodo(text) {
export function deleteTodo(id) {
dispatcher.dispatch({
type: "CREATE_TODO",
text,
type: "DELETE_TODO",
id,
});
}

export function deleteTodo(id) {
export function createTodo(text) {
dispatcher.dispatch({
type: "DELETE_TODO",
id,
type: "CREATE_TODO",
text,
});
}

Expand Down
41 changes: 40 additions & 1 deletion 3-flux/src/js/components/NewTodo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,51 @@ import * as TodoActions from "../actions/TodoActions";
export default class NewTodo extends React.Component {
constructor(props) {
super();
this.state = {
newTodo: ""
};
}

addTodo(e) {
e.preventDefault();
TodoActions.createTodo(this.state.newTodo);
this.setState({newTodo: ""});
}

handleChange(e) {
this.setState({newTodo: e.target.value});
}

render() {
const inputStyling = {
borderRadius: "10px",
borderStyle: "solid",
borderWidth: "1px",
borderColor: "#B19FBA",
marginRight: "20px",
minWidth: "200px",
backgroundColor: "#D8CFDD",
padding: "3px 15px 3px 15px"
};

return (
const formStyling = {
paddingBottom: "10px"
};

const standardButton = {
borderRadius: "10px",
borderStyle: "none",
padding: "3px 15px 3px 15px",
fontFamily: "Roboto",
backgroundColor: "#765786",
color: "#FFF"
};

return (
<form style={formStyling}>
<input style={inputStyling} type="text" value={this.state.newTodo} onChange={this.handleChange.bind(this)}/>
<button style={standardButton} onClick={this.addTodo.bind(this)}>Add New</button>
</form>
);
}
}
15 changes: 9 additions & 6 deletions 3-flux/src/js/components/Todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ export default class Todo extends React.Component {
super();
}

// Anna Code Start
removeTodo(e) {
deleteTodo(e) {
TodoActions.deleteTodo(this.props.id);
}
// Anna Code End
// const icon = complete ? "\u2714" : "\u2716"

render() {
const { complete, edit, text } = this.props;

Expand All @@ -23,6 +21,11 @@ export default class Todo extends React.Component {
padding: "5px"
};

const checkboxStyle = {
maxWidth: "50px",
padding: "10px"
}

if (edit) {
return (
<li>
Expand All @@ -33,8 +36,8 @@ export default class Todo extends React.Component {

return (
<li>
<span><img style={iconStyle} src={icon} /></span>
<span onClick={this.removeTodo.bind(this)}><img style={iconStyle} src={trash} /></span>
<span><img style={checkboxStyle} src={icon} /></span>
<span onClick={this.deleteTodo.bind(this)}><img style={iconStyle} src={trash} /></span>
<span>{text}</span>
</li>
);
Expand Down
47 changes: 3 additions & 44 deletions 3-flux/src/js/pages/Todos.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import Todo from "../components/Todo";
import NewTodo from "../components/Todo";
import NewTodo from "../components/NewTodo";
import * as TodoActions from "../actions/TodoActions";
import TodoStore from "../stores/TodoStore";

Expand All @@ -10,8 +10,7 @@ export default class Todos extends React.Component {
super();
this.getTodos = this.getTodos.bind(this);
this.state = {
todos: TodoStore.getAll(),
newTodo: ""
todos: TodoStore.getAll()
};
}

Expand All @@ -33,19 +32,6 @@ export default class Todos extends React.Component {
TodoActions.reloadTodos();
}

// Start Anna Code
addTodo(e) {
console.log("??");
e.preventDefault();
TodoActions.createTodo(this.state.newTodo);
this.setState({newTodo: ""});
}

handleChange(e) {
this.setState({newTodo: e.target.value});
}
// End Anna Code

render() {
const { todos } = this.state;

Expand All @@ -64,37 +50,10 @@ export default class Todos extends React.Component {
marginBottom: "20px"
};

const inputStyling = {
borderRadius: "10px",
borderStyle: "solid",
borderWidth: "1px",
borderColor: "#B19FBA",
marginRight: "20px",
minWidth: "200px",
backgroundColor: "#D8CFDD",
padding: "3px 15px 3px 15px"
}

const formStyling = {
paddingBottom: "10px"
}

const standardButton = {
borderRadius: "10px",
borderStyle: "none",
padding: "3px 15px 3px 15px",
fontFamily: "Roboto",
backgroundColor: "#765786",
color: "#FFF"
}

return (
<div>
<h1 style={headerStyling}>A List of things To Do</h1>
<form style={formStyling}>
<input style={inputStyling} type="text" value={this.state.newTodo} onChange={this.handleChange.bind(this)}/>
<button style={standardButton} onClick={this.addTodo.bind(this)}>Add New</button>
</form>
<NewTodo />
<ul style={customUl}>{TodoComponents}</ul>
</div>
);
Expand Down