-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathShareCard.tsx
71 lines (66 loc) · 1.89 KB
/
ShareCard.tsx
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
70
71
import React from "react";
import logo from "@/public/icons/logo.svg";
import styles from "./shareCard.module.css";
import calcCreateTime from "../../utils/calcCreateTime";
import Image from "next/image";
interface ShareCardProps {
linkInfo: {
id: number;
created_at: string;
url: string;
title: string;
description: string;
image_source: string;
};
}
function ShareCard({ linkInfo }: ShareCardProps) {
const created_at = new Date(linkInfo?.created_at);
const formattedTime = calcCreateTime(created_at);
const year = created_at.getFullYear();
const month = created_at.getMonth() + 1;
const date = created_at.getDate();
return (
<div className={styles.card}>
<a
href={`${linkInfo.url}`}
className={styles.cardLink}
target="_blank"
rel="noreferrer"
>
<div
className={
linkInfo?.image_source
? styles.cardImgSection
: styles.cardImgSectionEmpty
}
>
{linkInfo?.image_source ? (
<Image
src={linkInfo?.image_source}
className={styles.linkImg}
alt="cat"
fill
/>
) : (
<Image
src={logo}
className={`${styles.cardEmpty} ${styles.linkImg} ${styles.linkImgEmpty}`}
alt="cat"
width={50}
height={50}
/>
)}
</div>
<div className={styles.cardTextSection}>
<p className={styles.timeStamp}>{formattedTime}</p>
<p className={styles.introduceText}>
{linkInfo?.description ??
"Lorem ipsum dolor sit amet consectetur. Metus amet habitant nunc consequat. Tldkd"}
</p>
<p className={styles.createdDate}>{`${year}. ${month}. ${date}`}</p>
</div>
</a>
</div>
);
}
export default ShareCard;