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

Update App.jsx #7

Open
wants to merge 7 commits into
base: main
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
108 changes: 68 additions & 40 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,77 @@
import "./App.css";
import Head from "./Components/Header/Header";
import SearchForm from "./Components/SearchForm/SearchForm";
import Card from "./Components/Card/Card";
import { useState, useEffect } from "react";

function App() {
return (
<>
<header>
<div className="content-wrapper">
<h1>Welcome to the JSHeroes Bootcamp!</h1>
</div>
<img className="bear" src="/js-heroes-bear.png" />
</header>
const cards = [
{
title: "facebook/react",
description: "placeholder description",
stars: 500,
forks: 100,
},

<main>
<form className="search-form">
<input className="input" />
<button className="button">Search</button>
</form>
{
title: "vuejs/vue",
description: "placeholder description",
stars: 500,
forks: 100,
},

<ul className="repo-cards">
<li className="repo-card">
<span className="title">facebook/react</span>
<span className="description">placeholder description</span>
<section className="footer">
<div>Stars: 500</div>
<div>Forks: 100</div>
</section>
</li>
{
title: "sveltejs/svelte",
description: "test description",
stars: 500,
forks: 100,
},
];

<li className="repo-card">
<span className="title">vuejs/vue</span>
<span className="description">placeholder description</span>
<section className="footer">
<div>Stars: 500</div>
<div>Forks: 100</div>
</section>
</li>
function App() {
const [filteredCards, setFilteredCards] = useState(cards);

<li className="repo-card">
<span className="title">sveltejs/svelte</span>
<span className="description">placeholder description</span>
<section className="footer">
<div>Stars: 500</div>
<div>Forks: 100</div>
</section>
</li>
</ul>
const cardsJSX = filteredCards.map((card) => (
<Card
title={card.name}
description={card.description}
stars={card.score}
forks={card.forks}
/>
));
console.log("rerender", filteredCards);
useEffect(() => {
// cand apare componenta prima data
// console.log("prima data");
fetch("https://api.github.com/search/repositories?q=stars:>10000")
.then((response) => response.json())
.then((data) => {
console.log(data);
setFilteredCards(data.items);
});
}, []);
// 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
return (
<>
<Head />
<main>
<SearchForm
onSearch={(value) => {
console.log(value);
fetch(`https://api.github.com/search/repositories?q=${value}`, {
headers: {
Authorization:
"Bearer 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",
},
})
.then((response) => response.json())
.then((data) => {
console.log(data);
setFilteredCards(data.items);
});
}}
/>
{/* {render} */}
<ul className="repo-cards">{cardsJSX}</ul>
</main>
</>
);
Expand Down
19 changes: 19 additions & 0 deletions src/Components/Card/Card.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";

function Cards(props) {
console.log(props);
return (
<ul className="repo-cards">
<li className="repo-card">
<span className="title">{props.title}</span>
<span className="description">{props.description}</span>
<section className="footer">
<div>Stars: {props.stars}</div>
<div>Forks: {props.forks}</div>
</section>
</li>
</ul>
);
}

export default Cards;
14 changes: 14 additions & 0 deletions src/Components/Header/Header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";

function Head() {
return (
<header>
<div className="content-wrapper">
<h1>Hello!</h1>
</div>
<img className="bear" src="/js-heroes-bear.png" />
</header>
);
}

export default Head;
20 changes: 20 additions & 0 deletions src/Components/SearchForm/SearchForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { useRef } from "react";

function SearchForm(props) {
const textInput = useRef(null);
function buttonClicked(e) {
e.preventDefault();
props.onSearch(textInput.current.value);
}

return (
<form className="search-form">
<input className="input" ref={textInput} />
<button onClick={buttonClicked} className="button">
Search
</button>
</form>
);
}

export default SearchForm;