This repository was archived by the owner on Mar 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.tsx
More file actions
89 lines (86 loc) · 2.16 KB
/
Event.tsx
File metadata and controls
89 lines (86 loc) · 2.16 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Style
import styles from '../styles/components/Event.module.scss';
// Components
import Link from 'next/link';
// Internal Components
import Image from './Image';
import { SlCalender, SlLocationPin } from 'react-icons/sl';
import { formatDate, DateFormat } from '../utils';
import { type EventItem } from '../config';
interface Props {
eventItem: EventItem;
}
export const isFuture = (eventItem: EventItem) => {
const now = new Date();
const { start_date } = eventItem;
const closed = start_date > now;
return closed;
};
export const isClosed = (eventItem: EventItem) => {
const { href } = eventItem;
const closed = href == undefined || href == '';
return closed;
};
interface EventDateTimeProps {
start_date: Date;
end_date: Date;
}
/**
* Represents the events date
*/
const EventDateTime = ({ start_date, end_date }: EventDateTimeProps) => {
const start = (
<time dateTime={formatDate(start_date, DateFormat.HTMlDateTime)}>
{formatDate(start_date)}
</time>
);
if (start_date == end_date)
return (
<span>
<SlCalender /> {start}
</span>
);
const end = (
<time dateTime={formatDate(end_date, DateFormat.HTMlDateTime)}>
{formatDate(end_date)}
</time>
);
return (
<span>
<SlCalender /> {start} - {end}
</span>
);
};
export default function Event({ eventItem }: Props) {
const { title, href, start_date, end_date, image, location } = eventItem;
const closed = isClosed(eventItem);
const styleList = [styles.container];
if (closed) styleList.push(styles.closed);
// Build ui
const content = (
<>
{/* Background Image */}
<span className={styles.imageContainer}>
<Image src={image.src} alt={image.alt} fill />
</span>
{/* Content */}
<div>
<h3>{title}</h3>
<EventDateTime start_date={start_date} end_date={end_date} />
<br />
<span>
<SlLocationPin /> {location}
</span>
</div>
</>
);
if (closed) {
return <div className={styleList.join(' ')}>{content}</div>;
} else {
return (
<Link href={href} className={styleList.join(' ')}>
{content}
</Link>
);
}
}