Seekerbar.jsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React, { Component } from "react";
  2. import PropTypes from "prop-types";
  3. import { connect } from "react-redux";
  4. @connect(state => ({
  5. timeElapsed: state.station.currentSong.getIn(["timings", "timeElapsed"]) * 1000,
  6. timeTotal: state.station.currentSong.getIn(["timings", "duration"]) * 1000,
  7. paused: state.station.info.get("paused"),
  8. }))
  9. export default class Seekerbar extends Component {
  10. static propTypes = {
  11. onRef: PropTypes.func,
  12. };
  13. static defaultProps = {
  14. onRef: () => {},
  15. };
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. timeElapsedGuess: 0,
  20. percentage: 0,
  21. };
  22. setInterval(() => {
  23. if (!this.props.paused) {
  24. let timeElapsedGuess = this.state.timeElapsedGuess;
  25. timeElapsedGuess += 15;
  26. if (timeElapsedGuess <= this.props.timeElapsed) {
  27. timeElapsedGuess = this.props.timeElapsed;
  28. }
  29. this.setState({
  30. percentage: (timeElapsedGuess / this.props.timeTotal) * 100,
  31. timeElapsedGuess,
  32. });
  33. } else {
  34. this.setState({
  35. percentage: (this.props.timeElapsed / this.props.timeTotal) * 100,
  36. });
  37. }
  38. }, 50);
  39. }
  40. render() {
  41. return (
  42. <div className="seekerbar-container">
  43. <span style={{"width": this.state.percentage + "%"}}/>
  44. </div>
  45. );
  46. }
  47. }