generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #323 from hackforla/client/schedule-info
Client/schedule info
- Loading branch information
Showing
9 changed files
with
240 additions
and
49 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
client/web/src/components/MapPage/shared/LocationCard/LocationSchedule/Hours.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import React, { useState, useEffect, useMemo, useCallback } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { makeStyles } from '@material-ui/core/styles' | ||
import Collapse from '@material-ui/core/Collapse' | ||
import moment from 'moment' | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
today: { | ||
'& b': { | ||
display: 'inline-block', | ||
marginRight: 14, | ||
fontWeight: 400, | ||
}, | ||
}, | ||
table: { | ||
marginTop: 10, | ||
'& td, th': { | ||
padding: '2px 0', | ||
}, | ||
}, | ||
toggle: { | ||
color: theme.palette.primary.main, | ||
textDecoration: 'underline', | ||
userSelect: 'none', | ||
cursor: 'pointer', | ||
display: 'inline-block', | ||
marginLeft: 16, | ||
}, | ||
})) | ||
|
||
function formatTime(time) { | ||
let [hours, minutes] = time.split(':') | ||
hours = +hours | ||
const isPm = hours >= 12 | ||
hours = (hours > 12 ? hours - 12 : hours).toString() | ||
hours = hours.replace(/^0/, '') | ||
return `${hours}:${minutes}${isPm ? 'p' : 'a'}` | ||
} | ||
|
||
const Hours = ({ location, expandable }) => { | ||
const classes = useStyles() | ||
const [showDetails, setShowDetails] = useState(false) | ||
|
||
useEffect(() => { | ||
setShowDetails(false) | ||
}, [location]) | ||
|
||
const toggle = useCallback(() => { | ||
setShowDetails(!showDetails) | ||
}, [showDetails]) | ||
|
||
const hours = useMemo(() => { | ||
return location.hours | ||
.map((hour) => ({ | ||
beginDate: moment(hour.beginDate), | ||
endDate: moment(hour.endDate), | ||
openTime: formatTime(hour.openTime), | ||
closeTime: formatTime(hour.closeTime), | ||
})) | ||
.sort((a, b) => (b.beginDate.isBefore(a.beginDate) ? 1 : -1)) | ||
}, [location]) | ||
|
||
const today = useMemo(() => { | ||
const now = moment() | ||
return hours.find( | ||
(hour) => | ||
hour.beginDate.isSameOrBefore(now) && hour.endDate.isSameOrAfter(now) | ||
) | ||
}, [hours]) | ||
|
||
return ( | ||
<> | ||
<div className={classes.today}> | ||
{today ? ( | ||
<span> | ||
<b>Open Today</b> | ||
{today.openTime} - {today.closeTime} | ||
</span> | ||
) : ( | ||
<span>Closed Today</span> | ||
)} | ||
{expandable && ( | ||
<span className={classes.toggle} onClick={toggle}> | ||
{showDetails ? 'less' : 'more'} | ||
</span> | ||
)} | ||
</div> | ||
<Collapse in={showDetails} timeout="auto" unmountOnExit> | ||
<table className={classes.table}> | ||
<thead> | ||
<tr> | ||
<th>Date(s)</th> | ||
<th style={{ paddingLeft: 30 }}>Hours</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{hours.map((hour) => { | ||
const dateString = hour.beginDate.isSame(hour.endDate) | ||
? hour.beginDate.format('M/DD') | ||
: `${hour.beginDate.format('M/DD')} - ${hour.endDate.format( | ||
'M/DD' | ||
)}` | ||
return ( | ||
<tr> | ||
<td>{dateString}</td> | ||
<td style={{ paddingLeft: 30 }}> | ||
{hour.openTime} - {hour.closeTime} | ||
</td> | ||
</tr> | ||
) | ||
})} | ||
</tbody> | ||
</table> | ||
</Collapse> | ||
</> | ||
) | ||
} | ||
|
||
export default Hours | ||
|
||
Hours.propTypes = { | ||
location: PropTypes.shape({}).isRequired, | ||
expandable: PropTypes.bool, | ||
} | ||
|
||
Hours.defaultProps = { | ||
expandable: false, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
client/web/src/components/MapPage/shared/LocationDetail/DisplayNote.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { makeStyles } from '@material-ui/core/styles' | ||
import InfoIcon from '@material-ui/icons/Info' | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
root: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
marginBottom: 12, | ||
marginLeft: -10, | ||
}, | ||
iconCell: { | ||
width: 50, | ||
height: '100%', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
textCell: { | ||
flex: 1, | ||
fontWeight: 400, | ||
fontStyle: 'italic', | ||
}, | ||
})) | ||
|
||
const DisplayNote = ({ location }) => { | ||
const classes = useStyles() | ||
|
||
if (!location.displayNote) return null | ||
return ( | ||
<div className={classes.root}> | ||
<div className={classes.iconCell}> | ||
<InfoIcon color="primary" /> | ||
</div> | ||
<div className={classes.textCell}>{location.displayNote}</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default DisplayNote | ||
|
||
DisplayNote.propTypes = { | ||
location: PropTypes.shape({}).isRequired, | ||
showDistanceDetails: PropTypes.bool, | ||
} | ||
|
||
DisplayNote.defaultProps = { | ||
showDistanceDetails: false, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.