Redux changes and refactoring
This commit is contained in:
@@ -7,8 +7,11 @@ import Modal from '../../components/UI/Modal/Modal';
|
||||
import MountItem from '../../components/MountItem/MountItem';
|
||||
import IPCContainer from '../IPCContainer/IPCContainer';
|
||||
import {
|
||||
setAllowMount,
|
||||
setAutoMountProcessed,
|
||||
setBusy,
|
||||
setMountState,
|
||||
setMounted,
|
||||
setProviderState
|
||||
} from '../../redux/actions/mount_actions';
|
||||
|
||||
@@ -17,15 +20,7 @@ const Constants = require('../../constants');
|
||||
class MountItems extends IPCContainer {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
this.state[provider] = {
|
||||
AllowMount: false,
|
||||
DriveLetters: [],
|
||||
Mounted: false,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
this.setRequestHandler(Constants.IPC_Detect_Mounts_Reply, this.onDetectMountsReply);
|
||||
this.setRequestHandler(Constants.IPC_Mount_Drive_Reply, this.onMountDriveReply);
|
||||
this.setRequestHandler(Constants.IPC_Unmount_Drive_Reply, this.onUnmountDriveReply);
|
||||
@@ -92,7 +87,7 @@ class MountItems extends IPCContainer {
|
||||
|
||||
handleMountLocationChanged = (provider, value) => {
|
||||
const location = (this.props.Platform === 'win32') ?
|
||||
this.state[provider].DriveLetters[value] :
|
||||
this.props.MountState[provider].DriveLetters[value] :
|
||||
value;
|
||||
|
||||
const state = {
|
||||
@@ -140,85 +135,77 @@ class MountItems extends IPCContainer {
|
||||
}
|
||||
|
||||
if (allowAction) {
|
||||
const storageState = {
|
||||
...this.state[provider],
|
||||
AllowMount: false,
|
||||
};
|
||||
|
||||
this.props.setMountsBusy(true);
|
||||
this.props.setAllowMount(provider, false);
|
||||
|
||||
this.setState({
|
||||
[provider]: storageState,
|
||||
}, () => {
|
||||
if (mount) {
|
||||
this.sendRequest(Constants.IPC_Mount_Drive, {
|
||||
Location: location,
|
||||
NoConsoleSupported: this.props.noConsoleSupported,
|
||||
Provider: provider,
|
||||
Version: this.props.version,
|
||||
});
|
||||
} else {
|
||||
this.sendRequest(Constants.IPC_Unmount_Drive, {
|
||||
Location: location,
|
||||
Provider: provider,
|
||||
Version: this.props.version,
|
||||
});
|
||||
}
|
||||
});
|
||||
if (mount) {
|
||||
this.sendRequest(Constants.IPC_Mount_Drive, {
|
||||
Location: location,
|
||||
NoConsoleSupported: this.props.noConsoleSupported,
|
||||
Provider: provider,
|
||||
Version: this.props.version,
|
||||
});
|
||||
} else {
|
||||
this.sendRequest(Constants.IPC_Unmount_Drive, {
|
||||
Location: location,
|
||||
Provider: provider,
|
||||
Version: this.props.version,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onDetectMountsReply = (event, arg) => {
|
||||
if (!this.state.DisplayRetry && arg.data.Success) {
|
||||
let state = {};
|
||||
let mountsBusy = false;
|
||||
let mountStates = {};
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
state[provider] = {
|
||||
...this.state[provider],
|
||||
const mountState = {
|
||||
AllowMount: true,
|
||||
DriveLetters: (arg.data.DriveLetters[provider]),
|
||||
Mounted: (arg.data.Locations[provider].length > 0),
|
||||
};
|
||||
mountsBusy = mountsBusy || state[provider].Mounted;
|
||||
this.props.setMountState(provider, mountState);
|
||||
mountsBusy = mountsBusy || mountState.Mounted;
|
||||
mountStates[provider] = mountState;
|
||||
}
|
||||
this.props.setMountsBusy(mountsBusy);
|
||||
|
||||
this.setState(state, () => {
|
||||
const updateMountLocation = (data, provider) => {
|
||||
const providerState = this.props.ProviderState[provider];
|
||||
let location = data.Locations[provider];
|
||||
if (location.length === 0) {
|
||||
location = (this.props.Platform === 'win32') ?
|
||||
providerState.MountLocation || data.DriveLetters[provider][0] :
|
||||
providerState.MountLocation;
|
||||
}
|
||||
if (location !== providerState.MountLocation) {
|
||||
this.handleMountLocationChanged(provider, location);
|
||||
}
|
||||
};
|
||||
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
updateMountLocation(arg.data, provider);
|
||||
|
||||
const updateMountLocation = (data, provider) => {
|
||||
const providerState = this.props.ProviderState[provider];
|
||||
let location = data.Locations[provider];
|
||||
if (location.length === 0) {
|
||||
location = (this.props.Platform === 'win32') ?
|
||||
providerState.MountLocation || data.DriveLetters[provider][0] :
|
||||
providerState.MountLocation;
|
||||
}
|
||||
|
||||
this.performAutoMount();
|
||||
});
|
||||
if (location !== providerState.MountLocation) {
|
||||
this.handleMountLocationChanged(provider, location);
|
||||
}
|
||||
|
||||
if (!this.props.AutoMountProcessed &&
|
||||
this.props.ProviderState[provider].AutoMount &&
|
||||
!mountStates[provider].Mounted &&
|
||||
(location.length > 0)) {
|
||||
this.handleMountUnMount(provider, true, location);
|
||||
}
|
||||
};
|
||||
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
updateMountLocation(arg.data, provider);
|
||||
}
|
||||
|
||||
this.props.setAutoMountProcessed(true);
|
||||
} else {
|
||||
this.props.errorHandler(arg.data.Error);
|
||||
}
|
||||
};
|
||||
|
||||
onMountDriveReply = (event, arg) => {
|
||||
const state = {
|
||||
...this.state[arg.data.Provider],
|
||||
Mounted: arg.data.Success,
|
||||
};
|
||||
this.setState({
|
||||
[arg.data.Provider]: state,
|
||||
}, ()=> {
|
||||
this.detectMounts();
|
||||
});
|
||||
this.props.setMounted(arg.data.ProviderState, arg.data.Success);
|
||||
this.detectMounts();
|
||||
};
|
||||
|
||||
onUnmountDriveReply = (event, arg) => {
|
||||
@@ -231,13 +218,14 @@ class MountItems extends IPCContainer {
|
||||
retryItems[provider] = {
|
||||
RetrySeconds: 10,
|
||||
};
|
||||
const storageState = {
|
||||
...this.state[arg.data.Provider],
|
||||
const mountState = {
|
||||
...this.props.MountState[provider],
|
||||
AllowMount: false,
|
||||
Mounted: false,
|
||||
};
|
||||
this.setMountState(provider, mountState);
|
||||
|
||||
this.setState({
|
||||
[provider]: storageState,
|
||||
DisplayRetry: true,
|
||||
RetryItems: retryItems,
|
||||
}, () => {
|
||||
@@ -265,25 +253,6 @@ class MountItems extends IPCContainer {
|
||||
}
|
||||
};
|
||||
|
||||
performAutoMount = ()=> {
|
||||
if (!this.props.AutoMountProcessed) {
|
||||
this.props.setAutoMountProcessed(true);
|
||||
|
||||
const processAutoMount = (provider) => {
|
||||
const providerState = this.props.ProviderState[provider];
|
||||
if (providerState.AutoMount &&
|
||||
!this.state[provider].Mounted &&
|
||||
(providerState.MountLocation.length > 0)) {
|
||||
this.handleMountUnMount(provider, true, providerState.MountLocation);
|
||||
}
|
||||
};
|
||||
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
processAutoMount(provider);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
let retryDisplay;
|
||||
if (this.state.DisplayRetry) {
|
||||
@@ -315,15 +284,11 @@ class MountItems extends IPCContainer {
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
items.push((
|
||||
<MountItem allowConfig={this.props.allowConfig}
|
||||
allowMount={this.state[provider].AllowMount}
|
||||
browseClicked={this.handleBrowseLocation}
|
||||
changed={e => this.handleMountLocationChanged(provider, e.target.value)}
|
||||
clicked={this.handleMountUnMount}
|
||||
items={this.state[provider].DriveLetters}
|
||||
key={'mi_' + items.length}
|
||||
provider={provider}
|
||||
mounted={this.state[provider].Mounted}
|
||||
title={provider} />
|
||||
provider={provider}/>
|
||||
));
|
||||
if (items.length !== this.state.length) {
|
||||
items.push(<div key={'di_' + items.length}
|
||||
@@ -342,6 +307,7 @@ class MountItems extends IPCContainer {
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
AutoMountProcessed: state.mounts.AutoMountProcessed,
|
||||
MountState: state.mounts.MountState,
|
||||
Platform: state.common.Platform,
|
||||
ProviderState: state.mounts.ProviderState,
|
||||
}
|
||||
@@ -349,8 +315,11 @@ const mapStateToProps = state => {
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
setAllowMount: (provider, allow) => dispatch(setAllowMount(provider, allow)),
|
||||
setAutoMountProcessed: processed => dispatch(setAutoMountProcessed(processed)),
|
||||
setMounted: (provider, mounted) => dispatch(setMounted(provider, mounted)),
|
||||
setMountsBusy: busy => dispatch(setBusy(busy)),
|
||||
setMountState: (provider, state) => dispatch(setMountState(provider, state)),
|
||||
setProviderState: (provider, state) => dispatch(setProviderState(provider, state)),
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user