Skip to content

Commit 4390fb8

Browse files
committed
pushing part 1 of charle's code
1 parent a61ea46 commit 4390fb8

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

src/App.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,44 @@
1-
import React from "react";
1+
import React, { useState, useEffect } from "react";
22
import "./App.css";
33
import "bootstrap/dist/css/bootstrap.min.css";
44
import { Container } from "react-bootstrap";
5+
import IssueList from "./components/IssueList";
6+
import SearchForm from "./components/SearchForm";
57

68
function App() {
9+
const [issues, setIssues] = useState([]);
10+
const [searchTerm, setSearchTerm] = useState("");
11+
const [url, setUrl] = useState(
12+
"https://api.github.com/repos/octocat/hello-world/issues"
13+
);
14+
useEffect(() => {
15+
async function fetchData() {
16+
let data = await fetch(url);
17+
let json = await data.json();
18+
setIssues(json);
19+
}
20+
fetchData();
21+
}, [url]);
22+
23+
const handleClick = () => {
24+
setUrl(`https://api.github.com/repos/${searchTerm}/issues`);
25+
};
26+
27+
const handleChange = (e) => {
28+
setSearchTerm(e.target.value);
29+
};
30+
731
return (
832
<Container>
933
<h1 className="text-center">GitHub Issues Browser</h1>
10-
<p>Fill in files from /src/components.</p>
34+
<SearchForm
35+
handleChange={handleChange}
36+
handleClick={handleClick}
37+
searchTerm={searchTerm}
38+
/>
39+
<IssueList issues={issues} />
1140
</Container>
1241
);
1342
}
1443

15-
export default App;
44+
export default App;

src/components/IssueList.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from "react";
2+
3+
const IssueList = ({ issues }) => {
4+
return (
5+
<div>
6+
<h2>Issue list</h2>
7+
<ul>
8+
{issues.map((i) => (
9+
<li key={i.id}>{i.title}</li>
10+
))}
11+
</ul>
12+
</div>
13+
);
14+
};
15+
16+
export default IssueList;

src/components/SearchForm.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from "react";
2+
3+
const SearchForm = ({ handleChange, searchTerm, handleClick }) => {
4+
return (
5+
<div>
6+
<input type="text" onChange={handleChange} value={searchTerm} />
7+
<button onClick={handleClick}>Search</button>
8+
</div>
9+
);
10+
};
11+
12+
export default SearchForm;

0 commit comments

Comments
 (0)