Skip to content

Commit

Permalink
end of lesson 2
Browse files Browse the repository at this point in the history
  • Loading branch information
DakotaLMartinez committed Aug 30, 2022
1 parent e254422 commit bc1b411
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
10 changes: 8 additions & 2 deletions 02_state_and_events /project_showcase/src/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import React from "react";
import React, { useState } from "react";

const Header = () => {
const [isDarkMode, setIsDarkMode] = useState(true);

const handleToggleDarkMode = (e) => {
setIsDarkMode(isDarkMode => !isDarkMode)
}

return (
<header>
<h1>
<span className="logo">{"//"}</span>
Project Showcase
</h1>
<nav>
<button>Light Mode</button>
<button onClick={handleToggleDarkMode}>{isDarkMode ? "Light Mode" : "Dark Mode"}</button>
</nav>
</header>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import { useState } from "react";
import ProjectListItem from "./ProjectListItem";

import projects from "../projects";

const ProjectList = () => {
const [searchQuery, setSearchQuery] = useState("");

const projectListItems = projects.map(project => {
const handleSearch = (e) => {
console.log(e.target.value);
setSearchQuery(e.target.value);
}

const searchResults = projects.filter(project => {
// return true if the project should be included and false if not
return project.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
project.about.toLowerCase().includes(searchQuery.toLowerCase())
})

// console.log(searchResults)

const projectListItems = searchResults.map(project => {
return <ProjectListItem key={project.id} project={project} />
})


// console.log('render');
return (
<section>
<h2>Projects</h2>
Expand All @@ -21,7 +37,7 @@ const ProjectList = () => {
<button>Phase 2</button>
<button>Phase 1</button>
</div>
<input type="text" placeholder="Search..."/>
<input type="text" placeholder="Search..." onChange={handleSearch} />

<ul className="cards">{projectListItems}</ul>
</section>
Expand Down

0 comments on commit bc1b411

Please sign in to comment.