1- import React from 'react' ;
1+ import React , {
2+ useCallback ,
3+ useState ,
4+ useEffect
5+ } from 'react' ;
26import PropTypes from 'prop-types' ;
37import clsx from 'clsx' ;
8+ import axios from 'src/utils/axios' ;
9+ import useIsMountedRef from 'src/hooks/useIsMountedRef' ;
410
511import {
612 Box ,
@@ -13,7 +19,6 @@ import {
1319import Card from '@material-ui/core/Card' ;
1420import CardContent from '@material-ui/core/CardContent' ;
1521import CardMedia from '@material-ui/core/CardMedia' ;
16- import { events } from './HomeViewData' ;
1722
1823const 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
96102function 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