Skip to content

Commit b2923cf

Browse files
Tailwind-React-PixabayAPI
1 parent 6c352bc commit b2923cf

File tree

17 files changed

+70995
-242
lines changed

17 files changed

+70995
-242
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
REACT_APP_PIXABAYAPI_KEY=16675527-de3deee79ae2af51c97e941bd

package-lock.json

Lines changed: 853 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
"@testing-library/user-event": "^7.2.1",
99
"react": "^16.13.1",
1010
"react-dom": "^16.13.1",
11+
"react-loading-skeleton": "^2.0.1",
1112
"react-scripts": "3.4.1"
1213
},
1314
"scripts": {
14-
"start": "react-scripts start",
15-
"build": "react-scripts build",
15+
"start": "npm run watch:css && react-scripts start",
16+
"build": "npm run build:css && react-scripts build",
1617
"test": "react-scripts test",
17-
"eject": "react-scripts eject"
18+
"eject": "react-scripts eject",
19+
"build:css": "postcss src/assets/tailwind.css -o src/assets/main.css",
20+
"watch:css": "postcss src/assets/tailwind.css -o src/assets/main.css"
1821
},
1922
"eslintConfig": {
2023
"extends": "react-app"
@@ -30,5 +33,10 @@
3033
"last 1 firefox version",
3134
"last 1 safari version"
3235
]
36+
},
37+
"devDependencies": {
38+
"autoprefixer": "^9.8.0",
39+
"postcss-cli": "^7.1.1",
40+
"tailwindcss": "^1.4.6"
3341
}
3442
}

postcss.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const tailwindcss = require('tailwindcss');
2+
3+
module.exports = {
4+
plugins: [
5+
tailwindcss('./tailwind.js'),
6+
require('autoprefixer')
7+
]
8+
}

src/App.css

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/App.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
import React from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
4-
1+
import React, { useState, useEffect } from 'react';
2+
import ImageCard from './components/ImageCard';
3+
import Skeleton from 'react-loading-skeleton';
4+
import ImageSearch from './components/ImageSearch';
55
function App() {
6+
const [images, setImages] = useState([]);
7+
const [isLoading, setisLoading] = useState(true);
8+
const [term, setTerm] = useState('');
9+
10+
useEffect(() => {
11+
fetch(`https://pixabay.com/api/?key=${process.env.REACT_APP_PIXABAYAPI_KEY}&q=${term}&image_type=photo&pretty=true`)
12+
.then(response => response.json())
13+
.then(data => {
14+
setImages(data.hits);
15+
setisLoading(false);
16+
})
17+
.catch(error => console.log(error))
18+
}, [term]);
19+
620
return (
7-
<div className="App">
8-
<header className="App-header">
9-
<img src={logo} className="App-logo" alt="logo" />
10-
<p>
11-
Edit <code>src/App.js</code> and save to reload.
12-
</p>
13-
<a
14-
className="App-link"
15-
href="https://reactjs.org"
16-
target="_blank"
17-
rel="noopener noreferrer"
18-
>
19-
Learn React
20-
</a>
21-
</header>
21+
<div className="container mx-auto">
22+
<ImageSearch textSearch={(text) => setTerm(text)} />
23+
{!isLoading && images.length === 0 && <h1 className="text-center text-6xl mx-auto mt-32">No Images Found</h1>}
24+
{isLoading ? <Skeleton color="#202020" highlightColor="#444" count={5} />
25+
: <div className="grid grid-cols-3 gap-4">
26+
{images.map(image => (
27+
<ImageCard key={image.id} image={image} />
28+
))}
29+
</div>}
2230
</div>
2331
);
2432
}

src/App.test.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)