-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow user to set app to developer mode
closes #88
- Loading branch information
1 parent
58ab5da
commit f8c65bf
Showing
15 changed files
with
250 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
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,86 @@ | ||
import React, { Component } from 'react'; | ||
import FormControl from '@material-ui/core/FormControl'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import { withTranslation } from 'react-i18next'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import Switch from '@material-ui/core/Switch'; | ||
import FormControlLabel from '@material-ui/core/FormControlLabel'; | ||
import { getDeveloperMode, setDeveloperMode } from '../../actions'; | ||
import Loader from './Loader'; | ||
|
||
const styles = theme => ({ | ||
formControl: { | ||
margin: theme.spacing.unit, | ||
minWidth: 120, | ||
}, | ||
}); | ||
|
||
class DeveloperSwitch extends Component { | ||
static propTypes = { | ||
developerMode: PropTypes.bool.isRequired, | ||
activity: PropTypes.bool.isRequired, | ||
t: PropTypes.func.isRequired, | ||
dispatchGetDeveloperMode: PropTypes.func.isRequired, | ||
dispatchSetDeveloperMode: PropTypes.func.isRequired, | ||
classes: PropTypes.shape({ | ||
formControl: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
const { dispatchGetDeveloperMode } = this.props; | ||
dispatchGetDeveloperMode(); | ||
} | ||
|
||
handleChange = async ({ target }) => { | ||
const { dispatchSetDeveloperMode } = this.props; | ||
const { checked } = target; | ||
dispatchSetDeveloperMode(checked); | ||
}; | ||
|
||
render() { | ||
const { classes, t, developerMode, activity } = this.props; | ||
|
||
if (activity) { | ||
return <Loader />; | ||
} | ||
|
||
const control = ( | ||
<Switch | ||
checked={developerMode} | ||
onChange={this.handleChange} | ||
value={developerMode} | ||
color="primary" | ||
/> | ||
); | ||
|
||
return ( | ||
<FormControl className={classes.formControl}> | ||
<FormControlLabel control={control} label={t('Developer Mode')} /> | ||
</FormControl> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = ({ User }) => ({ | ||
developerMode: User.getIn(['current', 'developerMode']), | ||
activity: User.getIn(['current', 'activity']).size, | ||
}); | ||
|
||
const mapDispatchToProps = { | ||
dispatchGetDeveloperMode: getDeveloperMode, | ||
dispatchSetDeveloperMode: setDeveloperMode, | ||
}; | ||
|
||
const ConnectedComponent = connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(DeveloperSwitch); | ||
|
||
const StyledComponent = withStyles(styles)(ConnectedComponent); | ||
|
||
const TranslatedComponent = withTranslation()(StyledComponent); | ||
|
||
export default TranslatedComponent; |
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
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
Oops, something went wrong.