Skip to content
This repository was archived by the owner on Mar 7, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions src/views/pages/HomeView/Events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React from 'react';
import React, {
useCallback,
useState,
useEffect
} from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import axios from 'src/utils/axios';
import useIsMountedRef from 'src/hooks/useIsMountedRef';

import {
Box,
Expand All @@ -13,7 +19,6 @@ import {
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import CardMedia from '@material-ui/core/CardMedia';
import { events } from './HomeViewData';

const useStyles = makeStyles(theme => ({
root: {
Expand All @@ -40,7 +45,8 @@ const useStyles = makeStyles(theme => ({
position: 'relative'
},
cardMedia: {
paddingTop: '55.75%' // 16:9
paddingTop: '55.75%', // 16:9
borderBottom: '1px solid #eee'
},
cardContent: {
flexGrow: 1
Expand Down Expand Up @@ -95,6 +101,26 @@ const useStyles = makeStyles(theme => ({

function Events({ className, ...rest }) {
const classes = useStyles();
const isMountedRef = useIsMountedRef();
const [events, setEvents] = useState(null);

const getEvents = useCallback(() => {
axios
.get('https://us-central1-codeforcauseorg.cloudfunctions.net/widgets/events')
.then((response) => {
if (isMountedRef.current) {
setEvents(response.data);
}
});
}, [isMountedRef]);

useEffect(() => {
getEvents();
}, [getEvents]);

if (!events) {
return null;
}

return (
<div className={clsx(classes.root, className)} {...rest}>
Expand All @@ -116,7 +142,7 @@ function Events({ className, ...rest }) {
md={4}
>
<Card className={classes.card}>
{event.date_time ? (
{event.time ? (
<div className={classes.eventdate}>
<Typography
variant="caption"
Expand All @@ -125,15 +151,15 @@ function Events({ className, ...rest }) {
fontWeight: 500
}}
>
{event.date_time}
{event.time}
</Typography>
</div>
) : (
<></>
)}
<></>
)}
<CardMedia
className={classes.cardMedia}
image={event.img}
image={event.image}
title={event.title}
/>
<CardContent className={classes.cardContent}>
Expand All @@ -142,7 +168,7 @@ function Events({ className, ...rest }) {
style={{ paddingRight: '15px' }}
gutterBottom
>
{event.title}
{event.domain}
</Typography>
<Typography
variant="span"
Expand All @@ -167,7 +193,7 @@ function Events({ className, ...rest }) {
lineHeight: '1.3'
}}
>
{event.description}
{event.title}
</Typography>
</CardContent>
</Card>
Expand Down