1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/packages/app-mobile/components/screens/status.js

157 lines
3.8 KiB
JavaScript
Raw Normal View History

2019-07-29 15:43:53 +02:00
const React = require('react');
2019-07-29 15:58:33 +02:00
const { View, Text, Button, FlatList } = require('react-native');
const Setting = require('@joplin/lib/models/Setting').default;
const { connect } = require('react-redux');
2020-11-05 18:58:23 +02:00
const { ScreenHeader } = require('../screen-header.js');
const { ReportService } = require('@joplin/lib/services/report.js');
const { _ } = require('@joplin/lib/locale');
2020-11-05 18:58:23 +02:00
const { BaseScreenComponent } = require('../base-screen.js');
const { themeStyle } = require('../global-style.js');
2017-07-10 21:16:59 +02:00
2017-07-14 20:49:14 +02:00
class StatusScreenComponent extends BaseScreenComponent {
static navigationOptions() {
2017-07-10 21:16:59 +02:00
return { header: null };
}
constructor() {
super();
this.state = {
2017-07-13 20:09:47 +02:00
report: [],
2017-07-10 21:16:59 +02:00
};
}
UNSAFE_componentWillMount() {
2017-07-10 21:16:59 +02:00
this.resfreshScreen();
}
2017-07-13 00:32:08 +02:00
async resfreshScreen() {
const service = new ReportService();
const report = await service.status(Setting.value('sync.target'));
2017-07-13 20:09:47 +02:00
this.setState({ report: report });
2017-07-13 00:32:08 +02:00
}
styles() {
2020-09-15 15:01:07 +02:00
const theme = themeStyle(this.props.themeId);
return {
body: {
flex: 1,
margin: theme.margin,
},
};
}
2017-07-13 00:32:08 +02:00
render() {
2020-09-15 15:01:07 +02:00
const theme = themeStyle(this.props.themeId);
2017-08-01 19:59:01 +02:00
const renderBody = report => {
const baseStyle = {
2017-07-13 20:09:47 +02:00
paddingLeft: 6,
paddingRight: 6,
2017-08-01 20:59:10 +02:00
paddingTop: 2,
paddingBottom: 2,
2017-07-13 20:09:47 +02:00
flex: 0,
2017-08-01 19:59:01 +02:00
color: theme.color,
fontSize: theme.fontSize,
2017-07-13 20:09:47 +02:00
};
2017-08-01 20:59:10 +02:00
const lines = [];
2017-08-01 20:59:10 +02:00
2017-07-13 20:09:47 +02:00
for (let i = 0; i < report.length; i++) {
const section = report[i];
2017-07-13 20:09:47 +02:00
let style = Object.assign({}, baseStyle);
style.fontWeight = 'bold';
2017-07-13 20:09:47 +02:00
if (i > 0) style.paddingTop = 20;
2019-09-19 23:51:18 +02:00
lines.push({ key: `section_${i}`, isSection: true, text: section.title });
Desktop: Resolves #2688: Add "Retry All" option to synchronisation page Based on pull request #2712 by fhfuih commit 7d3815e51dbf682ecc1ed3544a15e51b79d5d12d Author: Laurent Cozic <laurent@cozic.net> Date: Sat Apr 4 18:26:01 2020 +0100 Fix issues commit dad1d2c4d4eb37fdd23096a3344cf4f14498e335 Merge: 16cf0a3058 0a1ba511ea Author: Laurent Cozic <laurent@cozic.net> Date: Sat Apr 4 18:09:46 2020 +0100 Merge branch 'master' of https://github.com/fhfuih/joplin into fhfuih-master commit 0a1ba511ea4cb04a20a1334dbc45a9ad6ad15300 Merge: 6207b42044 bdd760f343 Author: fhfuih <fhfuih@outlook.com> Date: Sat Mar 14 20:30:27 2020 -0400 Merge branch 'master' into master commit 6207b42044127b49fdd879217fc080fa11fb686b Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:13:28 2020 -0400 Decryption Retry All RN frontend commit 6f46d1985f580ce4b1428c0a2ce16800b696ce1d Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:10:55 2020 -0400 Decryption Retry All backend & desktop commit 4c3d37b311991dcbb76e984c299d5c5517bd2437 Author: fhfuih <sam.zyhuang@outlook.com> Date: Fri Mar 13 13:21:21 2020 -0400 Revert "Add "retry all" option to synchronisation page" This reverts commit 15daaa16fdb961003af78d54a083a3a35c79d7b3. commit cffc919791f86dd980bf326c913c4931c3261eca Author: fhfuih <sam.zyhuang@outlook.com> Date: Fri Mar 13 13:19:51 2020 -0400 Revert "Refactor "retry all" renderer to avoid hacks" This reverts commit 51ba6ea65521c8bfa953d90f8078684d8293122b. commit 51ba6ea65521c8bfa953d90f8078684d8293122b Author: fhfuih <sam.zyhuang@outlook.com> Date: Tue Mar 10 18:27:22 2020 -0400 Refactor "retry all" renderer to avoid hacks commit 57d71712e1718d9bdb18bc2b5fdaea94211a01e8 Merge: 15daaa16fd b367955e56 Author: fhfuih <sam.zyhuang@outlook.com> Date: Mon Mar 9 20:42:02 2020 -0400 Merge branch 'master' of https://github.com/fhfuih/joplin commit 15daaa16fdb961003af78d54a083a3a35c79d7b3 Author: fhfuih <sam.zyhuang@outlook.com> Date: Mon Mar 9 20:36:09 2020 -0400 Add "retry all" option to synchronisation page
2020-04-04 19:30:13 +02:00
if (section.canRetryAll) {
lines.push({ key: `retry_all_${i}`, text: '', retryAllHandler: section.retryAllHandler });
}
2017-07-13 20:09:47 +02:00
for (const n in section.body) {
2017-07-13 20:09:47 +02:00
if (!section.body.hasOwnProperty(n)) continue;
style = Object.assign({}, baseStyle);
const item = section.body[n];
let text = '';
let retryHandler = null;
if (typeof item === 'object') {
if (item.canRetry) {
retryHandler = async () => {
await item.retryHandler();
this.resfreshScreen();
2019-07-29 15:43:53 +02:00
};
}
text = item.text;
} else {
text = item;
}
2019-09-19 23:51:18 +02:00
lines.push({ key: `item_${i}_${n}`, text: text, retryHandler: retryHandler });
2017-07-13 20:09:47 +02:00
}
2017-08-01 20:59:10 +02:00
2019-09-19 23:51:18 +02:00
lines.push({ key: `divider2_${i}`, isDivider: true });
2017-07-13 20:09:47 +02:00
}
2019-07-29 15:43:53 +02:00
return (
<FlatList
data={lines}
renderItem={({ item }) => {
const style = Object.assign({}, baseStyle);
2019-07-29 15:43:53 +02:00
if (item.isSection === true) {
style.fontWeight = 'bold';
style.marginBottom = 5;
}
2019-07-29 15:43:53 +02:00
style.flex = 1;
Desktop: Resolves #2688: Add "Retry All" option to synchronisation page Based on pull request #2712 by fhfuih commit 7d3815e51dbf682ecc1ed3544a15e51b79d5d12d Author: Laurent Cozic <laurent@cozic.net> Date: Sat Apr 4 18:26:01 2020 +0100 Fix issues commit dad1d2c4d4eb37fdd23096a3344cf4f14498e335 Merge: 16cf0a3058 0a1ba511ea Author: Laurent Cozic <laurent@cozic.net> Date: Sat Apr 4 18:09:46 2020 +0100 Merge branch 'master' of https://github.com/fhfuih/joplin into fhfuih-master commit 0a1ba511ea4cb04a20a1334dbc45a9ad6ad15300 Merge: 6207b42044 bdd760f343 Author: fhfuih <fhfuih@outlook.com> Date: Sat Mar 14 20:30:27 2020 -0400 Merge branch 'master' into master commit 6207b42044127b49fdd879217fc080fa11fb686b Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:13:28 2020 -0400 Decryption Retry All RN frontend commit 6f46d1985f580ce4b1428c0a2ce16800b696ce1d Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:10:55 2020 -0400 Decryption Retry All backend & desktop commit 4c3d37b311991dcbb76e984c299d5c5517bd2437 Author: fhfuih <sam.zyhuang@outlook.com> Date: Fri Mar 13 13:21:21 2020 -0400 Revert "Add "retry all" option to synchronisation page" This reverts commit 15daaa16fdb961003af78d54a083a3a35c79d7b3. commit cffc919791f86dd980bf326c913c4931c3261eca Author: fhfuih <sam.zyhuang@outlook.com> Date: Fri Mar 13 13:19:51 2020 -0400 Revert "Refactor "retry all" renderer to avoid hacks" This reverts commit 51ba6ea65521c8bfa953d90f8078684d8293122b. commit 51ba6ea65521c8bfa953d90f8078684d8293122b Author: fhfuih <sam.zyhuang@outlook.com> Date: Tue Mar 10 18:27:22 2020 -0400 Refactor "retry all" renderer to avoid hacks commit 57d71712e1718d9bdb18bc2b5fdaea94211a01e8 Merge: 15daaa16fd b367955e56 Author: fhfuih <sam.zyhuang@outlook.com> Date: Mon Mar 9 20:42:02 2020 -0400 Merge branch 'master' of https://github.com/fhfuih/joplin commit 15daaa16fdb961003af78d54a083a3a35c79d7b3 Author: fhfuih <sam.zyhuang@outlook.com> Date: Mon Mar 9 20:36:09 2020 -0400 Add "retry all" option to synchronisation page
2020-04-04 19:30:13 +02:00
const retryAllButton = item.retryAllHandler ? (
<View style={{ flex: 0 }}>
<Button title={_('Retry All')} onPress={item.retryAllHandler} />
</View>
) : null;
2019-07-29 15:43:53 +02:00
const retryButton = item.retryHandler ? (
<View style={{ flex: 0 }}>
<Button title={_('Retry')} onPress={item.retryHandler} />
</View>
2019-07-29 15:43:53 +02:00
) : null;
if (item.isDivider) {
return <View style={{ borderBottomWidth: 1, borderBottomColor: theme.dividerColor, marginTop: 20, marginBottom: 20 }} />;
} else {
return (
<View style={{ flex: 1, flexDirection: 'row' }}>
<Text style={style}>{item.text}</Text>
Desktop: Resolves #2688: Add "Retry All" option to synchronisation page Based on pull request #2712 by fhfuih commit 7d3815e51dbf682ecc1ed3544a15e51b79d5d12d Author: Laurent Cozic <laurent@cozic.net> Date: Sat Apr 4 18:26:01 2020 +0100 Fix issues commit dad1d2c4d4eb37fdd23096a3344cf4f14498e335 Merge: 16cf0a3058 0a1ba511ea Author: Laurent Cozic <laurent@cozic.net> Date: Sat Apr 4 18:09:46 2020 +0100 Merge branch 'master' of https://github.com/fhfuih/joplin into fhfuih-master commit 0a1ba511ea4cb04a20a1334dbc45a9ad6ad15300 Merge: 6207b42044 bdd760f343 Author: fhfuih <fhfuih@outlook.com> Date: Sat Mar 14 20:30:27 2020 -0400 Merge branch 'master' into master commit 6207b42044127b49fdd879217fc080fa11fb686b Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:13:28 2020 -0400 Decryption Retry All RN frontend commit 6f46d1985f580ce4b1428c0a2ce16800b696ce1d Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:10:55 2020 -0400 Decryption Retry All backend & desktop commit 4c3d37b311991dcbb76e984c299d5c5517bd2437 Author: fhfuih <sam.zyhuang@outlook.com> Date: Fri Mar 13 13:21:21 2020 -0400 Revert "Add "retry all" option to synchronisation page" This reverts commit 15daaa16fdb961003af78d54a083a3a35c79d7b3. commit cffc919791f86dd980bf326c913c4931c3261eca Author: fhfuih <sam.zyhuang@outlook.com> Date: Fri Mar 13 13:19:51 2020 -0400 Revert "Refactor "retry all" renderer to avoid hacks" This reverts commit 51ba6ea65521c8bfa953d90f8078684d8293122b. commit 51ba6ea65521c8bfa953d90f8078684d8293122b Author: fhfuih <sam.zyhuang@outlook.com> Date: Tue Mar 10 18:27:22 2020 -0400 Refactor "retry all" renderer to avoid hacks commit 57d71712e1718d9bdb18bc2b5fdaea94211a01e8 Merge: 15daaa16fd b367955e56 Author: fhfuih <sam.zyhuang@outlook.com> Date: Mon Mar 9 20:42:02 2020 -0400 Merge branch 'master' of https://github.com/fhfuih/joplin commit 15daaa16fdb961003af78d54a083a3a35c79d7b3 Author: fhfuih <sam.zyhuang@outlook.com> Date: Mon Mar 9 20:36:09 2020 -0400 Add "retry all" option to synchronisation page
2020-04-04 19:30:13 +02:00
{retryAllButton}
2019-07-29 15:43:53 +02:00
{retryButton}
</View>
);
}
}}
/>
);
};
2017-07-13 20:09:47 +02:00
const body = renderBody(this.state.report);
2017-07-10 21:16:59 +02:00
return (
2020-09-15 15:01:07 +02:00
<View style={this.rootStyle(this.props.themeId).root}>
2019-07-29 15:43:53 +02:00
<ScreenHeader title={_('Status')} />
<View style={this.styles().body}>{body}</View>
2019-07-29 15:43:53 +02:00
<Button title={_('Refresh')} onPress={() => this.resfreshScreen()} />
2017-07-10 21:16:59 +02:00
</View>
);
}
}
const StatusScreen = connect(state => {
2019-07-29 15:43:53 +02:00
return {
2020-09-15 15:01:07 +02:00
themeId: state.settings.theme,
2019-07-29 15:43:53 +02:00
};
})(StatusScreenComponent);
2017-07-10 21:16:59 +02:00
2019-07-29 15:43:53 +02:00
module.exports = { StatusScreen };