Refactoring

This commit is contained in:
2021-05-05 01:52:11 -05:00
parent 5061121424
commit 56f7fcfddb
2 changed files with 56 additions and 105 deletions

View File

@@ -21,6 +21,16 @@ const Host = ({ allowDelete, editHost, host_list, host_data, onChange, onDelete
});
};
const getHostDisplay = () => {
return (
host_data.HostNameOrIp +
((host_data.Protocol === 'http' && host_data.ApiPort === 80) ||
(host_data.Protocol === 'https' && host_data.ApiPort === 443)
? ''
: ':' + host_data.ApiPort)
);
};
const premium = host_data.AuthURL && host_data.AuthUser;
return (
<div style={{ display: 'flex', flexDirection: 'row' }}>
@@ -46,23 +56,10 @@ const Host = ({ allowDelete, editHost, host_list, host_data, onChange, onDelete
) : null}
{premium ? (
<p>
<b>
{'(premium) ' +
host_data.HostNameOrIp +
((host_data.Protocol === 'http' && host_data.ApiPort === 80) ||
(host_data.Protocol === 'https' && host_data.ApiPort === 443)
? ''
: ':' + host_data.ApiPort)}
</b>
<b>{'(premium) ' + getHostDisplay()}</b>
</p>
) : (
<p>
{host_data.HostNameOrIp +
((host_data.Protocol === 'http' && host_data.ApiPort === 80) ||
(host_data.Protocol === 'https' && host_data.ApiPort === 443)
? ''
: ':' + host_data.ApiPort)}
</p>
<p>{getHostDisplay()}</p>
)}
</div>
);
@@ -78,4 +75,3 @@ Host.propTypes = {
};
export default connect(null, mapDispatchToProps)(Host);
// export default Host;

View File

@@ -67,11 +67,9 @@ class MountItems extends IPCContainer {
}
componentWillUnmount() {
for (const provider in this.state.RetryItems) {
if (Object.prototype.hasOwnProperty.call(this.state.RetryItems, provider)) {
this.cancelRetryMount(provider);
}
}
Object.keys(this.state.RetryItems).forEach((provider) => {
this.cancelRetryMount(provider);
});
this.props.resetMountsState();
this.activeDetections = [];
@@ -91,8 +89,7 @@ class MountItems extends IPCContainer {
detectMounts = () => {
if (!this.state.DisplayRetry) {
const providerList = this.getProviderList();
providerList.forEach((provider) => {
this.getProviderList().forEach((provider) => {
this.detectMount(provider);
});
}
@@ -121,7 +118,7 @@ class MountItems extends IPCContainer {
() => {
this.sendRequest(Constants.IPC_Show_Window);
this.retryIntervals[provider] = setInterval(() => {
let retryItems = {
const retryItems = {
...this.state.RetryItems,
};
const retrySeconds = retryItems[provider].RetrySeconds - 1;
@@ -174,6 +171,9 @@ class MountItems extends IPCContainer {
S3: s3,
Version: this.props.InstalledVersion,
}).data;
const displayRetry = (msg) => {
this.displayRetryMount(provider, remote, s3, location, msg);
};
if (result.Success) {
if (result.Valid) {
if (this.props.Platform !== 'win32') {
@@ -191,32 +191,16 @@ class MountItems extends IPCContainer {
result.Code === new Uint32Array([-1])[0] ||
result.Code === new Uint8Array([-1])[0]
) {
this.displayRetryMount(
provider,
remote,
s3,
location,
'Failed to connect to ' + provider + ' daemon'
);
displayRetry('Failed to connect to ' + provider + ' daemon');
} else if (
result.Code === new Uint32Array([-3])[0] ||
result.Code === new Uint8Array([-3])[0]
) {
this.displayRetryMount(
provider,
remote,
s3,
location,
displayRetry(
'Incompatible ' + provider + ' daemon. Please upgrade ' + provider + '.'
);
} else {
this.displayRetryMount(
provider,
remote,
s3,
location,
'Version check failed: ' + result.Error
);
displayRetry('Version check failed: ' + result.Error);
}
}
} else {
@@ -226,13 +210,7 @@ class MountItems extends IPCContainer {
'Failed to launch repertory. Please install Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019.'
);
} else {
this.displayRetryMount(
provider,
remote,
s3,
location,
'Version check failed: ' + result.Error
);
displayRetry('Version check failed: ' + result.Error);
}
}
}
@@ -241,23 +219,13 @@ class MountItems extends IPCContainer {
this.addMountsBusy(provider);
this.props.setAllowMount(provider, false);
if (mount) {
this.sendRequest(Constants.IPC_Mount_Drive, {
Location: location,
Provider: provider,
Remote: remote,
S3: s3,
Version: this.props.InstalledVersion,
});
} else {
this.sendRequest(Constants.IPC_Unmount_Drive, {
Location: location,
Provider: provider,
Remote: remote,
S3: s3,
Version: this.props.InstalledVersion,
});
}
this.sendRequest(mount ? Constants.IPC_Mount_Drive : Constants.IPC_Unmount_Drive, {
Location: location,
Provider: provider,
Remote: remote,
S3: s3,
Version: this.props.InstalledVersion,
});
}
}
};
@@ -285,11 +253,9 @@ class MountItems extends IPCContainer {
};
hasActiveMount = () => {
for (const provider of Object.keys(this.props.MountState)) {
if (this.props.MountState[provider].Mounted) return true;
}
return false;
return !!Object.keys(this.props.MountState).find((provider) => {
return this.props.MountState[provider].Mounted;
});
};
onDetectMountReply = (_, arg) => {
@@ -384,32 +350,27 @@ class MountItems extends IPCContainer {
render() {
let retryDisplay;
if (this.state.DisplayRetry) {
let retryList = [];
const retryList = [];
let retryCount = 0;
for (const provider in this.state.RetryItems) {
if (Object.prototype.hasOwnProperty.call(this.state.RetryItems, provider)) {
if (this.state.RetryItems[provider].RetryMessage) {
retryList.push(
<p key={'rl_' + retryList.length}>{this.state.RetryItems[provider].RetryMessage}</p>
);
}
Object.keys(this.state.RetryItems).forEach((provider) => {
if (this.state.RetryItems[provider].RetryMessage) {
retryList.push(
<Button
clicked={() => this.cancelRetryMount(provider, () => this.detectMounts())}
key={'rl_' + retryList.length}>
Cancel {provider} Remount ({this.state.RetryItems[provider].RetrySeconds}s)
</Button>
<p key={'rl_' + retryList.length}>{this.state.RetryItems[provider].RetryMessage}</p>
);
if (++retryCount < Object.keys(this.state.RetryItems).length) {
retryList.push(
<div
style={{ paddingTop: 'var(--default_spacing)' }}
key={'rl_' + retryList.length}
/>
);
}
}
}
retryList.push(
<Button
clicked={() => this.cancelRetryMount(provider, () => this.detectMounts())}
key={'rl_' + retryList.length}>
Cancel {provider} Remount ({this.state.RetryItems[provider].RetrySeconds}s)
</Button>
);
if (++retryCount < Object.keys(this.state.RetryItems).length) {
retryList.push(
<div style={{ paddingTop: 'var(--default_spacing)' }} key={'rl_' + retryList.length} />
);
}
});
retryDisplay = (
<Modal>
@@ -428,7 +389,7 @@ class MountItems extends IPCContainer {
);
}
let footerItems = [];
const footerItems = [];
if (this.props.remoteSupported || this.props.s3Supported) {
footerItems.push(
<AddMount
@@ -441,7 +402,7 @@ class MountItems extends IPCContainer {
footerItems.push(<div key={'hi_' + footerItems.length} style={{ height: '27px' }} />);
}
let mountItems = [];
const mountItems = [];
const addMountItem = (provider, remote, s3) => {
if (mountItems.length > 0) {
mountItems.push(
@@ -466,20 +427,14 @@ class MountItems extends IPCContainer {
);
};
for (const provider of this.getProviderList(true)) {
addMountItem(provider);
}
this.getProviderList(true).forEach((provider) => addMountItem(provider));
if (this.props.remoteSupported) {
for (const provider of this.props.RemoteMounts) {
addMountItem(provider, true);
}
this.props.RemoteMounts.forEach((provider) => addMountItem(provider, true));
}
if (this.props.s3Supported) {
for (const provider of this.props.S3Mounts) {
addMountItem(provider, false, true);
}
this.props.S3Mounts.forEach((provider) => addMountItem(provider, false, true));
}
return (