Redux changes and refactoring
This commit is contained in:
102
src/App.js
102
src/App.js
@@ -15,6 +15,7 @@ import ReleaseVersionDisplay from './components/ReleaseVersionDisplay/ReleaseVer
|
||||
import Text from './components/UI/Text/Text';
|
||||
import UpgradeIcon from './components/UpgradeIcon/UpgradeIcon';
|
||||
import UpgradeUI from './components/UpgradeUI/UpgradeUI';
|
||||
import {setProviderState} from './redux/actions/mount_actions';
|
||||
import {detectUIUpgrade, loadReleases, setActiveRelease, setDismissUIUpgrade, setReleaseUpgradeAvailable} from './redux/actions/release_version_actions';
|
||||
|
||||
const Constants = require('./constants');
|
||||
@@ -24,14 +25,6 @@ class App extends IPCContainer {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
this.state[provider] = {
|
||||
AutoMount: false,
|
||||
AutoRestart: false,
|
||||
MountLocation: '',
|
||||
}
|
||||
}
|
||||
|
||||
this.setRequestHandler(Constants.IPC_Check_Installed_Reply, this.onCheckInstalledReply);
|
||||
this.setRequestHandler(Constants.IPC_Download_File_Complete, this.onDownloadFileComplete);
|
||||
this.setRequestHandler(Constants.IPC_Download_File_Progress, this.onDownloadFileProgress);
|
||||
@@ -104,6 +97,10 @@ class App extends IPCContainer {
|
||||
(prevProps.VersionLookup !== this.props.VersionLookup)) {
|
||||
this.saveState();
|
||||
this.checkVersionInstalled();
|
||||
} else if (Object.keys(this.props.ProviderState).filter(k=> {
|
||||
return this.props.ProviderState[k] !== prevProps.ProviderState[k];
|
||||
}).length > 0) {
|
||||
this.saveState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +128,9 @@ class App extends IPCContainer {
|
||||
};
|
||||
|
||||
getSelectedVersion = () => {
|
||||
return this.props.VersionLookup[Constants.RELEASE_TYPES[this.props.Release]][this.props.ReleaseVersion];
|
||||
return (this.props.ReleaseVersion === -1) ?
|
||||
'unavailable' :
|
||||
this.props.VersionLookup[Constants.RELEASE_TYPES[this.props.Release]][this.props.ReleaseVersion];
|
||||
};
|
||||
|
||||
detectUpgrades = () => {
|
||||
@@ -141,30 +140,6 @@ class App extends IPCContainer {
|
||||
}
|
||||
};
|
||||
|
||||
handleAutoMountChanged = (storageType, e) => {
|
||||
const state = {
|
||||
...this.state[storageType],
|
||||
AutoMount: e.target.checked,
|
||||
};
|
||||
this.setState({
|
||||
[storageType]: state,
|
||||
}, ()=> {
|
||||
this.saveState();
|
||||
});
|
||||
};
|
||||
|
||||
handleAutoRestartChanged = (storageType, e) => {
|
||||
const state = {
|
||||
...this.state[storageType],
|
||||
AutoRestart: e.target.checked,
|
||||
};
|
||||
this.setState({
|
||||
[storageType]: state,
|
||||
}, ()=> {
|
||||
this.saveState();
|
||||
});
|
||||
};
|
||||
|
||||
handleDependencyDownload = (url) => {
|
||||
this.setState({
|
||||
DownloadActive: true,
|
||||
@@ -178,24 +153,6 @@ class App extends IPCContainer {
|
||||
});
|
||||
};
|
||||
|
||||
handleMountLocationChanged = (storageType, location) => {
|
||||
const state = {
|
||||
...this.state[storageType],
|
||||
MountLocation: location,
|
||||
};
|
||||
this.setState({
|
||||
[storageType]: state,
|
||||
}, ()=> {
|
||||
this.saveState();
|
||||
});
|
||||
};
|
||||
|
||||
handleReleaseChanged = (e) => {
|
||||
const release = parseInt(e.target.value, 10);
|
||||
const releaseVersion = this.props.VersionLookup[Constants.RELEASE_TYPES[release]].length - 1;
|
||||
this.props.setActiveRelease(release, releaseVersion);
|
||||
};
|
||||
|
||||
handleReleaseDownload = () => {
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
const fileName = selectedVersion + '.zip';
|
||||
@@ -225,10 +182,6 @@ class App extends IPCContainer {
|
||||
});
|
||||
};
|
||||
|
||||
handleVersionChanged = (e) => {
|
||||
this.props.setActiveRelease(this.props.Release, parseInt(e.target.value, 10));
|
||||
};
|
||||
|
||||
installDependency = data => {
|
||||
if (data.Success) {
|
||||
this.sendRequest(Constants.IPC_Install_Dependency, {
|
||||
@@ -335,24 +288,19 @@ class App extends IPCContainer {
|
||||
if (arg.data) {
|
||||
this.props.setActiveRelease(arg.data.Release, arg.data.Version);
|
||||
|
||||
let state = {};
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
let data = arg.data[provider] || this.state[provider];
|
||||
let data = arg.data[provider] || this.props.ProviderState[provider];
|
||||
if (data.AutoMount === undefined) {
|
||||
data['AutoMount'] = false;
|
||||
}
|
||||
if (data.AutoRestart === undefined) {
|
||||
data['AutoRestart'] = false;
|
||||
}
|
||||
state[provider] = data;
|
||||
this.props.setProviderState(provider, data);
|
||||
}
|
||||
|
||||
this.setState(state, ()=> {
|
||||
this.detectUpgrades();
|
||||
});
|
||||
} else {
|
||||
this.detectUpgrades();
|
||||
}
|
||||
|
||||
this.detectUpgrades();
|
||||
};
|
||||
|
||||
onInstallDependencyReply = (event, arg) => {
|
||||
@@ -399,9 +347,10 @@ class App extends IPCContainer {
|
||||
};
|
||||
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
state[provider] = this.state[provider];
|
||||
state[provider] = this.props.ProviderState[provider];
|
||||
}
|
||||
|
||||
console.log(state);
|
||||
this.sendRequest(Constants.IPC_Save_State, {
|
||||
State: state
|
||||
});
|
||||
@@ -444,9 +393,7 @@ class App extends IPCContainer {
|
||||
};
|
||||
|
||||
render() {
|
||||
const selectedVersion = (this.props.ReleaseVersion === -1) ?
|
||||
'unavailable' :
|
||||
this.getSelectedVersion();
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
|
||||
const downloadEnabled = this.state.AllowDownload &&
|
||||
!this.props.MountsBusy &&
|
||||
@@ -540,29 +487,20 @@ class App extends IPCContainer {
|
||||
<ReleaseVersionDisplay disabled={this.state.DownloadActive || this.state.ExtractActive || this.props.MountsBusy}
|
||||
downloadClicked={this.handleReleaseDownload}
|
||||
downloadDisabled={!downloadEnabled}
|
||||
releaseChanged={this.handleReleaseChanged}
|
||||
releaseExtracting={this.state.ExtractActive}
|
||||
text={this.state.InstalledVersion + ' [' + this.props.AppPlatform + ']'}
|
||||
versionChanged={this.handleVersionChanged}/>
|
||||
saveState={this.saveState}
|
||||
text={this.state.InstalledVersion + ' [' + this.props.AppPlatform + ']'}/>
|
||||
</div>
|
||||
));
|
||||
|
||||
if (allowMount) {
|
||||
let providerProps = {};
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
const providerLower = provider.toLowerCase();
|
||||
providerProps[providerLower] = this.state[provider];
|
||||
}
|
||||
mainContent.push((
|
||||
<div key={'md_' + key++}>
|
||||
<MountItems {...providerProps}
|
||||
allowConfig={allowConfig}
|
||||
<MountItems allowConfig={allowConfig}
|
||||
allowSiaPrime={allowSiaPrime}
|
||||
noConsoleSupported={noConsoleSupported}
|
||||
autoMountChanged={this.handleAutoMountChanged}
|
||||
autoRestartChanged={this.handleAutoRestartChanged}
|
||||
changed={this.handleMountLocationChanged}
|
||||
errorHandler={this.setErrorState}
|
||||
saveState={this.saveState}
|
||||
version={this.state.InstalledVersion}/>
|
||||
</div>
|
||||
));
|
||||
@@ -618,6 +556,7 @@ const mapStateToProps = state => {
|
||||
LocationsLookup: state.relver.LocationsLookup,
|
||||
MountsBusy: state.mounts.MountsBusy,
|
||||
Platform: state.common.Platform,
|
||||
ProviderState: state.mounts.ProviderState,
|
||||
Release: state.relver.Release,
|
||||
ReleaseVersion: state.relver.Version,
|
||||
UpgradeAvailable: state.relver.UpgradeAvailable,
|
||||
@@ -634,6 +573,7 @@ const mapDispatchToProps = dispatch => {
|
||||
loadReleases: ()=> dispatch(loadReleases()),
|
||||
setActiveRelease: (release, version) => dispatch(setActiveRelease(release, version)),
|
||||
setDismissUIUpgrade: dismiss => dispatch(setDismissUIUpgrade(dismiss)),
|
||||
setProviderState: (provider, state) => dispatch(setProviderState(provider, state)),
|
||||
setReleaseUpgradeAvailable: available => dispatch(setReleaseUpgradeAvailable(available)),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user