-
Notifications
You must be signed in to change notification settings - Fork 0
/
ItemCard.js
69 lines (65 loc) · 1.65 KB
/
ItemCard.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, { useRef } from 'react';
import { Media, Button } from 'react-bootstrap';
import moment from 'moment';
import './ItemCard.css';
import useObserver from '../custom-hooks/observer';
import Image from './Image';
const ItemCard = ({
id,
type,
created_at,
company,
location,
title,
company_logo,
index,
onItemClick,
}) => {
const imageRef = useRef(); // a ref which we can assign to the image
const [isVisible] = useObserver(imageRef);
return (
<Media
style={{
marginBottom: '10px',
border: '1px solid lightgrey',
}}
index={index + 1}
className='ItemCard__Media'
>
<div className='Company__Logo' ref={imageRef}>
{isVisible && (
<Image
className='mr-3'
src={company_logo}
alt={company}
height='150'
width='150'
draggable='false'
/>
)}
</div>
<Media.Body>
<div className='ItemCard__Media--Body'>
<div className='company__details'>
<h4>{title}</h4>
<h6>
{company} - {type}
</h6>
</div>
<div className='company__info'>
<span className='company__info--location'>{location}</span>
<span className='company__info--posted'>
Posted {moment(new Date(created_at)).fromNow()}
</span>
</div>
</div>
<div className='ItemCard__Button'>
<Button variant='primary' onClick={() => onItemClick(id)}>
View Details
</Button>
</div>
</Media.Body>
</Media>
);
};
export default ItemCard;