Use callback during setState()
This commit is contained in:
63
src/App.js
63
src/App.js
@@ -101,16 +101,11 @@ class App extends Component {
|
||||
}
|
||||
};
|
||||
|
||||
checkVersionInstalled = (release, version, versionLookup) => {
|
||||
if (!versionLookup) {
|
||||
versionLookup = this.state.VersionLookup;
|
||||
}
|
||||
|
||||
const selectedVersion = versionLookup[this.state.ReleaseTypes[release]][version];
|
||||
checkVersionInstalled = () => {
|
||||
this.setState({
|
||||
AllowDownload: false,
|
||||
});
|
||||
|
||||
}, ()=> {
|
||||
const selectedVersion = this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]][this.state.Version];
|
||||
if (selectedVersion !== 'unavailable') {
|
||||
if (ipcRenderer) {
|
||||
let dependencies = [];
|
||||
@@ -125,6 +120,7 @@ class App extends Component {
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
closeErrorDisplay = () => {
|
||||
@@ -176,6 +172,8 @@ class App extends Component {
|
||||
...this.state.Hyperspace
|
||||
};
|
||||
|
||||
this.saveState(this.state.Release, this.state.Version, sia, hyperspace);
|
||||
|
||||
if (storageType === 'Hyperspace') {
|
||||
hyperspace.AutoMount = e.target.checked;
|
||||
this.setState({
|
||||
@@ -188,7 +186,6 @@ class App extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
this.saveState(this.state.Release, this.state.Version, sia, hyperspace);
|
||||
};
|
||||
|
||||
handleConfigClicked = (storageType) => {
|
||||
@@ -212,13 +209,13 @@ class App extends Component {
|
||||
DownloadActive: true,
|
||||
DownloadingDependency: true,
|
||||
DownloadName: fileName,
|
||||
});
|
||||
|
||||
}, ()=> {
|
||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
Filename: fileName,
|
||||
Filename: this.state.DownloadName,
|
||||
URL: url,
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -227,9 +224,6 @@ class App extends Component {
|
||||
...this.state[storageType],
|
||||
MountLocation: location,
|
||||
};
|
||||
this.setState({
|
||||
[storageType]: state,
|
||||
});
|
||||
const hyperspace = (storageType === 'Hyperspace') ? state : {
|
||||
...this.state.Hyperspace,
|
||||
};
|
||||
@@ -238,17 +232,21 @@ class App extends Component {
|
||||
};
|
||||
|
||||
this.saveState(this.state.Release, this.state.Version, sia, hyperspace);
|
||||
this.setState({
|
||||
[storageType]: state,
|
||||
});
|
||||
};
|
||||
|
||||
handleReleaseChanged = (e) => {
|
||||
const val = parseInt(e.target.value, 10);
|
||||
const versionIndex = this.state.VersionLookup[this.state.ReleaseTypes[val]].length - 1;
|
||||
this.saveState(val, versionIndex, this.state.Sia, this.state.Hyperspace);
|
||||
this.setState({
|
||||
Release: val,
|
||||
Version: versionIndex
|
||||
}, ()=> {
|
||||
this.checkVersionInstalled( );
|
||||
});
|
||||
this.saveState(val, versionIndex, this.state.Sia, this.state.Hyperspace);
|
||||
this.checkVersionInstalled(val, versionIndex);
|
||||
};
|
||||
|
||||
handleReleaseDownload = () => {
|
||||
@@ -259,13 +257,13 @@ class App extends Component {
|
||||
DownloadActive: true,
|
||||
DownloadingRelease: true,
|
||||
DownloadName: fileName,
|
||||
});
|
||||
|
||||
}, () => {
|
||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
Filename: fileName,
|
||||
Filename: this.state.DownloadName,
|
||||
URL: this.state.LocationsLookup[selectedVersion].urls[0],
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -275,13 +273,13 @@ class App extends Component {
|
||||
DownloadActive: true,
|
||||
DownloadingUpgrade: true,
|
||||
DownloadName: 'UI Upgrade',
|
||||
});
|
||||
|
||||
}, ()=> {
|
||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
Filename: this.props.platform === 'win32' ? 'upgrade.exe' : 'upgrade',
|
||||
URL: this.state.UpgradeData.urls[0],
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.setState({UpgradeDismissed: true});
|
||||
}
|
||||
@@ -289,11 +287,12 @@ class App extends Component {
|
||||
|
||||
handleVersionChanged = (e) => {
|
||||
const val = parseInt(e.target.value, 10);
|
||||
this.saveState(this.state.Release, val, this.state.Sia, this.state.Hyperspace);
|
||||
this.setState({
|
||||
Version: val
|
||||
}, ()=> {
|
||||
this.checkVersionInstalled( );
|
||||
});
|
||||
this.saveState(this.state.Release, val, this.state.Sia, this.state.Hyperspace);
|
||||
this.checkVersionInstalled(this.state.Release, val);
|
||||
};
|
||||
|
||||
notifyAutoMountProcessed = () => {
|
||||
@@ -400,8 +399,9 @@ class App extends Component {
|
||||
|
||||
this.setState({
|
||||
ExtractActive: false,
|
||||
}, ()=> {
|
||||
this.checkVersionInstalled( );
|
||||
});
|
||||
this.checkVersionInstalled(this.state.Release, this.state.Version);
|
||||
};
|
||||
|
||||
onGetStateReply = (event, arg) => {
|
||||
@@ -417,9 +417,12 @@ class App extends Component {
|
||||
Release: arg.data.Release,
|
||||
Sia: arg.data.Sia,
|
||||
Version: arg.data.Version,
|
||||
});
|
||||
}
|
||||
}, ()=> {
|
||||
this.grabReleases();
|
||||
});
|
||||
} else {
|
||||
this.grabReleases();
|
||||
}
|
||||
};
|
||||
|
||||
onGrabReleasesReply = ()=> {
|
||||
@@ -437,9 +440,9 @@ class App extends Component {
|
||||
Version: version,
|
||||
VersionAvailable: version !== latestVersion,
|
||||
VersionLookup: versionLookup,
|
||||
}, () => {
|
||||
this.checkVersionInstalled( );
|
||||
});
|
||||
|
||||
this.checkVersionInstalled(this.state.Release, version, versionLookup);
|
||||
};
|
||||
|
||||
axios.get(Constants.RELEASES_URL)
|
||||
@@ -500,7 +503,7 @@ class App extends Component {
|
||||
ipcRenderer.send(Constants.IPC_Delete_File, {
|
||||
FilePath: arg.data.Source,
|
||||
});
|
||||
this.checkVersionInstalled(this.state.Release, this.state.Version);
|
||||
this.checkVersionInstalled( );
|
||||
};
|
||||
|
||||
onInstallUpgradeReply = (event, arg) => {
|
||||
|
||||
@@ -164,12 +164,13 @@ class Configuration extends Component {
|
||||
if (arg.data.Success) {
|
||||
this.setState({
|
||||
Template: arg.data.Template,
|
||||
});
|
||||
}, ()=> {
|
||||
ipcRenderer.send(Constants.IPC_Get_Config, {
|
||||
Directory: this.props.directory,
|
||||
StorageType: this.props.storageType,
|
||||
Version: this.props.version,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.props.errorHandler(arg.data.Error, () => {
|
||||
this.props.closed();
|
||||
@@ -185,8 +186,7 @@ class Configuration extends Component {
|
||||
if (ipcRenderer) {
|
||||
this.setState({
|
||||
Saving: true,
|
||||
});
|
||||
|
||||
}, ()=> {
|
||||
const changedItems = [];
|
||||
for (const item of this.state.ChangedItems) {
|
||||
changedItems.push({
|
||||
@@ -212,6 +212,7 @@ class Configuration extends Component {
|
||||
StorageType: this.props.storageType,
|
||||
Version: this.props.version,
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -69,12 +69,12 @@ class MountItems extends Component {
|
||||
...this.state[storageType],
|
||||
AllowMount: false,
|
||||
};
|
||||
this.setState({
|
||||
[storageType]: state,
|
||||
});
|
||||
|
||||
this.props.mountsBusy(true);
|
||||
|
||||
this.setState({
|
||||
[storageType]: state,
|
||||
}, ()=> {
|
||||
if (mount) {
|
||||
ipcRenderer.send(Constants.IPC_Mount_Drive, {
|
||||
Directory: this.props.directory,
|
||||
@@ -91,6 +91,7 @@ class MountItems extends Component {
|
||||
Version: this.props.version,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -111,13 +112,12 @@ class MountItems extends Component {
|
||||
PID: arg.data.PIDS.Hyperspace,
|
||||
};
|
||||
|
||||
this.props.mountsBusy(hs.Mounted || sia.Mounted);
|
||||
|
||||
this.setState({
|
||||
Hyperspace: hs,
|
||||
Sia: sia,
|
||||
});
|
||||
|
||||
this.props.mountsBusy(hs.Mounted || sia.Mounted);
|
||||
|
||||
}, () => {
|
||||
let hsLocation = arg.data.Locations.Hyperspace;
|
||||
if ((hsLocation.length === 0) && (this.props.platform === 'win32')) {
|
||||
hsLocation = this.props.hyperspace.MountLocation || arg.data.DriveLetters.Hyperspace[0];
|
||||
@@ -135,6 +135,7 @@ class MountItems extends Component {
|
||||
}
|
||||
|
||||
this.performAutoMount();
|
||||
});
|
||||
} else {
|
||||
this.props.errorHandler(arg.data.Error);
|
||||
}
|
||||
@@ -148,9 +149,9 @@ class MountItems extends Component {
|
||||
};
|
||||
this.setState({
|
||||
[arg.data.StorageType]: state,
|
||||
});
|
||||
|
||||
}, ()=> {
|
||||
this.detectMounts();
|
||||
});
|
||||
};
|
||||
|
||||
onUnmountDriveReply = (event, arg) => {
|
||||
|
||||
Reference in New Issue
Block a user