-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDev.js
69 lines (59 loc) · 2.31 KB
/
Dev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React, { useEffect, useState } from 'react';
import Header from './Header';
import devIcon from '../assets/images/dev.webp';
import Fade from 'react-reveal/Fade';
import { ThreeDots } from 'svg-loaders-react'
const Dev = () => {
const [devPosts, setDevPosts] = useState([]);
const [loading, setLoading] = useState(true)
const getDevFeed = async () => {
const response = await fetch('https://dev.to/api/articles', {
headers: {
'Content-type': 'application/json',
},
})
const apiResponse = await response.json();
// console.log(apiResponse);
setLoading(false);
setDevPosts(apiResponse);
}
useEffect(() => {
getDevFeed();
}, [])
return (
<div>
<Header
icon={devIcon}
title='Dev'
borderColor='border-gray-500'
/>
{
(loading === true) ?
<div className="flex justify-center my-48">
< ThreeDots fill="#6366F1" />
</div>
:
<div className="flex w-50 flex-row flex-wrap justify-center p-2">
{devPosts.map(post => {
return (
<Fade bottom key={post.id}>
<a href={post.url}
target="_blank" rel="noreferrer"
>
<div className="w-80 h-72 py-auto shadow flex flex-col bg-white rounded-md p-4 text-left m-2">
<img src={post.social_image === '' ? 'https://picsum.photos/seed/picsum/200/150' : post.social_image}
alt="cover-img" className="rounded" />
<h3 className="text-xl mt-2">
{post.title}
</h3>
</div>
</a>
</Fade>
)
})}
</div>
}
</div>
);
}
export default Dev;