Skip to content

Commit

Permalink
add user feedback
Browse files Browse the repository at this point in the history
so they know that something is happening
  • Loading branch information
mifi committed Mar 29, 2023
1 parent 80bd293 commit 4060019
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/@uppy/core/src/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default {
enterTextToSearch: 'Enter text to search for images',
search: 'Search',
emptyFolderAdded: 'No files were added from empty folder',
traversingSubfolders: 'Traversing %{numSubFolders} subfolder(s) inside "%{folder}"',
folderAlreadyAdded: 'The folder "%{folder}" was already added',
folderAdded: {
0: 'Added %{smart_count} file from %{folder}',
Expand Down
3 changes: 2 additions & 1 deletion packages/@uppy/provider-views/src/Loader.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { h } from 'preact'

export default ({ i18n }) => {
export default ({ i18n, loading }) => {
return (
<div className="uppy-Provider-loading">
<span>{i18n('loading')}</span>
{typeof loading === 'string' && <span>{loading}</span>}
</div>
)
}
15 changes: 10 additions & 5 deletions packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,24 @@ export default class ProviderView extends View {
}
}

async recursivelyListAllFiles (path, files = []) {
let curPath = path
async recursivelyListAllFiles (folder, files = []) {
let curPath = folder.requestPath

// need to repeat the list call until there are no more pages
while (curPath) {
const res = await this.provider.list(curPath)

const numSubFolders = res.items.filter((item) => item.isFolder).length
if (numSubFolders > 0) {
this.setLoading(this.plugin.uppy.i18n('traversingSubfolders', { numSubFolders, folder: folder.name }))
}

// limit concurrency (because what if we have a folder with 1000 folders inside!)
// todo this might still lead to a memory run-off
await pMap(res.items, async (item) => {
if (item.isFolder) {
// recursively call self for folder
await this.recursivelyListAllFiles(item.requestPath, files)
await this.recursivelyListAllFiles(item, files)
} else {
files.push(item)
}
Expand All @@ -268,7 +273,7 @@ export default class ProviderView extends View {
for (const file of currentSelection) {
if (file.isFolder) {
const folder = file
const filesInFolder = await this.recursivelyListAllFiles(folder.requestPath)
const filesInFolder = await this.recursivelyListAllFiles(folder)

// If the same folder is added again, we don't want to send
// X amount of duplicate file notifications, we want to say
Expand Down Expand Up @@ -369,7 +374,7 @@ export default class ProviderView extends View {
if (loading) {
return (
<CloseWrapper onUnmount={this.clearSelection}>
<LoaderView i18n={this.plugin.uppy.i18n} />
<LoaderView i18n={this.plugin.uppy.i18n} loading={loading} />
</CloseWrapper>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default class SearchProviderView extends View {
if (loading) {
return (
<CloseWrapper onUnmount={this.clearSelection}>
<LoaderView i18n={this.plugin.uppy.i18n} />
<LoaderView i18n={this.plugin.uppy.i18n} loading={loading} />
</CloseWrapper>
)
}
Expand Down

0 comments on commit 4060019

Please sign in to comment.