Created
November 24, 2017 19:50
-
-
Save nomanHasan/6117b53f38d022c04c5610bf4ea5de32 to your computer and use it in GitHub Desktop.
TodoTable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react'; | |
import {Button, Icon, Label, Menu, Table} from 'semantic-ui-react' | |
import TodoRow from './todoRow' | |
import EditTodo from './editTodo' | |
// TodoTable is a Stateless component | |
const TodoTable = (props) => { | |
return ( | |
<Table celled> | |
<Table.Header> | |
<Table.Row> | |
<Table.HeaderCell>Title</Table.HeaderCell> | |
<Table.HeaderCell>Description</Table.HeaderCell> | |
<Table.HeaderCell>Date</Table.HeaderCell> | |
<Table.HeaderCell>Options</Table.HeaderCell> | |
</Table.Row> | |
</Table.Header> | |
<Table.Body> | |
{/* This maps the todos recieved as a prop */} | |
{props | |
.todos | |
.map(t => { | |
// If the todo is being edited, EditTodo Component is rendered here | |
if (t.editing) { | |
return <EditTodo | |
editTodo={props.editTodo} | |
cancelEditing={e => props.cancelEditing(t._id)} | |
key={t._id} | |
todo={t}/> | |
} else { | |
// Is the todo is not being edited the TodoRow stateless component is returned | |
return <TodoRow | |
todo={t} | |
key={t._id} | |
completeTodo={e => props.completeTodo(t)} | |
startEditing={e => props.startEditing(t._id)} | |
deleteTodo={e=> props.deleteTodo(t)} | |
/> | |
} | |
})} | |
{/* This EditTodo component is used as a Create new Todo Component */} | |
{/* Thus by using the same component for both use, we can reuse a lot of the codes */} | |
<EditTodo createTodo={props.createTodo} /> | |
</Table.Body> | |
</Table> | |
) | |
} | |
export default TodoTable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment