Skip to content
This repository was archived by the owner on Mar 7, 2024. It is now read-only.

Commit 5004afb

Browse files
Adds events firebase api to event section (#65)
1 parent de0cc44 commit 5004afb

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

src/views/pages/HomeView/Events.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import React from 'react';
1+
import React, {
2+
useCallback,
3+
useState,
4+
useEffect
5+
} from 'react';
26
import PropTypes from 'prop-types';
37
import clsx from 'clsx';
8+
import axios from 'src/utils/axios';
9+
import useIsMountedRef from 'src/hooks/useIsMountedRef';
410

511
import {
612
Box,
@@ -13,7 +19,6 @@ import {
1319
import Card from '@material-ui/core/Card';
1420
import CardContent from '@material-ui/core/CardContent';
1521
import CardMedia from '@material-ui/core/CardMedia';
16-
import { events } from './HomeViewData';
1722

1823
const useStyles = makeStyles(theme => ({
1924
root: {
@@ -40,7 +45,8 @@ const useStyles = makeStyles(theme => ({
4045
position: 'relative'
4146
},
4247
cardMedia: {
43-
paddingTop: '55.75%' // 16:9
48+
paddingTop: '55.75%', // 16:9
49+
borderBottom: '1px solid #eee'
4450
},
4551
cardContent: {
4652
flexGrow: 1
@@ -95,6 +101,26 @@ const useStyles = makeStyles(theme => ({
95101

96102
function Events({ className, ...rest }) {
97103
const classes = useStyles();
104+
const isMountedRef = useIsMountedRef();
105+
const [events, setEvents] = useState(null);
106+
107+
const getEvents = useCallback(() => {
108+
axios
109+
.get('https://us-central1-codeforcauseorg.cloudfunctions.net/widgets/events')
110+
.then((response) => {
111+
if (isMountedRef.current) {
112+
setEvents(response.data);
113+
}
114+
});
115+
}, [isMountedRef]);
116+
117+
useEffect(() => {
118+
getEvents();
119+
}, [getEvents]);
120+
121+
if (!events) {
122+
return null;
123+
}
98124

99125
return (
100126
<div className={clsx(classes.root, className)} {...rest}>
@@ -116,7 +142,7 @@ function Events({ className, ...rest }) {
116142
md={4}
117143
>
118144
<Card className={classes.card}>
119-
{event.date_time ? (
145+
{event.time ? (
120146
<div className={classes.eventdate}>
121147
<Typography
122148
variant="caption"
@@ -125,15 +151,15 @@ function Events({ className, ...rest }) {
125151
fontWeight: 500
126152
}}
127153
>
128-
{event.date_time}
154+
{event.time}
129155
</Typography>
130156
</div>
131157
) : (
132-
<></>
133-
)}
158+
<></>
159+
)}
134160
<CardMedia
135161
className={classes.cardMedia}
136-
image={event.img}
162+
image={event.image}
137163
title={event.title}
138164
/>
139165
<CardContent className={classes.cardContent}>
@@ -142,7 +168,7 @@ function Events({ className, ...rest }) {
142168
style={{ paddingRight: '15px' }}
143169
gutterBottom
144170
>
145-
{event.title}
171+
{event.domain}
146172
</Typography>
147173
<Typography
148174
variant="span"
@@ -167,7 +193,7 @@ function Events({ className, ...rest }) {
167193
lineHeight: '1.3'
168194
}}
169195
>
170-
{event.description}
196+
{event.title}
171197
</Typography>
172198
</CardContent>
173199
</Card>

0 commit comments

Comments
 (0)