joplin/ReactNativeClient/lib/components/screens/status.js

86 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-07-10 19:16:59 +00:00
import React, { Component } from 'react';
import { ListView, View, Text, Button } from 'react-native';
import { connect } from 'react-redux'
import { Log } from 'lib/log.js'
import { reg } from 'lib/registry.js'
import { ScreenHeader } from 'lib/components/screen-header.js';
import { time } from 'lib/time-utils'
import { Logger } from 'lib/logger.js';
import { BaseItem } from 'lib/models/base-item.js';
2017-07-12 22:32:08 +00:00
import { Folder } from 'lib/models/folder.js';
2017-07-13 18:09:47 +00:00
import { ReportService } from 'lib/services/report.js';
2017-07-10 19:16:59 +00:00
import { _ } from 'lib/locale.js';
class StatusScreenComponent extends React.Component {
static navigationOptions(options) {
return { header: null };
}
constructor() {
super();
this.state = {
2017-07-13 18:09:47 +00:00
report: [],
2017-07-10 19:16:59 +00:00
};
}
componentWillMount() {
this.resfreshScreen();
}
2017-07-12 22:32:08 +00:00
async resfreshScreen() {
2017-07-13 18:09:47 +00:00
let service = new ReportService();
let report = await service.status();
this.setState({ report: report });
2017-07-12 22:32:08 +00:00
}
render() {
2017-07-13 18:09:47 +00:00
function renderBody(report) {
let output = [];
let baseStyle = {
paddingLeft: 6,
paddingRight: 6,
paddingTop: 0,
paddingBottom: 0,
flex: 0,
};
for (let i = 0; i < report.length; i++) {
let section = report[i];
let style = Object.assign({}, baseStyle);
style.fontWeight = 'bold';
if (i > 0) style.paddingTop = 20;
output.push(<Text key={'sectiontitle_' + i} style={style}>{section.title}</Text>);
for (let n in section.body) {
if (!section.body.hasOwnProperty(n)) continue;
style = Object.assign({}, baseStyle);
output.push(<Text key={'line_' + i + '_' + n} style={style}>{section.body[n]}</Text>);
}
}
return output;
}
let body = renderBody(this.state.report);
2017-07-10 19:16:59 +00:00
return (
<View style={{flex: 1}}>
<ScreenHeader navState={this.props.navigation.state} />
2017-07-13 18:09:47 +00:00
<View style={{flex: 1}}>
{ body }
</View>
2017-07-10 19:16:59 +00:00
<Button title="Refresh" onPress={() => this.resfreshScreen()}/>
</View>
);
}
}
const StatusScreen = connect(
(state) => {
return {};
}
)(StatusScreenComponent)
export { StatusScreen };