Skip to content

Commit e88f321

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

4 files changed

Lines changed: 37 additions & 9 deletions

File tree

cypress/components/UploadPicker/UploadPicker.cy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('UploadPicker rendering', () => {
3939
}
4040
cy.mount(UploadPicker, { propsData })
4141
cy.get('[data-cy-upload-picker]').should('be.visible')
42-
cy.get('[data-cy-upload-picker]').shouldHaveTrimmedText('New')
42+
cy.get('[data-cy-upload-picker]').shouldHaveTrimmedText('New Processing...')
4343
cy.get('[data-cy-upload-picker] [data-cy-upload-picker-input]').should('exist')
4444
})
4545

@@ -68,7 +68,7 @@ describe('UploadPicker valid uploads', () => {
6868
cy.mount(UploadPicker, { propsData }).as('uploadPicker')
6969

7070
// Label is displayed before upload
71-
cy.get('[data-cy-upload-picker]').shouldHaveTrimmedText('New')
71+
cy.get('[data-cy-upload-picker]').shouldHaveTrimmedText('New Processing...')
7272

7373
// Check and init aliases
7474
cy.get('[data-cy-upload-picker] [data-cy-upload-picker-input]').as('input').should('exist')
@@ -108,7 +108,7 @@ describe('UploadPicker valid uploads', () => {
108108
.should('not.be.visible')
109109

110110
// Label is displayed again after upload
111-
cy.get('[data-cy-upload-picker] button').shouldHaveTrimmedText('New')
111+
cy.get('[data-cy-upload-picker] button').shouldHaveTrimmedText('New Processing...')
112112
})
113113
})
114114
})

l10n/messages.pot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ msgstr ""
7979
msgid "Preview image"
8080
msgstr ""
8181

82+
msgid "Processing..."
83+
msgstr ""
84+
8285
msgid "Rename"
8386
msgstr ""
8487

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="!isUploading && isAssembling" class="upload-picker__loading">
130+
<NcLoadingIcon />
131+
<p>{{ t('Processing...') }}</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: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ import type { WebDAVClient } from 'webdav'
77
import type { IDirectory } from './utils/fileTree'
88

99
import { getCurrentUser } from '@nextcloud/auth'
10-
import { FileType, Folder, Permission, davGetClient, davRemoteURL, davRootPath } from '@nextcloud/files'
10+
import {
11+
davGetClient,
12+
davRemoteURL,
13+
davRootPath,
14+
FileType,
15+
Folder,
16+
Permission,
17+
} from '@nextcloud/files'
1118
import { encodePath } from '@nextcloud/paths'
1219
import { normalize } from 'path'
1320

@@ -509,6 +516,11 @@ export class Uploader {
509516
await Promise.all(chunksQueue)
510517
this.updateStats()
511518

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

523-
this.updateStats()
535+
this._uploadQueue.push(upload)
524536
upload.status = UploadStatus.FINISHED
537+
this.updateStats()
525538
logger.debug(`Successfully uploaded ${file.name}`, { file, upload })
526539
resolve(upload)
527540
} catch (error) {

0 commit comments

Comments
 (0)