-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdjacentWidget.jsx
37 lines (32 loc) · 1.22 KB
/
AdjacentWidget.jsx
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
import React, { useState, useEffect } from 'react';
import AdjacentPostCard from './AdjacentPostCard';
import { getAdjacentPosts } from '../services';
const AdjacentPosts = ({ createdAt, slug }) => {
const [adjacentPost, setAdjacentPost] = useState(null);
const [dataLoaded, setDataLoaded] = useState(false);
useEffect(() => {
getAdjacentPosts(createdAt, slug).then((result) => {
setAdjacentPost(result);
setDataLoaded(true);
});
}, [slug]);
return (
<div className="grid grid-cols-1 lg:grid-cols-8 gap-12 mb-8">
{dataLoaded && (
<>
{adjacentPost.previous && (
<div className={`${adjacentPost.next ? 'col-span-1 lg:col-span-4' : 'col-span-1 lg:col-span-8'} adjacent-post rounded-lg relative h-72`}>
<AdjacentPostCard post={adjacentPost.previous} position="LEFT" />
</div>
)}
{adjacentPost.next && (
<div className={`${adjacentPost.previous ? 'col-span-1 lg:col-span-4' : 'col-span-1 lg:col-span-8'} adjacent-post rounded-lg relative h-72`}>
<AdjacentPostCard post={adjacentPost.next} position="RIGHT" />
</div>
)}
</>
)}
</div>
);
};
export default AdjacentPosts;