Skip to content

TagSpaces is an offline, open source, document manager with tagging support

lazyLoading dialogs (#1181)

Stanimira01f3fa0d7bf
diff --git a/app/components/LocationManager.tsx b/app/components/LocationManager.tsx
index 1497cf354..e179de34d 100644
--- a/app/components/LocationManager.tsx
+++ b/app/components/LocationManager.tsx
@@ -48,8 +48,6 @@ import { Progress } from 'aws-sdk/clients/s3';
import styles from './SidePanels.css';
import DirectoryMenu from './menus/DirectoryMenu';
import LocationManagerMenu from './menus/LocationManagerMenu';
-import EditLocationDialog from './dialogs/EditLocationDialog';
-import CreateLocationDialog from './dialogs/CreateLocationDialog';
import ConfirmDialog from './dialogs/ConfirmDialog';
import SelectDirectoryDialog from './dialogs/SelectDirectoryDialog';
import CreateDirectoryDialog from './dialogs/CreateDirectoryDialog';
@@ -74,9 +72,32 @@ import TargetMoveFileBox from './TargetMoveFileBox';
import DragItemTypes from './DragItemTypes';
import IOActions from '../reducers/io-actions';
import DirectoryTreeView from '-/components/DirectoryTreeView';
+import LoadingLazy from '-/components/LoadingLazy';
const isLocationsReadOnly = window.ExtLocationsReadOnly;
+const CreateLocationDialog = React.lazy(() =>
+ import(
+ /* webpackChunkName: "CreateLocationDialog" */ './dialogs/CreateLocationDialog'
+ )
+);
+const CreateLocationDialogAsync = props => (
+ <React.Suspense fallback={<LoadingLazy />}>
+ <CreateLocationDialog {...props} />
+ </React.Suspense>
+);
+
+const EditLocationDialog = React.lazy(() =>
+ import(
+ /* webpackChunkName: "CreateLocationDialog" */ './dialogs/EditLocationDialog'
+ )
+);
+const EditLocationDialogAsync = props => (
+ <React.Suspense fallback={<LoadingLazy />}>
+ <EditLocationDialog {...props} />
+ </React.Suspense>
+);
+
interface Props {
classes: any;
locations: Array<Location>;
@@ -632,53 +653,63 @@ class LocationManager extends React.Component<Props, State> {
</div>
)}
<div>
- <CreateLocationDialog
- key={this.state.createLocationDialogKey}
- resetState={this.resetState}
- open={this.state.isCreateLocationDialogOpened}
- onClose={this.handleCloseDialogs}
- addLocation={this.props.addLocation}
- showSelectDirectoryDialog={this.showSelectDirectoryDialog}
- />
- <EditLocationDialog
- key={this.state.editLocationDialogKey}
- resetState={this.resetState}
- open={this.state.isEditLocationDialogOpened}
- onClose={this.handleCloseDialogs}
- location={this.state.selectedLocation}
- editLocation={this.props.editLocation}
- showSelectDirectoryDialog={this.showSelectDirectoryDialog}
- selectedDirectoryPath={this.state.selectedDirectoryPath}
- />
- <ConfirmDialog
- open={this.state.isDeleteLocationDialogOpened}
- onClose={this.handleCloseDialogs}
- title={i18n.t('core:deleteLocationTitleAlert')}
- content={i18n.t('core:deleteLocationContentAlert', {
- locationName: this.state.selectedLocation
- ? this.state.selectedLocation.name
- : ''
- })}
- confirmCallback={result => {
- if (result && this.state.selectedLocation) {
- this.props.removeLocation(this.state.selectedLocation);
- }
- }}
- cancelDialogTID="cancelDeleteLocationDialog"
- confirmDialogTID="confirmDeleteLocationDialog"
- />
- <SelectDirectoryDialog
- open={this.state.isSelectDirectoryDialogOpened}
- onClose={this.closeSelectDirectoryExtDialog}
- createNewDirectoryExt={this.createNewDirectoryExt}
- chooseDirectoryPath={this.chooseDirectoryPath}
- selectedDirectoryPath={this.state.selectedDirectoryPath}
- />
- <CreateDirectoryDialog
- open={this.state.isCreateDirectoryDialogOpened}
- onClose={this.closeNewDirectoryDialog}
- selectedDirectoryPath={this.state.selectedDirectoryPath}
- />
+ {this.state.isCreateLocationDialogOpened && (
+ <CreateLocationDialogAsync
+ key={this.state.createLocationDialogKey}
+ resetState={this.resetState}
+ open={this.state.isCreateLocationDialogOpened}
+ onClose={this.handleCloseDialogs}
+ addLocation={this.props.addLocation}
+ showSelectDirectoryDialog={this.showSelectDirectoryDialog}
+ />
+ )}
+ {this.state.isEditLocationDialogOpened && (
+ <EditLocationDialogAsync
+ key={this.state.editLocationDialogKey}
+ resetState={this.resetState}
+ open={this.state.isEditLocationDialogOpened}
+ onClose={this.handleCloseDialogs}
+ location={this.state.selectedLocation}
+ editLocation={this.props.editLocation}
+ showSelectDirectoryDialog={this.showSelectDirectoryDialog}
+ selectedDirectoryPath={this.state.selectedDirectoryPath}
+ />
+ )}
+ {this.state.isDeleteLocationDialogOpened && (
+ <ConfirmDialog
+ open={this.state.isDeleteLocationDialogOpened}
+ onClose={this.handleCloseDialogs}
+ title={i18n.t('core:deleteLocationTitleAlert')}
+ content={i18n.t('core:deleteLocationContentAlert', {
+ locationName: this.state.selectedLocation
+ ? this.state.selectedLocation.name
+ : ''
+ })}
+ confirmCallback={result => {
+ if (result && this.state.selectedLocation) {
+ this.props.removeLocation(this.state.selectedLocation);
+ }
+ }}
+ cancelDialogTID="cancelDeleteLocationDialog"
+ confirmDialogTID="confirmDeleteLocationDialog"
+ />
+ )}
+ {this.state.isSelectDirectoryDialogOpened && (
+ <SelectDirectoryDialog
+ open={this.state.isSelectDirectoryDialogOpened}
+ onClose={this.closeSelectDirectoryExtDialog}
+ createNewDirectoryExt={this.createNewDirectoryExt}
+ chooseDirectoryPath={this.chooseDirectoryPath}
+ selectedDirectoryPath={this.state.selectedDirectoryPath}
+ />
+ )}
+ {this.state.isCreateDirectoryDialogOpened && (
+ <CreateDirectoryDialog
+ open={this.state.isCreateDirectoryDialogOpened}
+ onClose={this.closeNewDirectoryDialog}
+ selectedDirectoryPath={this.state.selectedDirectoryPath}
+ />
+ )}
<Menu
anchorEl={this.state.locationDirectoryContextMenuAnchorEl}
open={this.state.locationContextMenuOpened}
diff --git a/app/components/dialogs/EditLocationDialog.tsx b/app/components/dialogs/EditLocationDialog.tsx
index 0934e5a9d..660b273e8 100644
--- a/app/components/dialogs/EditLocationDialog.tsx
+++ b/app/components/dialogs/EditLocationDialog.tsx
@@ -79,34 +79,74 @@ interface State {
}
class EditLocationDialog extends React.Component<Props, State> {
- state = {
- errorTextPath: false,
- errorTextName: false,
- disableConfirmButton: true,
- cloudErrorTextName: false,
- cloudErrorBucketName: false,
- cloudErrorRegion: false,
- cloudErrorAccessKey: false,
- cloudErrorSecretAccessKey: false,
- uuid: '',
- name: '',
- path: '',
- endpointURL: '',
- isDefault: false,
- isReadOnly: false,
- watchForChanges: false,
- persistIndex: false,
- fullTextIndex: false,
- storeName: '',
- accessKeyId: '',
- secretAccessKey: '',
- bucketName: '',
- region: undefined,
- storePath: '',
- type: locationType.TYPE_LOCAL
- };
+ constructor(props) {
+ super(props);
- componentWillReceiveProps = (nextProps: any) => {
+ if (props.open === true && props.location) {
+ const dir = props.selectedDirectoryPath;
+ let properties;
+ if (props.location.type === locationType.TYPE_CLOUD) {
+ properties = {
+ storeName: dir
+ ? extractDirectoryName(dir, PlatformIO.getDirSeparator())
+ : props.location.name,
+ storePath: dir || props.location.paths[0]
+ };
+ } else {
+ properties = {
+ // TODO maybe its better to separate name/path keys for different locationTypes ??
+ name: dir
+ ? extractDirectoryName(dir, PlatformIO.getDirSeparator())
+ : props.location.name,
+ path: dir || props.location.paths[0]
+ };
+ }
+ this.state = {
+ ...properties,
+ uuid: props.location.uuid,
+ isDefault: props.location.isDefault,
+ isReadOnly: props.location.isReadOnly,
+ watchForChanges: props.location.watchForChanges,
+ persistIndex: props.location.persistIndex,
+ fullTextIndex: props.location.fullTextIndex,
+ type: props.location.type || locationType.TYPE_LOCAL,
+ accessKeyId: props.location.accessKeyId,
+ secretAccessKey: props.location.secretAccessKey,
+ bucketName: props.location.bucketName,
+ endpointURL: props.location.endpointURL,
+ region: props.location.region
+ };
+ } else {
+ this.state = {
+ errorTextPath: false,
+ errorTextName: false,
+ disableConfirmButton: true,
+ cloudErrorTextName: false,
+ cloudErrorBucketName: false,
+ cloudErrorRegion: false,
+ cloudErrorAccessKey: false,
+ cloudErrorSecretAccessKey: false,
+ uuid: '',
+ name: '',
+ path: '',
+ endpointURL: '',
+ isDefault: false,
+ isReadOnly: false,
+ watchForChanges: false,
+ persistIndex: false,
+ fullTextIndex: false,
+ storeName: '',
+ accessKeyId: '',
+ secretAccessKey: '',
+ bucketName: '',
+ region: undefined,
+ storePath: '',
+ type: locationType.TYPE_LOCAL
+ };
+ }
+ }
+
+ /* componentWillReceiveProps = (nextProps: any) => {
if (nextProps.open === true && nextProps.location) {
const dir = nextProps.selectedDirectoryPath;
let properties;
@@ -142,7 +182,7 @@ class EditLocationDialog extends React.Component<Props, State> {
region: nextProps.location.region
});
}
- };
+ }; */
handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { target } = event;