Refactoring

This commit is contained in:
Scott E. Graves
2019-06-10 11:29:55 -05:00
parent 8eea53c0b0
commit 32b8508a51

View File

@@ -25,8 +25,7 @@ import {
checkInstalled, checkInstalled,
installDependency, installDependency,
installRelease, installRelease,
installUpgrade, installUpgrade
setMissingDependencies
} from './redux/actions/install_actions'; } from './redux/actions/install_actions';
import { import {
detectUIUpgrade, detectUIUpgrade,
@@ -78,6 +77,11 @@ class App extends Component {
Scheduler.cancelJob(this.scheduledUpdateJob); Scheduler.cancelJob(this.scheduledUpdateJob);
} }
createModalConditionally = (condition, jsx, critical) => {
const modalProps = {critical: critical};
return condition ? (<Modal {...modalProps}>{jsx}</Modal>) : null;
};
detectUpgrades = () => { detectUpgrades = () => {
if (this.props.AppPlatform !== 'unknown') { if (this.props.AppPlatform !== 'unknown') {
this.props.loadReleases(); this.props.loadReleases();
@@ -263,50 +267,11 @@ class App extends Component {
missingDependencies && missingDependencies &&
!this.props.DownloadActive; !this.props.DownloadActive;
let errorDisplay = null; const configDisplay = this.createModalConditionally(showConfig, <Configuration version={selectedVersion} />);
if (this.props.DisplayError) { const dependencyDisplay = this.createModalConditionally(showDependencies, <DependencyList onDownload={this.handleDownloadDependency}/>);
errorDisplay = ( const downloadDisplay = this.createModalConditionally(this.props.DownloadActive, <DownloadProgress/>);
<Modal critical> const errorDisplay = this.createModalConditionally(this.props.DisplayError, <ErrorDetails/>, true);
<ErrorDetails/> const upgradeDisplay = this.createModalConditionally(showUpgrade, <UpgradeUI upgrade={this.handleDownloadUpgrade}/>);
</Modal>
);
}
let configDisplay = null;
if (showConfig) {
configDisplay = (
<Modal>
<Configuration version={selectedVersion} />
</Modal>
);
}
let dependencyDisplay = null;
if (showDependencies) {
dependencyDisplay = (
<Modal>
<DependencyList onDownload={this.handleDownloadDependency}/>
</Modal>
);
}
let downloadDisplay = null;
if (this.props.DownloadActive) {
downloadDisplay = (
<Modal>
<DownloadProgress/>
</Modal>
);
}
let upgradeDisplay = null;
if (showUpgrade) {
upgradeDisplay = (
<Modal>
<UpgradeUI upgrade={this.handleDownloadUpgrade}/>
</Modal>
);
}
let mainContent = []; let mainContent = [];
if (this.props.AppReady) { if (this.props.AppReady) {
@@ -412,7 +377,6 @@ const mapDispatchToProps = dispatch => {
setAllowDownload: allow => dispatch(setAllowDownload(allow)), setAllowDownload: allow => dispatch(setAllowDownload(allow)),
setDismissUIUpgrade: dismiss => dispatch(setDismissUIUpgrade(dismiss)), setDismissUIUpgrade: dismiss => dispatch(setDismissUIUpgrade(dismiss)),
setInstalledVersion: version => dispatch(setInstalledVersion(version)), setInstalledVersion: version => dispatch(setInstalledVersion(version)),
setMissingDependencies: dependencies => dispatch(setMissingDependencies(dependencies)),
setProviderState: (provider, state) => dispatch(setProviderState(provider, state)), setProviderState: (provider, state) => dispatch(setProviderState(provider, state)),
setReleaseUpgradeAvailable: available => dispatch(setReleaseUpgradeAvailable(available)), setReleaseUpgradeAvailable: available => dispatch(setReleaseUpgradeAvailable(available)),
}; };