mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-22 23:27:54 -05:00
refactor intro.jsx and navigation.jsx to use new navigation reducer single registration open request action
This commit is contained in:
parent
d4676ec990
commit
baa4e0e2c3
2 changed files with 10 additions and 38 deletions
|
@ -15,20 +15,12 @@ class Intro extends React.Component {
|
|||
constructor (props) {
|
||||
super(props);
|
||||
bindAll(this, [
|
||||
'handleClickRegistration',
|
||||
'handleShowVideo'
|
||||
]);
|
||||
this.state = {
|
||||
videoOpen: false
|
||||
};
|
||||
}
|
||||
handleClickRegistration (event) {
|
||||
if (this.props.useScratch3Registration) {
|
||||
this.props.navigateToRegistration(event);
|
||||
} else {
|
||||
this.props.handleOpenRegistration(event);
|
||||
}
|
||||
}
|
||||
handleShowVideo () {
|
||||
this.setState({videoOpen: true});
|
||||
}
|
||||
|
@ -52,7 +44,7 @@ class Intro extends React.Component {
|
|||
<a
|
||||
className="intro-button join-button button"
|
||||
href="#"
|
||||
onClick={this.handleClickRegistration}
|
||||
onClick={this.props.handleClickRegistration}
|
||||
>
|
||||
{this.props.messages['intro.join']}
|
||||
</a>
|
||||
|
@ -115,7 +107,7 @@ class Intro extends React.Component {
|
|||
}
|
||||
|
||||
Intro.propTypes = {
|
||||
handleOpenRegistration: PropTypes.func,
|
||||
handleClickRegistration: PropTypes.func,
|
||||
messages: PropTypes.shape({
|
||||
'intro.aboutScratch': PropTypes.string,
|
||||
'intro.forEducators': PropTypes.string,
|
||||
|
@ -125,9 +117,7 @@ Intro.propTypes = {
|
|||
'intro.tagLine1': PropTypes.string,
|
||||
'intro.tagLine2': PropTypes.string,
|
||||
'intro.watchVideo': PropTypes.string
|
||||
}),
|
||||
navigateToRegistration: PropTypes.func,
|
||||
useScratch3Registration: PropTypes.bool
|
||||
})
|
||||
};
|
||||
|
||||
Intro.defaultProps = {
|
||||
|
@ -145,18 +135,13 @@ Intro.defaultProps = {
|
|||
};
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
session: state.session,
|
||||
useScratch3Registration: state.navigation.useScratch3Registration
|
||||
session: state.session
|
||||
});
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
handleOpenRegistration: event => {
|
||||
handleClickRegistration: event => {
|
||||
event.preventDefault();
|
||||
dispatch(navigationActions.setRegistrationOpen(true));
|
||||
},
|
||||
navigateToRegistration: event => {
|
||||
event.preventDefault();
|
||||
navigationActions.navigateToRegistration();
|
||||
dispatch(navigationActions.handleRegistrationRequested());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ class Navigation extends React.Component {
|
|||
super(props);
|
||||
bindAll(this, [
|
||||
'getProfileUrl',
|
||||
'handleClickRegistration',
|
||||
'handleSearchSubmit'
|
||||
]);
|
||||
this.state = {
|
||||
|
@ -78,13 +77,6 @@ class Navigation extends React.Component {
|
|||
if (!this.props.user) return;
|
||||
return `/users/${this.props.user.username}/`;
|
||||
}
|
||||
handleClickRegistration (event) {
|
||||
if (this.props.useScratch3Registration) {
|
||||
this.props.navigateToRegistration(event);
|
||||
} else {
|
||||
this.props.handleOpenRegistration(event);
|
||||
}
|
||||
}
|
||||
handleSearchSubmit (formData) {
|
||||
let targetUrl = '/search/projects';
|
||||
if (formData.q) {
|
||||
|
@ -201,7 +193,7 @@ class Navigation extends React.Component {
|
|||
<a
|
||||
className="registrationLink"
|
||||
href="#"
|
||||
onClick={this.handleClickRegistration}
|
||||
onClick={this.props.handleClickRegistration}
|
||||
>
|
||||
<FormattedMessage id="general.joinScratch" />
|
||||
</a>
|
||||
|
@ -239,13 +231,12 @@ class Navigation extends React.Component {
|
|||
Navigation.propTypes = {
|
||||
accountNavOpen: PropTypes.bool,
|
||||
getMessageCount: PropTypes.func,
|
||||
handleClickRegistration: PropTypes.func,
|
||||
handleCloseAccountNav: PropTypes.func,
|
||||
handleLogOut: PropTypes.func,
|
||||
handleOpenRegistration: PropTypes.func,
|
||||
handleToggleAccountNav: PropTypes.func,
|
||||
handleToggleLoginOpen: PropTypes.func,
|
||||
intl: intlShape,
|
||||
navigateToRegistration: PropTypes.func,
|
||||
permissions: PropTypes.shape({
|
||||
admin: PropTypes.bool,
|
||||
social: PropTypes.bool,
|
||||
|
@ -296,9 +287,9 @@ const mapDispatchToProps = dispatch => ({
|
|||
handleCloseAccountNav: () => {
|
||||
dispatch(navigationActions.setAccountNavOpen(false));
|
||||
},
|
||||
handleOpenRegistration: event => {
|
||||
handleClickRegistration: event => {
|
||||
event.preventDefault();
|
||||
dispatch(navigationActions.setRegistrationOpen(true));
|
||||
dispatch(navigationActions.handleRegistrationRequested());
|
||||
},
|
||||
handleLogOut: event => {
|
||||
event.preventDefault();
|
||||
|
@ -308,10 +299,6 @@ const mapDispatchToProps = dispatch => ({
|
|||
event.preventDefault();
|
||||
dispatch(navigationActions.toggleLoginOpen());
|
||||
},
|
||||
navigateToRegistration: event => {
|
||||
event.preventDefault();
|
||||
navigationActions.navigateToRegistration();
|
||||
},
|
||||
setMessageCount: newCount => {
|
||||
dispatch(messageCountActions.setCount(newCount));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue