1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ReactNativeClient/lib/components/screens/status.js
Laurent Cozic f550d847c4 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 0a1ba511ea
Merge: 6207b42044 bdd760f343
Author: fhfuih <fhfuih@outlook.com>
Date:   Sat Mar 14 20:30:27 2020 -0400

    Merge branch 'master' into master

commit 6207b42044
Author: fhfuih <sam.zyhuang@outlook.com>
Date:   Sat Mar 14 20:13:28 2020 -0400

    Decryption Retry All RN frontend

commit 6f46d1985f
Author: fhfuih <sam.zyhuang@outlook.com>
Date:   Sat Mar 14 20:10:55 2020 -0400

    Decryption Retry All backend & desktop

commit 4c3d37b311
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 15daaa16fd.

commit cffc919791
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 51ba6ea655.

commit 51ba6ea655
Author: fhfuih <sam.zyhuang@outlook.com>
Date:   Tue Mar 10 18:27:22 2020 -0400

    Refactor "retry all" renderer to avoid hacks

commit 57d71712e1
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 15daaa16fd
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 18:30:13 +01:00

154 lines
3.8 KiB
JavaScript

const React = require('react');
const { StyleSheet, View, Text, Button, FlatList } = require('react-native');
const Setting = require('lib/models/Setting.js');
const { connect } = require('react-redux');
const { ScreenHeader } = require('lib/components/screen-header.js');
const { ReportService } = require('lib/services/report.js');
const { _ } = require('lib/locale.js');
const { BaseScreenComponent } = require('lib/components/base-screen.js');
const { globalStyle, themeStyle } = require('lib/components/global-style.js');
const styles = StyleSheet.create({
body: {
flex: 1,
margin: globalStyle.margin,
},
});
class StatusScreenComponent extends BaseScreenComponent {
static navigationOptions() {
return { header: null };
}
constructor() {
super();
this.state = {
report: [],
};
}
UNSAFE_componentWillMount() {
this.resfreshScreen();
}
async resfreshScreen() {
const service = new ReportService();
const report = await service.status(Setting.value('sync.target'));
this.setState({ report: report });
}
render() {
const theme = themeStyle(this.props.theme);
const renderBody = report => {
const baseStyle = {
paddingLeft: 6,
paddingRight: 6,
paddingTop: 2,
paddingBottom: 2,
flex: 0,
color: theme.color,
fontSize: theme.fontSize,
};
const lines = [];
for (let i = 0; i < report.length; i++) {
const section = report[i];
let style = Object.assign({}, baseStyle);
style.fontWeight = 'bold';
if (i > 0) style.paddingTop = 20;
lines.push({ key: `section_${i}`, isSection: true, text: section.title });
if (section.canRetryAll) {
lines.push({ key: `retry_all_${i}`, text: '', retryAllHandler: section.retryAllHandler });
}
for (const n in section.body) {
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();
};
}
text = item.text;
} else {
text = item;
}
lines.push({ key: `item_${i}_${n}`, text: text, retryHandler: retryHandler });
}
lines.push({ key: `divider2_${i}`, isDivider: true });
}
return (
<FlatList
data={lines}
renderItem={({ item }) => {
const style = Object.assign({}, baseStyle);
if (item.isSection === true) {
style.fontWeight = 'bold';
style.marginBottom = 5;
}
style.flex = 1;
const retryAllButton = item.retryAllHandler ? (
<View style={{ flex: 0 }}>
<Button title={_('Retry All')} onPress={item.retryAllHandler} />
</View>
) : null;
const retryButton = item.retryHandler ? (
<View style={{ flex: 0 }}>
<Button title={_('Retry')} onPress={item.retryHandler} />
</View>
) : 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>
{retryAllButton}
{retryButton}
</View>
);
}
}}
/>
);
};
const body = renderBody(this.state.report);
return (
<View style={this.rootStyle(this.props.theme).root}>
<ScreenHeader title={_('Status')} />
<View style={styles.body}>{body}</View>
<Button title={_('Refresh')} onPress={() => this.resfreshScreen()} />
</View>
);
}
}
const StatusScreen = connect(state => {
return {
theme: state.settings.theme,
};
})(StatusScreenComponent);
module.exports = { StatusScreen };