Skip to content
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

Projects gallery: reset gallery state #15621

Merged
merged 10 commits into from Jun 8, 2017
Merged

Projects gallery: reset gallery state #15621

merged 10 commits into from Jun 8, 2017

Conversation

caleybrock
Copy link
Contributor

UX fix: If I click on “View more ___ Projects,” go back to My projects list, and then go back to the Public Gallery, I should be taken back to the main gallery page (not stay in the specific projects page)

This PR sets up redux in the project gallery and uses it to store the page location.

Copy link
Member

@davidsbailey davidsbailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work Caley! Moving onto redux is a great step and I'll be moving more stuff to the store very soon after this is merged in. Just one actionable comment below.

import {registerReducers} from '@cdo/apps/redux';

// Actions
const TOGGLE_GALLERY = 'Projects/TOGGLE_GALLERY';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another minor style difference: that gamelab is using camel case like Projects whereas our other code uses lowercase like projects. Again this is fine to ignore since it'd be easy to change later if we decide to.

@@ -0,0 +1,30 @@
/** @file Redux actions and reducer for the Projects Gallery */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noting that the filename here follows the style used in gamelab, whereas we use redux.js in most other parts in apps. I think this is fine and should be easier to switch later if we decide to standardize.

@@ -50,31 +48,29 @@ const styles = {

class GallerySwitcher extends Component {
static propTypes = {
initialGallery: PropTypes.oneOf(Object.keys(Galleries)).isRequired,
pageLocation: PropTypes.string.isRequired,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name pageLocation seems misleading since it suggests a URL path like /projects or /projects/public. What do you think about calling this selectedGallery, or anything else without "location" in it? If you do change it, the string should probably be changed everywhere it appears in this PR.

Copy link
Member

@davidsbailey davidsbailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started building on top of this PR and now i have a few more requests :) I couldn't figure out what kind of thing selectGallery was from reading our code, so I went to look it up in the redux docs and now there are a couple of places I think it would be helpful to add or change code comments in projectsModule.js.

/** @file Redux actions and reducer for the Projects Gallery */
import {registerReducers} from '@cdo/apps/redux';

// Actions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to http://redux.js.org/docs/basics/Actions.html these are "Action types".

*/
export function selectGallery(projectType) {
return { type: TOGGLE_GALLERY, projectType: projectType };
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to http://redux.js.org/docs/basics/Actions.html these are "Action creators".

selectGallery(gallery){
dispatch(selectGallery(gallery));
}
}))(Radium(GallerySwitcher));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connect actually has a short-form, where if you're just dispatch actions with the same props, I believe you can do this:

connect({state => ({
  pageLocation: state.pageLocation
}), { selectGallery });


// Reducer
function pageLocation(state, action) {
const defaultState = isPublic ? 'PUBLIC' : 'PRIVATE';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename defaultState to initialState and move it outside of the reducer. Then you can do

const initialState = isPublic ? 'PUBLIC' : 'PRIVATE';
function pageLocation(state=initialState, action) {
   // action handling here

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this some more, I think I would move the isPublic check out of this module and have a caller set the state based on window.location. This module itself should not depend on window.location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants