Skip to content

Commit b27ca78

Browse files
committed
fix: Add throttling to createFolderCallback
1 parent 035cffb commit b27ca78

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/elements/content-explorer/ContentExplorer.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import debounce from 'lodash/debounce';
66
import flow from 'lodash/flow';
77
import getProp from 'lodash/get';
88
import noop from 'lodash/noop';
9+
import throttle from 'lodash/throttle';
910
import uniqueid from 'lodash/uniqueId';
1011
import { TooltipProvider } from '@box/blueprint-web';
1112
import { AxiosRequestConfig, AxiosResponse } from 'axios';
@@ -1170,16 +1171,6 @@ class ContentExplorer extends Component<ContentExplorerProps, State> {
11701171
);
11711172
};
11721173

1173-
/**
1174-
* Creates a new folder
1175-
*
1176-
* @private
1177-
* @return {void}
1178-
*/
1179-
createFolder = (): void => {
1180-
this.createFolderCallback();
1181-
};
1182-
11831174
/**
11841175
* New folder callback
11851176
*
@@ -1243,6 +1234,22 @@ class ContentExplorer extends Component<ContentExplorerProps, State> {
12431234
);
12441235
};
12451236

1237+
/**
1238+
* Throttled version of createFolderCallback to prevent errors from rapid clicking.
1239+
* @param {string} [name] - folder name
1240+
*/
1241+
throttledCreateFolderCallback = throttle(this.createFolderCallback, 500);
1242+
1243+
/**
1244+
* Creates a new folder
1245+
*
1246+
* @private
1247+
* @return {void}
1248+
*/
1249+
createFolder = (): void => {
1250+
this.throttledCreateFolderCallback();
1251+
};
1252+
12461253
/**
12471254
* Selects the clicked file and then shares it
12481255
*
@@ -1738,7 +1745,7 @@ class ContentExplorer extends Component<ContentExplorerProps, State> {
17381745
{allowCreate && !!this.appElement ? (
17391746
<CreateFolderDialog
17401747
isOpen={isCreateFolderModalOpen}
1741-
onCreate={this.createFolderCallback}
1748+
onCreate={this.throttledCreateFolderCallback}
17421749
onCancel={this.closeModals}
17431750
isLoading={isLoading}
17441751
errorCode={errorCode}

0 commit comments

Comments
 (0)