Youtube music and video downloader

Options.jsx 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React, { Component, PropTypes } from 'react';
  2. import Video from './Video';
  3. import classnames from 'classnames';
  4. export default class Options extends Component {
  5. render() {
  6. return (
  7. <div>
  8. { _.map(this.props.handlers, (h) => (
  9. <button key={h.type} className={this.getClasses(h.type)}
  10. onClick={() => h.handler(this.props.video)}
  11. disabled={this.isDisabled(h.type)} title={this.getErrorMessage(h.type)}>
  12. <div className="option-progress" style={{ width: this.getProgress(h.type) + '%' }} />
  13. <i className="fa fa-download" /> {h.type}
  14. </button>
  15. )) }
  16. </div>
  17. );
  18. }
  19. getProgress(type) {
  20. return !this.props.converted ? 0 : this.props.converted[type === 'MP3' ? 'audio_progress' : 'video_progress'];
  21. }
  22. isDisabled(type) {
  23. return !this.props.converted || !this.props.converted[type === 'MP3' ? 'audio' : 'video'];
  24. }
  25. getClasses(type) {
  26. let option = true;
  27. let unreachable = null;
  28. if (this.props.converted)
  29. unreachable = (type === 'MP3' ? this.props.converted.error_audio : this.props.converted.error_video);
  30. return classnames({ option, unreachable });
  31. }
  32. getErrorMessage(type) {
  33. let typestr = (type === 'MP3' ? 'audio' : 'video');
  34. return this.props.converted && this.props.converted[`error_${typestr}`] || null;
  35. }
  36. }
  37. Options.propTypes = {
  38. handlers: PropTypes.arrayOf(PropTypes.shape({
  39. type: PropTypes.string,
  40. handler: PropTypes.func
  41. })),
  42. video: PropTypes.instanceOf(Video),
  43. converted: PropTypes.object
  44. };