-
Notifications
You must be signed in to change notification settings - Fork 18
"Back to calendar" link in event page when opened in new tab/window #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
972a5d4
e21c2e1
b6211f6
54e5f4f
449168a
2e3725b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,8 @@ class EventDetails extends Component { | |
promoterInfo, | ||
} = this.props.event | ||
|
||
const { calendar } = this.props | ||
|
||
// TODO: migrate old events to have flyer section and not just "flyerUrl" property | ||
const { movedToEvent } = this.props | ||
|
||
|
@@ -312,6 +314,7 @@ class EventDetails extends Component { | |
: ( | ||
// eslint-disable-next-line | ||
<div className='EventDetails-container'> | ||
<Link className="back-to-calendar" to={`/calendars/${calendar.slug}?past=visible`}>Back to {calendar.name}</Link> | ||
{eventDetailsComponent} | ||
</div> | ||
) | ||
|
@@ -321,14 +324,15 @@ class EventDetails extends Component { | |
|
||
EventDetails.propTypes = { | ||
event: PropTypes.object.isRequired, | ||
calendar: PropTypes.object, | ||
// if event status is "Moved" this would contain event it's moved to | ||
movedToEvent: PropTypes.object, | ||
} | ||
|
||
export { EventDetails } | ||
|
||
import { connect } from 'react-redux' | ||
import { getEvent } from 'shared/reducers/reducer.js' | ||
import { getEvent, getCalendar } from 'shared/reducers/reducer.js' | ||
import { replaceRoutedModal } from 'shared/actions/actions.js' | ||
|
||
export default connect( | ||
|
@@ -337,13 +341,14 @@ export default connect( | |
// calendar: getCalendar() | ||
|
||
const event = getEvent(state, ownProps.params.eventId) | ||
const calendar = getCalendar(state, {calendarId: event.calendarId}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should be consistent with simple selectors like that and either use named arguments or don't. Above selector doesn't use those since it's pretty self-explanatory when you see like like this:
Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @graymur yeah, I know, it just became apparent here. I am fine with doing it in another PR. |
||
let movedToEvent | ||
|
||
if (event.status === Statuses.moved && event.movedToEventId) { | ||
movedToEvent = getEvent(state, event.movedToEventId) | ||
} | ||
|
||
return { event, movedToEvent } | ||
return { event, movedToEvent, calendar } | ||
}, | ||
(dispatch, ownProps) => ({ | ||
replaceRoutedModal: (path) => dispatch(replaceRoutedModal({path, hasPadding: false})) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ const toByIdMap = objects => objects.reduce((map, x) => { | |
return map | ||
}, {}) | ||
|
||
const setEventsCalendarId = calendarId => event => Object.assign({}, event, {calendarId}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's babel transpiled, so you can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
const toArrayOfIds = objects => objects.map(x => x.id) | ||
|
||
const initialState = { | ||
|
@@ -60,16 +62,17 @@ const initialState = { | |
}, | ||
|
||
events: toByIdMap( | ||
norcalMtb2016Events | ||
.concat(ncnca2016Events) | ||
.concat(ncnca2017Events) | ||
.concat(usac2017Events) | ||
norcalMtb2016Events.map(setEventsCalendarId('cal-norcal-mtb-2016')) | ||
.concat(ncnca2016Events.map(setEventsCalendarId('cal-ncnca-2016'))) | ||
.concat(ncnca2017Events.map(setEventsCalendarId('cal-ncnca-2017'))) | ||
.concat(usac2017Events.map(setEventsCalendarId('cal-usac-2017'))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this line gets confusing with this amount of manipulations. Let's refactor to: const _ = require('lodash')
//..
const setCalendarId = calendarId => event => ({...event, calendarId })
const toByIdMap = _.partialRight(_.keyBy, 'id')
const result = toByIdMap(
_.concat(
norcalMtb2016Events.map(setCalendarId('cal-norcal-mtb-2016')),
ncnca2016Events.map(setCalendarId('cal-ncnca-2016')),
//...
)
) Notice shorter name of the function Also, I forgot to mention that I plan to set a relationship as many-to-many. So event can belong to multiple calendars. Use-case would be you would want to pick events from multiple calendars and create your own or combine multiple calendars into own calendar. But every even also should point to it's "primaryCalendar" (not sure if "primary" is a good name) where it was created originally. With that I think we should name this property as "primaryCalendarId" since later we would have "calendarIds" and having singular "calendarId" along with plural "calendarIds" would be confusing. Open for naming ideas. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @graymur sounds good. |
||
), | ||
|
||
//calenars map by id | ||
calendars: { | ||
['cal-norcal-mtb-2016']: { | ||
id: 'cal-norcal-mtb-2016', | ||
slug: 'norcal-mtb', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slug is actually a calculated property, you can see how it's done here https://github.com/Restuta/rcn.io/blob/master/src/client/calendar/utils/get-calendar-id.js in reverse. Convention is https://rcn.io/calendars/usac-2017 (is canonical url) So part of calendar id after
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Restuta maybe create a helper function getCalendarsSlug(calendar) and use it everywhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
year: 2016, | ||
name: '2016 NorCal MTB Calendar', | ||
highlight: { | ||
|
@@ -82,6 +85,7 @@ const initialState = { | |
}, | ||
['cal-ncnca-2017-draft']: { | ||
id: 'cal-ncnca-2017-draft', | ||
slug: 'ncnca-2017', | ||
year: 2017, | ||
name: '2017 NCNCA Calendar', | ||
// highlight: { | ||
|
@@ -97,6 +101,7 @@ const initialState = { | |
}, | ||
['cal-ncnca-2018-draft']: { | ||
id: 'cal-ncnca-2018-draft', | ||
slug: 'ncnca-2017', | ||
year: 2018, | ||
name: '2018 NCNCA Calendar', | ||
// highlight: { | ||
|
@@ -113,6 +118,7 @@ const initialState = { | |
}, | ||
['cal-ncnca-2016']: { | ||
id: 'cal-ncnca-2016', | ||
slug: 'ncnca-2016', | ||
year: 2016, | ||
name: '2016 NCNCA Calendar', | ||
// highlight: { | ||
|
@@ -127,6 +133,7 @@ const initialState = { | |
}, | ||
['cal-ncnca-2017']: { | ||
id: 'cal-ncnca-2017', | ||
slug: 'ncnca-2017', | ||
year: 2017, | ||
name: '2017 NCNCA Calendar', | ||
// highlight: { | ||
|
@@ -141,6 +148,7 @@ const initialState = { | |
}, | ||
['cal-usac-2017']: { | ||
id: 'cal-usac-2017', | ||
slug: 'usac-2017', | ||
year: 2017, | ||
name: '2017 USA Cycling Calendar', | ||
// highlight: { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about destructuring this all together below with
movedToEvent
?