VolumeSlider.jsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. {
  28. (this.props.muted) ? ([
  29. <i className="material-icons" key="unmuteButton" onClick={ this.unmuteVolume }>volume_off</i>,
  30. <input key="disabledVolumeInput" type="range" min="0" max="10000" value="0" disabled/>,
  31. ]) : ([
  32. <i className="material-icons" key="muteButton" onClick={ this.muteVolume }>volume_up</i>,
  33. <input key="volumeInput" type="range" min="0" max="10000" value={ this.props.volume * 100 } onChange={ (e) => { this.changeVolumeHandler(e.target.value) } }/>, //Add default value
  34. ])
  35. }
  36. </div>
  37. );
  38. }
  39. }