VolumeSlider.jsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React, { Component } from "react";
  2. import PropTypes from "prop-types";
  3. import { connect } from "react-redux";
  4. import { changeVolume, changeVolumeMuted } from "actions/volume";
  5. @connect(state => ({
  6. volume: state.volume.get("volume"),
  7. muted: state.volume.get("muted"),
  8. }))
  9. export default class VolumeSlider extends Component {
  10. constructor(props) {
  11. super(props);
  12. }
  13. changeVolumeHandler = (volume) => {
  14. volume = volume / 100;
  15. localStorage.setItem("volume", volume);
  16. this.props.dispatch(changeVolume(volume));
  17. };
  18. muteVolume = () => {
  19. this.props.dispatch(changeVolumeMuted(true));
  20. };
  21. unmuteVolume = () => {
  22. this.props.dispatch(changeVolumeMuted(false));
  23. };
  24. render() {
  25. return (
  26. <div className="volume-container">
  27. <h2>{ this.props.volume }. Muted: { (this.props.muted) ? "true" : "false" }</h2>
  28. {
  29. (this.props.muted) ? ([
  30. <i className="material-icons" key="unmuteButton" onClick={ this.unmuteVolume }>volume_off</i>,
  31. <input key="disabledVolumeInput" type="range" min="0" max="10000" value="0" disabled/>,
  32. ]) : ([
  33. <i className="material-icons" key="muteButton" onClick={ this.muteVolume }>volume_up</i>,
  34. <input key="volumeInput" type="range" min="0" max="10000" value={ this.props.volume * 100 } onChange={ (e) => { this.changeVolumeHandler(e.target.value) } }/>, //Add default value
  35. ])
  36. }
  37. </div>
  38. );
  39. }
  40. }