1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Refactor "retry all" renderer to avoid hacks

This commit is contained in:
fhfuih 2020-03-10 18:27:22 -04:00
parent 57d71712e1
commit 51ba6ea655

View File

@ -55,8 +55,6 @@ class StatusScreenComponent extends React.Component {
height: style.height - theme.headerHeight - containerPadding * 2,
});
let retryHandlers = [];
function renderSectionTitleHtml(key, title) {
return (
<h2 key={`section_${key}`} style={theme.h2Style}>
@ -83,8 +81,6 @@ class StatusScreenComponent extends React.Component {
this.resfreshScreen();
};
retryHandlers.push(item.retryHandler);
retryLink = (
<a href="#" onClick={onClick} style={retryStyle}>
{_('Retry')}
@ -109,13 +105,24 @@ class StatusScreenComponent extends React.Component {
return <div key={key}>{itemsHtml}</div>;
};
function renderRetryAllHtml() {
function renderRetryAllHtml(report) {
let retryHandlers = [];
let retryAllLink = null;
report.forEach(section => {
section.body.forEach(item => {
if (item.canRetry) {
retryHandlers.push(item.retryHandler);
}
});
});
if (retryHandlers.length > 1) {
const onClick = async () => {
await Promise.all(retryHandlers.map(handler => handler()));
this.resfreshScreen();
};
retryAllLink = (
<div>
<a href="#" onClick={onClick} style={retryStyle}>
@ -136,7 +143,7 @@ class StatusScreenComponent extends React.Component {
sectionsHtml.push(renderSectionHtml(i, section));
}
let retryAllHtml = renderRetryAllHtml(); // must be called after renderSectionHtml
let retryAllHtml = renderRetryAllHtml(report);
return (
<div>