import React from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import * as helpers from '../helpers'; import * as uiActions from '../services/ui/actions'; class DebugInfo extends React.Component { constructor(props) { super(props); } localStorageSize() { let data = ''; for (const key in window.localStorage) { if (window.localStorage.hasOwnProperty(key)) { data += window.localStorage[key]; } } let used = 0; const total = 5000; if (data !== '') { used = ((data.length * 16) / (8 * 1024)).toFixed(2); } return { used, percent: (used / total * 100).toFixed(2), }; } renderLoadQueue() { if (!this.props.ui.load_queue) { return null; } const { load_queue } = this.props.ui; const queue = []; return (
{queue}
); } renderLoadQueue() { if (!this.props.ui.load_queue) { return
Nothing loading
; } const { load_queue } = this.props.ui; const queue = []; for (const key in load_queue) { if (load_queue.hasOwnProperty(key)) { queue.push(
{load_queue[key]}
); } } if (queue.length > 0) { return (
{queue}
); } return
Nothing loading
; } render() { const localStorageUsage = this.localStorageSize(); return (
Version: {' '} {version}
Build: {' '} {build}
Indexes
Albums: {' '} {this.props.core.albums ? Object.keys(this.props.core.albums).length : '0'}
Artists: {' '} {this.props.core.artists ? Object.keys(this.props.core.artists).length : '0'}
Playlists: {' '} {this.props.core.playlists ? Object.keys(this.props.core.playlists).length : '0'}
Tracks: {' '} {this.props.core.tracks ? Object.keys(this.props.core.tracks).length : '0'}
Users: {' '} {this.props.core.users ? Object.keys(this.props.core.users).length : '0'}
Notifications: {' '} {this.props.ui.notifications ? Object.keys(this.props.ui.notifications).length : '0'}
Processes: {' '} {this.props.ui.processes ? Object.keys(this.props.ui.processes).length : '0'}
Enqueue batches: {' '} {this.props.mopidy.enqueue_uris_batches ? this.props.mopidy.enqueue_uris_batches.length : '0'}
Cached URLs: {' '} {Object.keys(helpers.getStorage('cache')).length}
Config
Slim mode: {' '} {this.props.ui.slim_mode ? 'on' : 'off'}
Test mode: {' '} {this.props.ui.test_mode ? 'on' : 'off'}
Touch: {' '} {helpers.isTouchDevice() ? 'on' : 'off'}
LocalStorage usage: {' '} {localStorageUsage.used} kb (~ {localStorageUsage.percent} %)
Selected tracks: {' '} {this.props.ui.selected_tracks.length}
{ this.props.ui.selected_tracks.map((track_key, index) => (
{track_key}
)) }
Load queue
{this.renderLoadQueue()}
); } } const mapStateToProps = (state, ownProps) => ({ core: state.core, ui: state.ui, mopidy: state.mopidy, }); const mapDispatchToProps = (dispatch) => ({ uiActions: bindActionCreators(uiActions, dispatch), }); export default connect(mapStateToProps, mapDispatchToProps)(DebugInfo);