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.

65 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 'flavours/glitch/actions/modal';
  10. import { changeLocalSetting } from 'flavours/glitch/actions/local_settings';
  11. const mapStateToProps = state => ({
  12. settings: state.get('local_settings'),
  13. });
  14. const mapDispatchToProps = dispatch => ({
  15. onChange (setting, value) {
  16. dispatch(changeLocalSetting(setting, value));
  17. },
  18. onClose () {
  19. dispatch(closeModal());
  20. },
  21. });
  22. class LocalSettings extends React.PureComponent {
  23. static propTypes = {
  24. onChange: PropTypes.func.isRequired,
  25. onClose: PropTypes.func.isRequired,
  26. settings: ImmutablePropTypes.map.isRequired,
  27. };
  28. state = {
  29. currentIndex: 0,
  30. };
  31. navigateTo = (index) =>
  32. this.setState({ currentIndex: +index });
  33. render () {
  34. const { navigateTo } = this;
  35. const { onChange, onClose, settings } = this.props;
  36. const { currentIndex } = this.state;
  37. return (
  38. <div className='glitch modal-root__modal local-settings'>
  39. <LocalSettingsNavigation
  40. index={currentIndex}
  41. onClose={onClose}
  42. onNavigate={navigateTo}
  43. />
  44. <LocalSettingsPage
  45. index={currentIndex}
  46. onChange={onChange}
  47. settings={settings}
  48. />
  49. </div>
  50. );
  51. }
  52. }
  53. export default connect(mapStateToProps, mapDispatchToProps)(LocalSettings);