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

Raul h #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
context created and images fetched
  • Loading branch information
PuffCab authored and PuffCab committed Oct 31, 2021
commit 69b50fc2b2ac16d7ce9acf0f68b805148404f744
892 changes: 892 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -3,11 +3,15 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.2",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"axios": "^0.24.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.3.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.2"
},
4 changes: 3 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Album from "./components/Album";

function App() {
return (
<div className="App">
<h1>react project cleaned</h1>
<Album />
</div>
);
}
28 changes: 28 additions & 0 deletions src/components/Album.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { useContext, useEffect, useState } from "react";
import { AlbumContext } from "../context/AlbumContext";
import AlbumImage from "./AlbumImage";

// import "./album.css";

function Album() {
const { albums, getData } = useContext(AlbumContext);

// const [images, setimages] = useState([]);
// setimages(albums.url);

console.log(albums);
useEffect(() => {
getData();
}, []);

return (
<div className="gridContainer">
{albums &&
albums.map((item, index) => {
return <AlbumImage key={index} image={item} />;
})}
</div>
);
}

export default Album;
12 changes: 12 additions & 0 deletions src/components/AlbumImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";

const AlbumImage = ({ image }) => {
return (
<>
{console.log("imgae en AlbumImage", image.url)}
<img src={image.url} alt="" />
</>
);
};

export default AlbumImage;
3 changes: 3 additions & 0 deletions src/components/album/album.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* .gridContainer {
background-color: red;
} */
28 changes: 28 additions & 0 deletions src/context/AlbumContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { createContext, useState } from "react";

export const AlbumContext = createContext();

export const AlbumContextProvider = ({ children }) => {
const [albums, setAlbums] = useState();

const getData = async () => {
try {
const response = await fetch(
"https://jsonplaceholder.typicode.com/albums/1/photos"
);
const obj = await response.json();
console.log(obj);
setAlbums(obj);
} catch (error) {
// console.log(error.response.data.error);
console.log(error);
}
};
console.log(`Albums >>>`, albums);

return (
<AlbumContext.Provider value={{ albums, getData }}>
{children}
</AlbumContext.Provider>
);
};
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -2,10 +2,16 @@ import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import { BrowserRouter as Router } from "react-router-dom";
import { AlbumContextProvider } from "./context/AlbumContext";

ReactDOM.render(
<React.StrictMode>
<App />
<Router>
<AlbumContextProvider>
<App />
</AlbumContextProvider>
</Router>
</React.StrictMode>,
document.getElementById("root")
);