2024-04-08 13:35:57 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
import { View, Text, Button, FlatList, TextStyle, StyleSheet } from 'react-native';
|
|
|
|
import Setting from '@joplin/lib/models/Setting';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { ScreenHeader } from '../ScreenHeader';
|
|
|
|
import ReportService, { ReportSection } from '@joplin/lib/services/ReportService';
|
|
|
|
import { _ } from '@joplin/lib/locale';
|
|
|
|
import { BaseScreenComponent } from '../base-screen';
|
|
|
|
import { themeStyle } from '../global-style';
|
|
|
|
import { AppState } from '../../utils/types';
|
|
|
|
import checkDisabledSyncItemsNotification from '@joplin/lib/services/synchronizer/utils/checkDisabledSyncItemsNotification';
|
|
|
|
import { Dispatch } from 'redux';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
themeId: number;
|
|
|
|
dispatch: Dispatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
report: ReportSection[];
|
|
|
|
}
|
2017-07-10 21:16:59 +02:00
|
|
|
|
2024-04-08 13:35:57 +02:00
|
|
|
class StatusScreenComponent extends BaseScreenComponent<Props, State> {
|
|
|
|
public constructor(props: Props) {
|
|
|
|
super(props);
|
2017-07-10 21:16:59 +02:00
|
|
|
this.state = {
|
2017-07-13 20:09:47 +02:00
|
|
|
report: [],
|
2017-07-10 21:16:59 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-04-08 13:35:57 +02:00
|
|
|
public override componentDidMount() {
|
|
|
|
void this.refreshScreen();
|
2017-07-10 21:16:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-08 13:35:57 +02:00
|
|
|
private async refreshScreen() {
|
2020-03-14 01:46:14 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-04-08 13:35:57 +02:00
|
|
|
private styles() {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2024-04-08 13:35:57 +02:00
|
|
|
return StyleSheet.create({
|
2020-06-10 23:08:59 +02:00
|
|
|
body: {
|
|
|
|
flex: 1,
|
|
|
|
margin: theme.margin,
|
|
|
|
},
|
2024-04-08 13:35:57 +02:00
|
|
|
actionButton: {
|
|
|
|
flex: 0,
|
|
|
|
marginLeft: 2,
|
|
|
|
marginRight: 2,
|
|
|
|
},
|
|
|
|
});
|
2020-06-10 23:08:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-08 13:35:57 +02:00
|
|
|
public override render() {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2024-04-08 13:35:57 +02:00
|
|
|
const styles = this.styles();
|
2017-08-01 19:59:01 +02:00
|
|
|
|
2024-04-08 13:35:57 +02:00
|
|
|
const renderBody = (report: ReportSection[]) => {
|
2020-03-14 01:46:14 +02:00
|
|
|
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
|
|
|
|
2020-03-14 01:46:14 +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++) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const section = report[i];
|
2017-07-13 20:09:47 +02:00
|
|
|
|
2024-04-08 13:35:57 +02:00
|
|
|
let style: TextStyle = { ...baseStyle };
|
2018-03-09 22:59:12 +02:00
|
|
|
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 });
|
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
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
for (const n in section.body) {
|
2017-07-13 20:09:47 +02:00
|
|
|
if (!section.body.hasOwnProperty(n)) continue;
|
2023-06-01 13:02:36 +02:00
|
|
|
style = { ...baseStyle };
|
2019-06-08 00:11:08 +02:00
|
|
|
const item = section.body[n];
|
|
|
|
|
|
|
|
let text = '';
|
|
|
|
|
|
|
|
let retryHandler = null;
|
2024-04-08 13:35:57 +02:00
|
|
|
let ignoreHandler = null;
|
2019-06-08 00:11:08 +02:00
|
|
|
if (typeof item === 'object') {
|
|
|
|
if (item.canRetry) {
|
|
|
|
retryHandler = async () => {
|
|
|
|
await item.retryHandler();
|
2024-04-08 13:35:57 +02:00
|
|
|
await this.refreshScreen();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (item.canIgnore) {
|
|
|
|
ignoreHandler = async () => {
|
|
|
|
await item.ignoreHandler();
|
|
|
|
await this.refreshScreen();
|
|
|
|
await checkDisabledSyncItemsNotification((action) => this.props.dispatch(action));
|
2019-07-29 15:43:53 +02:00
|
|
|
};
|
2019-06-08 00:11:08 +02:00
|
|
|
}
|
|
|
|
text = item.text;
|
|
|
|
} else {
|
|
|
|
text = item;
|
|
|
|
}
|
|
|
|
|
2024-04-08 13:35:57 +02:00
|
|
|
lines.push({ key: `item_${i}_${n}`, text: text, retryHandler, ignoreHandler });
|
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 }) => {
|
2024-04-08 13:35:57 +02:00
|
|
|
const style: TextStyle = { ...baseStyle };
|
2019-06-08 00:11:08 +02:00
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
if (item.isSection === true) {
|
|
|
|
style.fontWeight = 'bold';
|
|
|
|
style.marginBottom = 5;
|
|
|
|
}
|
2019-06-08 00:11:08 +02:00
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
style.flex = 1;
|
2019-06-08 00:11:08 +02:00
|
|
|
|
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 ? (
|
2024-04-08 13:35:57 +02:00
|
|
|
<View style={styles.actionButton}>
|
2019-07-29 15:43:53 +02:00
|
|
|
<Button title={_('Retry')} onPress={item.retryHandler} />
|
2019-06-08 00:11:08 +02:00
|
|
|
</View>
|
2019-07-29 15:43:53 +02:00
|
|
|
) : null;
|
|
|
|
|
2024-04-08 13:35:57 +02:00
|
|
|
const ignoreButton = item.ignoreHandler ? (
|
|
|
|
<View style={styles.actionButton}>
|
|
|
|
<Button title={_('Ignore')} onPress={item.ignoreHandler} />
|
|
|
|
</View>
|
|
|
|
) : null;
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
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>
|
2024-04-08 13:35:57 +02:00
|
|
|
{ignoreButton}
|
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
|
|
|
|
2020-03-14 01:46:14 +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')} />
|
2024-04-08 13:35:57 +02:00
|
|
|
<View style={styles.body}>{body}</View>
|
|
|
|
<Button title={_('Refresh')} onPress={() => this.refreshScreen()} />
|
2017-07-10 21:16:59 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-08 13:35:57 +02:00
|
|
|
export default connect((state: AppState) => {
|
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);
|