Files
Iris/src/js/components/DebugInfo.js

178 lines
4.7 KiB
JavaScript
Raw Normal View History

2019-09-05 15:36:11 +12:00
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';
2019-09-05 15:36:11 +12:00
import * as uiActions from '../services/ui/actions';
2020-03-13 16:41:44 +13:00
import { indexToArray } from '../util/arrays';
import { decodeUri } from '../util/format';
2019-09-05 15:36:11 +12:00
class DebugInfo extends React.Component {
constructor(props) {
super(props);
2021-03-23 21:21:00 +13:00
this.state = { localForageLength: 0 };
}
2021-03-23 21:21:00 +13:00
componentDidMount() {
2021-03-23 21:21:00 +13:00
localForage.length().then((localForageLength) => this.setState({ localForageLength }));
}
2021-03-23 21:21:00 +13:00
2019-09-05 15:36:11 +12:00
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 <div className="debug-info-item mid_grey-text">Nothing loading</div>;
2019-09-05 15:36:11 +12:00
const queue = indexToArray(load_queue);
2019-09-05 15:36:11 +12:00
if (queue.length > 0) {
return (
<div className="debug-info-item">
{queue.map((item, index) => (<div key={`${item}_${index}`}>{item}</div>))}
2019-09-05 15:36:11 +12:00
</div>
);
}
return <div className="debug-info-item mid_grey-text">Nothing loading</div>;
2019-09-05 15:36:11 +12:00
}
render = () => {
2019-09-05 15:36:11 +12:00
const localStorageUsage = this.localStorageSize();
const {
items = {},
notifications = {},
processes = {},
slim_mode,
test_mode,
selected_tracks = [],
enqueue_uris_batches = [],
} = this.props;
2019-09-05 15:36:11 +12:00
return (
<div className="debug-info">
<div className="debug-info-section">
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
Version:
{' '}
2019-09-05 15:36:11 +12:00
{version}
</div>
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
Build:
{' '}
2019-09-05 15:36:11 +12:00
{build}
</div>
</div>
<div className="debug-info-section">
<h5>State</h5>
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
{`Items: ${Object.keys(items).length}`}
2019-09-05 15:36:11 +12:00
</div>
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
{`Coldstore items: ${this.state.localForageLength}`}
2019-09-05 15:36:11 +12:00
</div>
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
{`Notifications: ${Object.keys(notifications).length}`}
2019-09-05 15:36:11 +12:00
</div>
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
{`Processes: ${Object.keys(processes).length}`}
2019-09-05 15:36:11 +12:00
</div>
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
{`Enqueue batches: ${enqueue_uris_batches.length}`}
2019-09-05 15:36:11 +12:00
</div>
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
{`Cached URLs: ${Object.keys(getStorage('cache')).length}`}
</div>
2019-09-05 15:36:11 +12:00
</div>
<div className="debug-info-section">
<h5>Config</h5>
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
{`Slim mode: ${slim_mode ? 'on' : 'off'}`}
2019-09-05 15:36:11 +12:00
</div>
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
{`Test mode: ${test_mode ? 'on' : 'off'}`}
2019-09-05 15:36:11 +12:00
</div>
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
{`Touch: ${isTouchDevice() ? 'on' : 'off'}`}
2019-09-05 15:36:11 +12:00
</div>
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
{`LocalStorage usage: ${localStorageUsage.used}kb (~${localStorageUsage.percent}%)`}
2019-09-05 15:36:11 +12:00
</div>
<div className="debug-info-item">
2021-03-23 21:21:00 +13:00
{`Selected tracks: ${selected_tracks.length}`}
2019-09-05 15:36:11 +12:00
<br />
{
selected_tracks.map((track_key, index) => (
2021-03-23 21:21:00 +13:00
<div key={`${track_key}_${index}`}>{track_key}</div>
2019-09-05 15:36:11 +12:00
))
}
2019-09-05 15:36:11 +12:00
</div>
</div>
2019-09-05 15:36:11 +12:00
<div className="debug-info-section">
<h5>Load queue</h5>
{this.renderLoadQueue()}
2019-09-05 15:36:11 +12:00
</div>
2019-09-05 15:36:11 +12:00
</div>
);
}
2017-01-29 12:54:06 +13:00
}
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,
};
};
2017-01-29 12:54:06 +13:00
2019-09-05 15:36:11 +12:00
const mapDispatchToProps = (dispatch) => ({
uiActions: bindActionCreators(uiActions, dispatch),
});
2017-01-29 12:54:06 +13:00
export default connect(mapStateToProps, mapDispatchToProps)(DebugInfo);