You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.6 KiB

  1. // Package imports.
  2. import React from 'react';
  3. import PropTypes from 'prop-types';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import { connect } from 'react-redux';
  6. // Our imports
  7. import LocalSettingsPage from './page';
  8. import LocalSettingsNavigation from './navigation';
  9. import { closeModal } from 'themes/glitch/actions/modal';
  10. import { changeLocalSetting } from 'themes/glitch/actions/local_settings';
  11. // Stylesheet imports
  12. import './style.scss';
  13. const mapStateToProps = state => ({
  14. settings: state.get('local_settings'),
  15. });
  16. const mapDispatchToProps = dispatch => ({
  17. onChange (setting, value) {
  18. dispatch(changeLocalSetting(setting, value));
  19. },
  20. onClose () {
  21. dispatch(closeModal());
  22. },
  23. });
  24. class LocalSettings extends React.PureComponent {
  25. static propTypes = {
  26. onChange: PropTypes.func.isRequired,
  27. onClose: PropTypes.func.isRequired,
  28. settings: ImmutablePropTypes.map.isRequired,
  29. };
  30. state = {
  31. currentIndex: 0,
  32. };
  33. navigateTo = (index) =>
  34. this.setState({ currentIndex: +index });
  35. render () {
  36. const { navigateTo } = this;
  37. const { onChange, onClose, settings } = this.props;
  38. const { currentIndex } = this.state;
  39. return (
  40. <div className='glitch modal-root__modal local-settings'>
  41. <LocalSettingsNavigation
  42. index={currentIndex}
  43. onClose={onClose}
  44. onNavigate={navigateTo}
  45. />
  46. <LocalSettingsPage
  47. index={currentIndex}
  48. onChange={onChange}
  49. settings={settings}
  50. />
  51. </div>
  52. );
  53. }
  54. }
  55. export default connect(mapStateToProps, mapDispatchToProps)(LocalSettings);