import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import localForage from 'localforage';
import { get as getStorage } from '../util/storage';
import { isTouchDevice } from '../util/helpers';
import * as uiActions from '../services/ui/actions';
import { indexToArray } from '../util/arrays';
import { decodeUri } from '../util/format';
class DebugInfo extends React.Component {
constructor(props) {
super(props);
this.state = { localForageLength: 0 };
}
componentDidMount() {
localForage.length().then((localForageLength) => this.setState({ localForageLength }));
}
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 = () => {
const { load_queue } = this.props;
if (!load_queue) return
Version:
{' '}
{version}
Build:
{' '}
{build}
Dimensions:
{' '}
{`${document.documentElement.clientWidth} (${window.innerWidth})w `}
{`${document.documentElement.clientHeight} (${window.innerHeight})h `}
State
{`Items: ${Object.keys(items).length}`}
{`Coldstore items: ${this.state.localForageLength}`}
{`Notifications: ${Object.keys(notifications).length}`}
{`Processes: ${Object.keys(processes).length}`}
{`Enqueue batches: ${enqueue_uris_batches.length}`}
{`Cached URLs: ${Object.keys(getStorage('cache')).length}`}
Config
{`Slim mode: ${slim_mode ? 'on' : 'off'}`}
{`Test mode: ${test_mode ? 'on' : 'off'}`}
{`Touch: ${isTouchDevice() ? 'on' : 'off'}`}
{`LocalStorage usage: ${localStorageUsage.used}kb (~${localStorageUsage.percent}%)`}
{`Selected tracks: ${selected_tracks.length}`}
{
selected_tracks.map((track_key, index) => (
{track_key}
))
}
Load queue
{this.renderLoadQueue()}
);
}
}
const mapStateToProps = (state) => {
const {
core: {
items,
},
ui: {
notifications,
processes,
slim_mode,
test_mode,
selected_tracks,
load_queue,
},
mopidy: {
enqueue_uris_batches,
},
} = state;
return {
items,
notifications,
processes,
slim_mode,
test_mode,
selected_tracks,
enqueue_uris_batches,
load_queue,
};
};
const mapDispatchToProps = (dispatch) => ({
uiActions: bindActionCreators(uiActions, dispatch),
});
export default connect(mapStateToProps, mapDispatchToProps)(DebugInfo);