-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Completed State Events Mini Project #15
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
cmhorsey
wants to merge
10
commits into
learn-co-curriculum:master
Choose a base branch
from
cmhorsey:test_branch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
845eafd
Display all tasks on task list
cmhorsey 019f266
Delete task on click
cmhorsey 654ac9b
Render all category buttons
cmhorsey 541a6a7
Correct button class handler
cmhorsey d6ff935
Complete button functionality
cmhorsey 802900c
Create controlled form
cmhorsey 6efef53
All functionality working
cmhorsey d2846a0
3 of 4 tests passing
cmhorsey 83d8e3e
All tests complete
cmhorsey befba8f
Refactor code
cmhorsey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,37 @@ | ||
import React from "react"; | ||
import React, { useState } from "react"; | ||
import CategoryFilter from "./CategoryFilter"; | ||
import NewTaskForm from "./NewTaskForm"; | ||
import TaskList from "./TaskList"; | ||
|
||
import { CATEGORIES, TASKS } from "../data"; | ||
console.log("Here's the data you're working with"); | ||
console.log({ CATEGORIES, TASKS }); | ||
|
||
function App() { | ||
const [allTasks, setAllTasks] = useState(TASKS) | ||
|
||
function onTaskFormSubmit(addTask) { | ||
const updatedTasks = [...allTasks, addTask] | ||
setAllTasks(updatedTasks) | ||
} | ||
|
||
return ( | ||
<div className="App"> | ||
<h2>My tasks</h2> | ||
<CategoryFilter /> | ||
<NewTaskForm /> | ||
<TaskList /> | ||
<CategoryFilter | ||
categories={CATEGORIES} | ||
TASKS={TASKS} | ||
allTasks={allTasks} | ||
setAllTasks={setAllTasks} | ||
/> | ||
<NewTaskForm | ||
categories={CATEGORIES} | ||
onTaskFormSubmit={onTaskFormSubmit} | ||
/> | ||
<TaskList | ||
tasks={allTasks} | ||
setAllTasks={setAllTasks} | ||
/> | ||
</div> | ||
); | ||
) | ||
} | ||
|
||
export default App; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,37 @@ | ||
import React from "react"; | ||
import React, { useState } from "react"; | ||
|
||
function CategoryFilter({ categories, TASKS, setAllTasks }) { | ||
const [selectedCategory, setSelectedCategory] = useState("All") | ||
|
||
const handleCategoryClick = (category) => { | ||
setSelectedCategory(category) | ||
if (category === "All") { | ||
setAllTasks(TASKS) | ||
} else { | ||
const filteredTasks = TASKS.filter((task) => task.category === category) | ||
setAllTasks(filteredTasks) | ||
} | ||
} | ||
|
||
const createButtons = categories.map((category) => { | ||
const isSelected = selectedCategory === category | ||
return ( | ||
<button | ||
onClick={() => handleCategoryClick(category)} | ||
className={isSelected ? "selected" : ""} | ||
key={category} | ||
> | ||
{category} | ||
</button> | ||
) | ||
}) | ||
|
||
function CategoryFilter() { | ||
return ( | ||
<div className="categories"> | ||
<h5>Category filters</h5> | ||
{/* render <button> elements for each category here */} | ||
{createButtons} | ||
</div> | ||
); | ||
) | ||
} | ||
|
||
export default CategoryFilter; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,56 @@ | ||
import React from "react"; | ||
import React, { useState } from "react"; | ||
|
||
function NewTaskForm({ categories, onTaskFormSubmit }) { | ||
const [newTask, setNewTask] = useState('') | ||
const [newTaskCat, setNewTaskCat] = useState('Code') | ||
|
||
function handleTaskChange(event) { | ||
setNewTask(event.target.value) | ||
} | ||
|
||
function handleCatChange(event) { | ||
setNewTaskCat(event.target.value) | ||
} | ||
|
||
const filteredOptions = categories.filter(category => category !== 'All') | ||
const createOptions = filteredOptions.map((category) => { | ||
return ( | ||
<option key={category}>{category}</option> | ||
) | ||
}) | ||
|
||
function handleSubmit(event) { | ||
event.preventDefault() | ||
|
||
const addTask = { | ||
text: newTask, | ||
category: newTaskCat | ||
} | ||
onTaskFormSubmit(addTask) | ||
setNewTask('') | ||
setNewTaskCat('Code') | ||
} | ||
|
||
function NewTaskForm() { | ||
return ( | ||
<form className="new-task-form"> | ||
<form onSubmit={handleSubmit} className="new-task-form"> | ||
<label> | ||
Details | ||
<input type="text" name="text" /> | ||
<input | ||
type="text" | ||
name="text" | ||
value={newTask} | ||
onChange={handleTaskChange} | ||
/> | ||
</label> | ||
<label> | ||
Category | ||
<select name="category"> | ||
{/* render <option> elements for each category here */} | ||
<select onChange={handleCatChange} name="category"> | ||
{createOptions} | ||
</select> | ||
</label> | ||
<input type="submit" value="Add task" /> | ||
</form> | ||
); | ||
) | ||
} | ||
|
||
export default NewTaskForm; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
import React from "react"; | ||
import Task from "./Task"; | ||
|
||
function TaskList({ tasks, setAllTasks }) { | ||
function handleDelete(taskToDelete) { | ||
const updatedTasks = tasks.filter(task => task.text !== taskToDelete.text) | ||
setAllTasks(updatedTasks) | ||
} | ||
|
||
const displayAllTasks = tasks.map((task, index) => { | ||
return <Task | ||
key={index} | ||
text={task.text} | ||
category={task.category} | ||
handleDelete={() => handleDelete(task)} | ||
/> | ||
}) | ||
|
||
function TaskList() { | ||
return ( | ||
<div className="tasks"> | ||
{/* display a list of tasks using Task component */} | ||
{displayAllTasks} | ||
</div> | ||
); | ||
) | ||
} | ||
|
||
export default TaskList; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meow