Skip to content

Commit cd20d7f

Browse files
committed
feat: Show loading indicator on file assembling
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent 19aa6bd commit cd20d7f

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

l10n/messages.pot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ msgstr ""
6464
msgid "Last modified date unknown"
6565
msgstr ""
6666

67+
msgid "Merging uploaded chunks into a file"
68+
msgstr ""
69+
6770
msgid "New"
6871
msgstr ""
6972

lib/components/UploadPicker.vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@
126126
</template>
127127
</NcButton>
128128

129+
<div v-show="isAssembling" class="upload-picker__loading">
130+
<NcLoadingIcon />
131+
<p>{{ t('Merging uploaded chunks into a file') }}</p>
132+
</div>
133+
129134
<!-- Hidden files picker input -->
130135
<input ref="input"
131136
:accept="accept?.join?.(', ')"
@@ -144,14 +149,15 @@ import type { Upload } from '../upload.ts'
144149
145150
import { Folder, NewMenuEntryCategory, getNewFileMenuEntries } from '@nextcloud/files'
146151
import makeEta from 'simple-eta'
147-
import Vue from 'vue'
152+
import { defineComponent } from 'vue'
148153
149154
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
150155
import NcActionCaption from '@nextcloud/vue/dist/Components/NcActionCaption.js'
151156
import NcActionSeparator from '@nextcloud/vue/dist/Components/NcActionSeparator.js'
152157
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
153158
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
154159
import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'
160+
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
155161
import NcProgressBar from '@nextcloud/vue/dist/Components/NcProgressBar.js'
156162
157163
import IconCancel from 'vue-material-design-icons/Cancel.vue'
@@ -166,7 +172,7 @@ import { t } from '../utils/l10n.ts'
166172
import logger from '../utils/logger.ts'
167173
import { uploadConflictHandler } from '../utils/conflicts.ts'
168174
169-
export default Vue.extend({
175+
export default defineComponent({
170176
name: 'UploadPicker',
171177
172178
components: {
@@ -180,6 +186,7 @@ export default Vue.extend({
180186
NcActions,
181187
NcButton,
182188
NcIconSvgWrapper,
189+
NcLoadingIcon,
183190
NcProgressBar,
184191
},
185192
@@ -293,7 +300,7 @@ export default Vue.extend({
293300
return this.queue?.filter((upload: Upload) => upload.status === UploadStatus.FAILED).length !== 0
294301
},
295302
isUploading() {
296-
return this.queue?.length > 0
303+
return this.queue?.filter((upload: Upload) => upload.status === UploadStatus.UPLOADING).length !== 0
297304
},
298305
isAssembling() {
299306
return this.queue?.filter((upload: Upload) => upload.status === UploadStatus.ASSEMBLING).length !== 0
@@ -394,7 +401,6 @@ export default Vue.extend({
394401
return Array.isArray(this.content) ? this.content : await this.content(path)
395402
},
396403
397-
398404
/**
399405
* Start uploading
400406
*/
@@ -507,6 +513,12 @@ $progress-width: 200px;
507513
&--paused &__progress {
508514
animation: breathing 3s ease-out infinite normal;
509515
}
516+
517+
&__loading {
518+
display: flex;
519+
margin-left: 8px;
520+
gap: 8px;
521+
}
510522
}
511523
512524
@keyframes breathing {

lib/uploader.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,34 @@
22
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
import type { AxiosError, AxiosResponse } from 'axios'
6-
import type { WebDAVClient } from 'webdav'
7-
import type { IDirectory } from './utils/fileTree'
8-
9-
import { getCurrentUser } from '@nextcloud/auth'
10-
import { FileType, Folder, Permission, davGetClient, davRemoteURL, davRootPath } from '@nextcloud/files'
11-
import { encodePath } from '@nextcloud/paths'
12-
import { normalize } from 'path'
13-
14-
import axios, { isCancel } from '@nextcloud/axios'
5+
import type {AxiosError, AxiosResponse} from 'axios'
6+
import type {WebDAVClient} from 'webdav'
7+
import type {IDirectory} from './utils/fileTree'
8+
9+
import {getCurrentUser} from '@nextcloud/auth'
10+
import {
11+
davGetClient,
12+
davRemoteURL,
13+
davRootPath,
14+
FileType,
15+
Folder,
16+
Permission
17+
} from '@nextcloud/files'
18+
import {encodePath} from '@nextcloud/paths'
19+
import {normalize} from 'path'
20+
21+
import axios, {isCancel} from '@nextcloud/axios'
1522
import PCancelable from 'p-cancelable'
1623
import PQueue from 'p-queue'
1724

18-
import { getChunk, initChunkWorkspace, uploadData } from './utils/upload.js'
19-
import { getMaxChunksSize } from './utils/config.js'
20-
import { Status as UploadStatus, Upload } from './upload.js'
21-
import { isFileSystemFileEntry } from './utils/filesystem.js'
22-
import { Directory } from './utils/fileTree.js'
23-
import { t } from './utils/l10n.js'
25+
import {getChunk, initChunkWorkspace, uploadData} from './utils/upload.js'
26+
import {getMaxChunksSize} from './utils/config.js'
27+
import {Status as UploadStatus, Upload} from './upload.js'
28+
import {isFileSystemFileEntry} from './utils/filesystem.js'
29+
import {Directory} from './utils/fileTree.js'
30+
import {t} from './utils/l10n.js'
2431
import logger from './utils/logger.js'
25-
import { getCapabilities } from '@nextcloud/capabilities'
32+
import {getCapabilities} from '@nextcloud/capabilities'
2633

2734
export enum Status {
2835
IDLE = 0,
@@ -508,6 +515,11 @@ export class Uploader {
508515
await Promise.all(chunksQueue)
509516
this.updateStats()
510517

518+
// re-add upload because it was reset
519+
this._uploadQueue.push(upload)
520+
upload.status = UploadStatus.ASSEMBLING
521+
this.updateStats()
522+
511523
upload.response = await axios.request({
512524
method: 'MOVE',
513525
url: `${tempUrl}/.file`,
@@ -519,8 +531,9 @@ export class Uploader {
519531
},
520532
})
521533

522-
this.updateStats()
534+
this._uploadQueue.push(upload)
523535
upload.status = UploadStatus.FINISHED
536+
this.updateStats()
524537
logger.debug(`Successfully uploaded ${file.name}`, { file, upload })
525538
resolve(upload)
526539
} catch (error) {

0 commit comments

Comments
 (0)