SongScanningDialog.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React, { Component } from 'react'
  2. import '../css/SongScanningDialog.scss'
  3. import { connect } from 'react-redux'
  4. import Modal from './Modal';
  5. import ProgressBar from './ProgressBar';
  6. class SongScanningDialog extends Component {
  7. constructor(props) {
  8. super(props)
  9. this.state = {
  10. open: false
  11. }
  12. }
  13. componentWillReceiveProps(props) {
  14. if(props.scanning === true) this.setState({ open: true })
  15. }
  16. render() {
  17. return (
  18. this.state.open ?
  19. <Modal width={ 575 } height={ 330 } onClose={ () => { this.setState({ open: false }) } }>
  20. <h1 className={ `scanning-text theme-${this.props.theme}` }>{ !this.props.scanning ? `Finished scanning for songs.` : 'Scanning for songs...' }</h1>
  21. <div className="song-scanning-progress"><ProgressBar progress={ this.props.processedFiles / this.props.discoveredFiles * 100 } /></div>
  22. <h5 className="scanning-text">{ `${ this.props.processedFiles } / ${ this.props.discoveredFiles } Files scanned.${ !this.props.scanning ? ` | ${this.props.songs.length } songs discovered.` : '..' }` }</h5>
  23. { !this.props.scanning ? <h5 className="scanning-text">Click outside to exit.</h5> : null }
  24. </Modal>
  25. : null
  26. )
  27. }
  28. }
  29. let mapStateToProps = state => ({
  30. theme: state.settings.theme,
  31. songs: state.songs.downloadedSongs,
  32. scanning: state.songs.scanningForSongs,
  33. discoveredFiles: state.songs.discoveredFiles,
  34. processedFiles: state.songs.processedFiles
  35. })
  36. export default connect(mapStateToProps, null)(SongScanningDialog)