forked from SLoh4137/umcp-tase
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Event.tsx
executable file
·142 lines (126 loc) · 4.06 KB
/
Event.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import React, { useState } from "react"
import { Link } from "gatsby"
import moment from "moment"
import {
Button,
Card,
CardActions,
Grid,
Theme,
createStyles,
withStyles,
WithStyles,
} from "@material-ui/core"
import { useSpring, animated as a } from "react-spring"
// Components
import Text from "components/Typography/Text"
import MarkdownContent from "components/General/MarkdownContent"
import ColoredShadowImage from "components/General/ColoredShadowImage"
import ButtonLink from "components/Button/ButtonLink"
import GridWithItems from "components/General/GridWithItems"
// Types
import { EventType } from "hooks/useEvents"
// Hooks
import useDateFormat from "hooks/useDateFormat"
import usePrefersReducedMotion from "hooks/usePrefersReducedMotion"
const styles = (theme: Theme) =>
createStyles({
content: {
marginTop: theme.spacing(2),
},
tags: {
fontSize: "10px",
},
})
type Props = WithStyles<typeof styles> & {
event: EventType
showDescription?: boolean
preview?: boolean
}
function Event(props: Props) {
const { classes, event, showDescription = true, preview = false } = props
// const dateFormat = useDateFormat()
const dateFormat = "M/D"
if (!event.node.frontmatter) {
throw new Error("Frontmatter does not exist")
}
if (!event.node.fields?.slug) {
throw new Error("Slug not valid")
}
const { title, tags, date, link } = event.node.frontmatter
const { slug } = event.node.fields
const [isHover, setHover] = useState(false)
const springStyle = useSpring({
to: {
transform: isHover ? "scale(1.1)" : "scale(1.0)",
},
immediate: usePrefersReducedMotion(),
})
return (
<>
<Link
to={slug}
onMouseOver={() => setHover(true)}
onMouseLeave={() => setHover(false)}
>
<a.div style={springStyle}>
<ColoredShadowImage
image={event.image}
alt={`${title} event image`}
/>
</a.div>
</Link>
<Card elevation={0}>
<GridWithItems
className={classes.content}
direction="column"
alignItems="center"
spacing={1}
xs={false}
sm={false}
itemMargins={false}
>
{preview ? (
<></>
) : (
<Text variant="subtitle2" color="textSecondary">
{moment(date).format(dateFormat)}
</Text>
)}
<Text
variant="h6"
color="textSecondary"
align="center"
heading
>
<b>{title}</b>
</Text>
{showDescription ? (
<MarkdownContent content={event.node.excerpt} />
) : (
<></>
)}
</GridWithItems>
<CardActions>
<GridWithItems
container
alignItems="center"
justifyContent="center"
spacing={2}
xs={false}
sm={false}
itemMargins={false}
>
<Button size="small" href={link} variant="contained">
FB
</Button>
<ButtonLink size="small" to={slug} variant="contained">
Event Details
</ButtonLink>
</GridWithItems>
</CardActions>
</Card>
</>
)
}
export default withStyles(styles)(Event)