From 0bbfddc17c6cd38d14c3e1f461619cc37aec819f Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Thu, 6 Jun 2019 15:52:56 -0500 Subject: [PATCH] Redux changes and refactoring --- public/electron.js | 60 ++++----- src/App.js | 102 +++------------ src/components/MountItem/MountItem.js | 50 ++++++-- .../ReleaseVersionDisplay.js | 23 +++- src/containers/Configuration/Configuration.js | 6 +- src/containers/MountItems/MountItems.js | 121 +++++++++--------- src/helpers.js | 42 +++--- src/redux/actions/mount_actions.js | 12 +- src/redux/reducers/mount_reducer.js | 28 +++- 9 files changed, 233 insertions(+), 211 deletions(-) diff --git a/public/electron.js b/public/electron.js index f98786c..001b254 100644 --- a/public/electron.js +++ b/public/electron.js @@ -119,7 +119,7 @@ function createWindow() { // Unmount all items for (const i in mountedLocations) { const data = mountedData[mountedLocations[i]]; - helpers.stopMountProcessSync(data.Version, data.StorageType); + helpers.stopMountProcessSync(data.Version, data.Provider); } mountedLocations = []; @@ -205,10 +205,10 @@ if (!instanceLock) { }); } -const clearManualMountDetection = (storageType) => { - if (manualMountDetection[storageType]) { - clearInterval(manualMountDetection[storageType]); - delete manualMountDetection[storageType]; +const clearManualMountDetection = (provider) => { + if (manualMountDetection[provider]) { + clearInterval(manualMountDetection[provider]); + delete manualMountDetection[provider]; } }; @@ -223,25 +223,25 @@ const loadUiSettings = () => { } }; -const monitorMount = (sender, storageType, version, pid, location) => { - manualMountDetection[storageType] = setInterval(() => { +const monitorMount = (sender, provider, version, pid, location) => { + manualMountDetection[provider] = setInterval(() => { helpers .detectRepertoryMounts(version) .then(result => { - if (result[storageType].PID !== pid) { - if (result[storageType].PID === -1) { - clearManualMountDetection(storageType); + if (result[provider].PID !== pid) { + if (result[provider].PID === -1) { + clearManualMountDetection(provider); sender.send(Constants.IPC_Unmount_Drive_Reply, { data: { - Expected: expectedUnmount[storageType], + Expected: expectedUnmount[provider], Location: location, - StorageType: storageType, - Error: Error(storageType + ' Unmounted').toString(), + Provider: provider, + Error: Error(provider + ' Unmounted').toString(), Success: false, } }); } else { - pid = result[storageType].PID; + pid = result[provider].PID; } } }) @@ -289,7 +289,7 @@ ipcMain.on(Constants.IPC_Browse_Directory + '_sync', (event, data) => { ipcMain.on(Constants.IPC_Check_Daemon_Version, (event, data) => { helpers - .checkDaemonVersion(data.Version, data.StorageType) + .checkDaemonVersion(data.Version, data.Provider) .then(code => { standardIPCReply(event, Constants.IPC_Check_Daemon_Version_Reply, { Valid: (code === 0), @@ -304,7 +304,7 @@ ipcMain.on(Constants.IPC_Check_Daemon_Version, (event, data) => { ipcMain.on(Constants.IPC_Check_Daemon_Version + '_sync', (event, data) => { helpers - .checkDaemonVersion(data.Version, data.StorageType) + .checkDaemonVersion(data.Version, data.Provider) .then(code => { event.returnValue = { data: { @@ -593,7 +593,7 @@ ipcMain.on(Constants.IPC_Extract_Release, (event, data) => { ipcMain.on(Constants.IPC_Get_Config, (event, data) => { helpers - .getConfig(data.Version, data.StorageType) + .getConfig(data.Version, data.Provider) .then((data) => { if (data.Code === 0) { standardIPCReply(event, Constants.IPC_Get_Config_Reply, { @@ -610,7 +610,7 @@ ipcMain.on(Constants.IPC_Get_Config, (event, data) => { ipcMain.on(Constants.IPC_Get_Config_Template, (event, data) => { helpers - .getConfigTemplate(data.Version, data.StorageType) + .getConfigTemplate(data.Version, data.Provider) .then((data) => { standardIPCReply(event, Constants.IPC_Get_Config_Template_Reply, { Template: data, @@ -796,15 +796,15 @@ ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => { }); ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => { - expectedUnmount[data.StorageType] = false; + expectedUnmount[data.Provider] = false; if (mountedLocations.indexOf(data.Location) !== -1) { - console.log(data.StorageType + ' already mounted: ' + data.Location); + console.log(data.Provider + ' already mounted: ' + data.Location); } else { mountedLocations.push(data.Location); mountedData[data.Location] = { Version: data.Version, - StorageType: data.StorageType, + Provider: data.Provider, }; const errorHandler = (pid, error) => { if (mountedLocations.indexOf(data.Location) !== -1) { @@ -813,18 +813,18 @@ ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => { } standardIPCReply(event, Constants.IPC_Unmount_Drive_Reply, { - Expected: expectedUnmount[data.StorageType], + Expected: expectedUnmount[data.Provider], Location: data.Location, - StorageType: data.StorageType, - }, error || Error(data.StorageType + ' Unmounted')); + Provider: data.Provider, + }, error || Error(data.Provider + ' Unmounted')); }; helpers - .executeMount(data.Version, data.StorageType, data.Location, data.NoConsoleSupported, (error, pid) => { + .executeMount(data.Version, data.Provider, data.Location, data.NoConsoleSupported, (error, pid) => { errorHandler(pid, error); }) .then(() => { standardIPCReply(event, Constants.IPC_Mount_Drive_Reply, { - StorageType: data.StorageType, + Provider: data.Provider, }); }) .catch(error => { @@ -843,7 +843,7 @@ ipcMain.on(Constants.IPC_Set_Config_Values, (event, data) => { const setConfigValue = (i) => { if (i < data.Items.length) { helpers - .setConfigValue(data.Items[i].Name, data.Items[i].Value, data.StorageType, data.Version) + .setConfigValue(data.Items[i].Name, data.Items[i].Value, data.Provider, data.Version) .then(() => { setConfigValue(++i); }) @@ -871,11 +871,11 @@ ipcMain.on(Constants.IPC_Show_Window + '_sync', event => { }); ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => { - clearManualMountDetection(data.StorageType); + clearManualMountDetection(data.Provider); - expectedUnmount[data.StorageType] = true; + expectedUnmount[data.Provider] = true; helpers - .stopMountProcess(data.Version, data.StorageType) + .stopMountProcess(data.Version, data.Provider) .then((result)=> { console.log(result); }) diff --git a/src/App.js b/src/App.js index 565bf0b..cafb703 100644 --- a/src/App.js +++ b/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 { + saveState={this.saveState} + text={this.state.InstalledVersion + ' [' + this.props.AppPlatform + ']'}/> )); if (allowMount) { - let providerProps = {}; - for (const provider of Constants.PROVIDER_LIST) { - const providerLower = provider.toLowerCase(); - providerProps[providerLower] = this.state[provider]; - } mainContent.push((
-
)); @@ -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)), }; }; diff --git a/src/components/MountItem/MountItem.js b/src/components/MountItem/MountItem.js index 317d783..45d55b2 100644 --- a/src/components/MountItem/MountItem.js +++ b/src/components/MountItem/MountItem.js @@ -1,6 +1,6 @@ import React from 'react'; import './MountItem.css'; -import {connect} from "react-redux"; +import {connect} from 'react-redux'; import DropDown from '../UI/DropDown/DropDown'; import Button from '../UI/Button/Button'; import Loader from 'react-loader-spinner'; @@ -8,14 +8,40 @@ import Text from '../UI/Text/Text'; import Grid from '../UI/Grid/Grid'; import configureImage from '../../assets/images/configure.png'; import RootElem from '../../hoc/RootElem/RootElem'; +import {displayConfiguration, setProviderState} from '../../redux/actions/mount_actions'; -const mapStateToProps = state => { +const mapStateToProps = (state, ownProps) => { return { Platform: state.common.Platform, + ProviderState: state.mounts.ProviderState, + State: state.mounts.ProviderState[ownProps.provider] }; }; -export default connect(mapStateToProps)(props => { +const mapDispatchToProps = dispatch => { + return { + displayConfiguration: provider => dispatch(displayConfiguration(provider)), + setProviderState: (provider, state) => dispatch(setProviderState(provider, state)), + } +}; + +export default connect(mapStateToProps, mapDispatchToProps)(props => { + const handleAutoMountChanged = e => { + const state = { + ...props.ProviderState[props.provider], + AutoMount: e.target.checked, + }; + props.setProviderState(props.provider, state); + }; + + const handleAutoRestartChanged = e => { + const state = { + ...props.ProviderState[props.provider], + AutoRestart: e.target.checked, + }; + props.setProviderState(props.provider, state); + }; + let configButton = null; let secondRow = 6; if (props.allowConfig) { @@ -25,7 +51,7 @@ export default connect(mapStateToProps)(props => { rowSpan={6}> {e.preventDefault();}} + onClick={props.allowMount ? ()=>props.displayConfiguration(props.provider) : e=>{e.preventDefault();}} src={configureImage} style={{padding: 0, border: 0, margin: 0, ...pointer}} width={'16px'}/> @@ -43,7 +69,7 @@ export default connect(mapStateToProps)(props => { items={props.items} row={secondRow} rowSpan={7} - selected={props.items.indexOf(props.location)}/>; + selected={props.items.indexOf(props.State.MountLocation)}/>; } else { inputColumnSpan = 58; @@ -60,11 +86,11 @@ export default connect(mapStateToProps)(props => { size={4096} className={'MountItemInput'} type={'text'} - value={props.location}/> + value={props.State.MountLocation}/> )); inputControls.push(( - ); + clicked={()=>this.cancelRetryMount(provider, ()=> this.detectMounts())} + key={'b' + retryListCount}>Cancel {provider} Remount ({this.state.RetryItems[provider].RetrySeconds}s)); if (retryListCount < Object.keys(this.state.RetryItems).length) { retryList.push(
); } @@ -299,21 +307,15 @@ class MountItems extends IPCContainer { let items = []; for (const provider of Constants.PROVIDER_LIST) { - const providerLower = provider.toLowerCase(); items.push(( this.props.autoMountChanged(provider, e)} - autoRestart={this.props[providerLower].AutoRestart} - autoRestartChanged={(e)=>this.props.autoRestartChanged(provider, e)} browseClicked={this.handleBrowseLocation} - changed={(e) => this.handleMountLocationChanged(provider, e.target.value)} + changed={e => this.handleMountLocationChanged(provider, e.target.value)} clicked={this.handleMountUnMount} - configClicked={()=>this.props.displayConfiguration(provider)} items={this.state[provider].DriveLetters} key={'mi_' + items.length} - location={this.props[providerLower].MountLocation} + provider={provider} mounted={this.state[provider].Mounted} title={provider} /> )); @@ -335,14 +337,15 @@ const mapStateToProps = state => { return { AutoMountProcessed: state.mounts.AutoMountProcessed, Platform: state.common.Platform, + ProviderState: state.mounts.ProviderState, } }; const mapDispatchToProps = dispatch => { return { - displayConfiguration: storageType => dispatch(displayConfiguration(storageType)), setAutoMountProcessed: processed => dispatch(setAutoMountProcessed(processed)), setMountsBusy: busy => dispatch(setBusy(busy)), + setProviderState: (provider, state) => dispatch(setProviderState(provider, state)), } }; diff --git a/src/helpers.js b/src/helpers.js index 1863ac3..8721986 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -30,7 +30,7 @@ const tryParse = (j, def) => { } }; -module.exports.checkDaemonVersion = (version, storageType) => { +module.exports.checkDaemonVersion = (version, provider) => { return new Promise((resolve, reject) => { const processOptions = { detached: true, @@ -41,8 +41,8 @@ module.exports.checkDaemonVersion = (version, storageType) => { const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory'); const args = []; args.push('-cv'); - if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) { - args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]); + if (Constants.PROVIDER_ARG[provider.toLowerCase()].length > 0) { + args.push(Constants.PROVIDER_ARG[provider.toLowerCase()]); } const process = new spawn(command, args, processOptions); @@ -254,7 +254,7 @@ module.exports.executeScript = script => { }); }; -module.exports.executeMount = (version, storageType, location, noConsoleSupported, exitCallback) => { +module.exports.executeMount = (version, provider, location, noConsoleSupported, exitCallback) => { return new Promise((resolve) => { const processOptions = { detached: false, @@ -264,8 +264,8 @@ module.exports.executeMount = (version, storageType, location, noConsoleSupporte const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory'); const args = []; - if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) { - args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]); + if (Constants.PROVIDER_ARG[provider.toLowerCase()].length > 0) { + args.push(Constants.PROVIDER_ARG[provider.toLowerCase()]); } if ((os.platform() === 'linux') || (os.platform() === 'darwin')) { @@ -299,7 +299,7 @@ module.exports.executeMount = (version, storageType, location, noConsoleSupporte }); }; -module.exports.getConfig = (version, storageType) => { +module.exports.getConfig = (version, provider) => { return new Promise((resolve, reject) => { const processOptions = { detached: true, @@ -310,8 +310,8 @@ module.exports.getConfig = (version, storageType) => { const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory'); const args = []; args.push('-dc'); - if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) { - args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]); + if (Constants.PROVIDER_ARG[provider.toLowerCase()].length > 0) { + args.push(Constants.PROVIDER_ARG[provider.toLowerCase()]); } const process = new spawn(command, args, processOptions); @@ -345,7 +345,7 @@ module.exports.getConfig = (version, storageType) => { }); }; -module.exports.getConfigTemplate = (version, storageType) => { +module.exports.getConfigTemplate = (version, provider) => { return new Promise((resolve, reject) => { const processOptions = { detached: true, @@ -356,8 +356,8 @@ module.exports.getConfigTemplate = (version, storageType) => { const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory'); const args = []; args.push('-gt'); - if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) { - args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]); + if (Constants.PROVIDER_ARG[provider.toLowerCase()].length > 0) { + args.push(Constants.PROVIDER_ARG[provider.toLowerCase()]); } const process = new spawn(command, args, processOptions); @@ -500,7 +500,7 @@ module.exports.removeDirectoryRecursively = (p) => { module.exports.resolvePath = _resolvePath; -module.exports.setConfigValue = (name, value, storageType, version) => { +module.exports.setConfigValue = (name, value, provider, version) => { return new Promise((resolve, reject) => { const processOptions = { detached: true, @@ -513,8 +513,8 @@ module.exports.setConfigValue = (name, value, storageType, version) => { args.push('-set'); args.push(name); args.push(value); - if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) { - args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]); + if (Constants.PROVIDER_ARG[provider.toLowerCase()].length > 0) { + args.push(Constants.PROVIDER_ARG[provider.toLowerCase()]); } const process = new spawn(command, args, processOptions); @@ -531,7 +531,7 @@ module.exports.setConfigValue = (name, value, storageType, version) => { }); }; -module.exports.stopMountProcess = (version, storageType) => { +module.exports.stopMountProcess = (version, provider) => { return new Promise((resolve, reject) => { const processOptions = { detached: os.platform() === 'darwin', @@ -541,8 +541,8 @@ module.exports.stopMountProcess = (version, storageType) => { const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory'); const args = ['-unmount']; - if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) { - args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]); + if (Constants.PROVIDER_ARG[provider.toLowerCase()].length > 0) { + args.push(Constants.PROVIDER_ARG[provider.toLowerCase()]); } const process = new spawn(command, args, processOptions); @@ -563,7 +563,7 @@ module.exports.stopMountProcess = (version, storageType) => { }); }; -module.exports.stopMountProcessSync = (version, storageType) => { +module.exports.stopMountProcessSync = (version, provider) => { const processOptions = { detached: true, shell: os.platform() !== 'darwin', @@ -572,8 +572,8 @@ module.exports.stopMountProcessSync = (version, storageType) => { const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory'); const args = ['-unmount']; - if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) { - args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]); + if (Constants.PROVIDER_ARG[provider.toLowerCase()].length > 0) { + args.push(Constants.PROVIDER_ARG[provider.toLowerCase()]); } const process = new spawn(command, args, processOptions); diff --git a/src/redux/actions/mount_actions.js b/src/redux/actions/mount_actions.js index ba38ed2..fecb1c1 100644 --- a/src/redux/actions/mount_actions.js +++ b/src/redux/actions/mount_actions.js @@ -2,4 +2,14 @@ import {createAction} from 'redux-starter-kit'; export const displayConfiguration = createAction('mounts/displayConfiguration'); export const setAutoMountProcessed = createAction('mounts/setAutoMountProcessed'); -export const setBusy = createAction('mounts/setBusy'); \ No newline at end of file +export const setBusy = createAction('mounts/setBusy'); +export const SET_PROVIDER_STATE = 'mounts/setProviderState'; +export const setProviderState = (provider, state) => { + return { + type: SET_PROVIDER_STATE, + payload: { + provider, + state + } + } +}; \ No newline at end of file diff --git a/src/redux/reducers/mount_reducer.js b/src/redux/reducers/mount_reducer.js index 88baeb0..45d587a 100644 --- a/src/redux/reducers/mount_reducer.js +++ b/src/redux/reducers/mount_reducer.js @@ -1,10 +1,27 @@ +import * as Constants from '../../constants'; import {createReducer} from 'redux-starter-kit'; -import {displayConfiguration, setAutoMountProcessed, setBusy} from '../actions/mount_actions'; +import {displayConfiguration, setAutoMountProcessed, setBusy, SET_PROVIDER_STATE} from '../actions/mount_actions'; + +const providerState = Constants.PROVIDER_LIST.map(p=> { + return { + [p]: { + AutoMount: false, + AutoRestart: false, + MountLocation: '', + } + } +}).reduce((map, obj) => { + return { + ...map, + ...obj + } +}); export const mountReducer = createReducer({ AutoMountProcessed: false, DisplayConfiguration: null, MountsBusy: false, + ProviderState: providerState, }, { [displayConfiguration]: (state, action) => { return {...state, DisplayConfiguration: action.payload}; @@ -14,5 +31,14 @@ export const mountReducer = createReducer({ }, [setBusy]: (state, action) => { return {...state, MountsBusy: action.payload}; + }, + [SET_PROVIDER_STATE]: (state, action) => { + return { + ...state, + ProviderState: { + ...state.ProviderState, + [action.payload.provider]: action.payload.state, + } + } } }); \ No newline at end of file