Skip to content

feat/imporve-code-structure #1

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 1 commit into
base: master
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
45 changes: 22 additions & 23 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ import {
TextInput,
View,
Button,
ScrollView
ScrollView,
} from "react-native";
import AppBar from "./src/components/AppBar";
import Todo from "./src/components/Todo";
import TodoList from "./src/components/TodoList";
import AddTodo from "./src/components/AddTodo";
import TodoItem from "./src/components/TodoItem";

export default function App() {
const [title, setTitle] = useState("");

// iniitalize empty object todo
const [todo, setTodo] = useState({});

// Initalize empty array to store todos
const [todos, setTodos] = useState([]);

Expand All @@ -31,11 +28,11 @@ export default function App() {
};

// function to mark todo as checked or unchecked
const checkTodo = id => {
const checkTodo = (id) => {
// loop through todo list and look for the the todo that matches the given id param
// update the state using setTodos function
setTodos(
todos.map(todo => {
todos.map((todo) => {
if (todo.key === id) {
todo.isChecked = !todo.isChecked;
}
Expand All @@ -45,12 +42,14 @@ export default function App() {
};

// function to delete todo from the todo list
const deleteTodo = id => {
const deleteTodo = (id) => {
// loop through todo list and return todos that don't match the id
// update the state using setTodos function
setTodos(todos.filter(todo => {
return todo.key !== id;
}));
setTodos(
todos.filter((todo) => {
return todo.key !== id;
})
);
};

useEffect(() => {
Expand All @@ -63,18 +62,18 @@ export default function App() {
<View style={styles.statusBar}></View>
<AppBar />
<View style={styles.todo}>
<TextInput
<AddTodo
placeholder="Add a todo"
value={title}
onChangeText={value => setTitle(value)}
title={title}
setTitle={setTitle}
style={styles.textbox}
addTodo={addTodo}
/>
<Button title="Add" color="#7F39FB" onPress={() => addTodo()} />
</View>

<ScrollView>
{todos.map(todo => (
<TodoList
{todos.map((todo) => (
<TodoItem
key={todo.key}
todo={todo}
checkTodo={checkTodo}
Expand All @@ -91,26 +90,26 @@ const styles = StyleSheet.create({
backgroundColor: "#7F39FB",
color: "#fff",
width: "100%",
height: 30
height: 30,
},
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "flex-start"
justifyContent: "flex-start",
},
todo: {
flexDirection: "row",
width: "100%",
justifyContent: "center",
alignItems: "center"
alignItems: "center",
},
textbox: {
borderWidth: 1,
borderColor: "#7F39FB",
borderRadius: 8,
padding: 10,
margin: 10,
width: "80%"
}
width: "80%",
},
});
Loading