Skip to content
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

Practice/005002 answer #1

Open
wants to merge 3 commits into
base: practice/005002_base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion app/components/TodoItem/TodoItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';

import Icon from 'react-native-vector-icons/FontAwesome';

const TodoItem = ({ todo, onPressComplete }) => {
const TodoItem = ({ todo, onPressComplete, onPressRemove }) => {
const isCompleted = todo.completed === true;
const isIncomplete = todo.completed === false;
return (
Expand Down Expand Up @@ -32,6 +32,12 @@ const TodoItem = ({ todo, onPressComplete }) => {
)}
{isCompleted && (
<View style={styles.btnGroup}>
<TouchableOpacity
onPress={() => onPressRemove(todo)}
style={styles.btnContainer}
>
<Icon size={15} name={'remove'} color={'#fff'} />
</TouchableOpacity>
</View>
)}
</TouchableOpacity>
Expand Down
13 changes: 13 additions & 0 deletions app/views/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ class App extends Component {

handleRemove = async todo => {
console.log("handleRemove", todo);
const todos = this.state.todos;

let id = todo.id;

let response = await fetch(`http://192.168.60.1:3000/api/task/${id}`, {
method: 'delete'
});
let result = await response.json();

const updatedTodos = todos.filter(t => t.id !== todo.id);

this.setState({ todos: updatedTodos });
};

handleOnAddNewTodo = async () => {
Expand Down Expand Up @@ -153,6 +165,7 @@ class App extends Component {
<TodoList
data={todos}
onPressComplete={this.handleComplete}
onPressRemove={this.handleRemove}
/>
<Footer />
</View>
Expand Down