Skip to content

Commit

Permalink
Show loading indicator on file assembling
Browse files Browse the repository at this point in the history
Signed-off-by: Kostiantyn Miakshyn <[email protected]>
  • Loading branch information
Koc committed Oct 27, 2024
1 parent 19aa6bd commit c468ae8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
20 changes: 16 additions & 4 deletions lib/components/UploadPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
</template>
</NcButton>

<div v-show="isAssembling" class="upload-picker__loading">
<NcLoadingIcon />
<p>{{ t('Merging uploaded chunks into a file') }}</p>
</div>

<!-- Hidden files picker input -->
<input ref="input"
:accept="accept?.join?.(', ')"
Expand All @@ -144,14 +149,15 @@ import type { Upload } from '../upload.ts'
import { Folder, NewMenuEntryCategory, getNewFileMenuEntries } from '@nextcloud/files'
import makeEta from 'simple-eta'
import Vue from 'vue'
import { defineComponent } from 'vue'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActionCaption from '@nextcloud/vue/dist/Components/NcActionCaption.js'
import NcActionSeparator from '@nextcloud/vue/dist/Components/NcActionSeparator.js'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
import NcProgressBar from '@nextcloud/vue/dist/Components/NcProgressBar.js'
import IconCancel from 'vue-material-design-icons/Cancel.vue'
Expand All @@ -166,7 +172,7 @@ import { t } from '../utils/l10n.ts'
import logger from '../utils/logger.ts'
import { uploadConflictHandler } from '../utils/conflicts.ts'
export default Vue.extend({
export default defineComponent({
name: 'UploadPicker',
components: {
Expand All @@ -180,6 +186,7 @@ export default Vue.extend({
NcActions,
NcButton,
NcIconSvgWrapper,
NcLoadingIcon,
NcProgressBar,
},
Expand Down Expand Up @@ -293,7 +300,7 @@ export default Vue.extend({
return this.queue?.filter((upload: Upload) => upload.status === UploadStatus.FAILED).length !== 0
},
isUploading() {
return this.queue?.length > 0
return this.queue?.filter((upload: Upload) => upload.status === UploadStatus.UPLOADING).length !== 0

Check warning on line 303 in lib/components/UploadPicker.vue

View check run for this annotation

Codecov / codecov/patch

lib/components/UploadPicker.vue#L303

Added line #L303 was not covered by tests
},
isAssembling() {
return this.queue?.filter((upload: Upload) => upload.status === UploadStatus.ASSEMBLING).length !== 0
Expand Down Expand Up @@ -394,7 +401,6 @@ export default Vue.extend({
return Array.isArray(this.content) ? this.content : await this.content(path)
},
/**
* Start uploading
*/
Expand Down Expand Up @@ -507,6 +513,12 @@ $progress-width: 200px;
&--paused &__progress {
animation: breathing 3s ease-out infinite normal;
}
&__loading {
display: flex;
margin-left: 8px;
gap: 8px;
}
}
@keyframes breathing {
Expand Down
49 changes: 31 additions & 18 deletions lib/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { AxiosError, AxiosResponse } from 'axios'
import type { WebDAVClient } from 'webdav'
import type { IDirectory } from './utils/fileTree'

import { getCurrentUser } from '@nextcloud/auth'
import { FileType, Folder, Permission, davGetClient, davRemoteURL, davRootPath } from '@nextcloud/files'
import { encodePath } from '@nextcloud/paths'
import { normalize } from 'path'

import axios, { isCancel } from '@nextcloud/axios'
import type {AxiosError, AxiosResponse} from 'axios'
import type {WebDAVClient} from 'webdav'
import type {IDirectory} from './utils/fileTree'

import {getCurrentUser} from '@nextcloud/auth'
import {
davGetClient,
davRemoteURL,
davRootPath,
FileType,
Folder,
Permission
} from '@nextcloud/files'
import {encodePath} from '@nextcloud/paths'
import {normalize} from 'path'

import axios, {isCancel} from '@nextcloud/axios'
import PCancelable from 'p-cancelable'
import PQueue from 'p-queue'

import { getChunk, initChunkWorkspace, uploadData } from './utils/upload.js'
import { getMaxChunksSize } from './utils/config.js'
import { Status as UploadStatus, Upload } from './upload.js'
import { isFileSystemFileEntry } from './utils/filesystem.js'
import { Directory } from './utils/fileTree.js'
import { t } from './utils/l10n.js'
import {getChunk, initChunkWorkspace, uploadData} from './utils/upload.js'
import {getMaxChunksSize} from './utils/config.js'
import {Status as UploadStatus, Upload} from './upload.js'
import {isFileSystemFileEntry} from './utils/filesystem.js'
import {Directory} from './utils/fileTree.js'
import {t} from './utils/l10n.js'
import logger from './utils/logger.js'
import { getCapabilities } from '@nextcloud/capabilities'
import {getCapabilities} from '@nextcloud/capabilities'

export enum Status {
IDLE = 0,
Expand Down Expand Up @@ -508,6 +515,11 @@ export class Uploader {
await Promise.all(chunksQueue)
this.updateStats()

// re-add upload because it was reset
this._uploadQueue.push(upload)
upload.status = UploadStatus.ASSEMBLING
this.updateStats()

Check warning on line 521 in lib/uploader.ts

View check run for this annotation

Codecov / codecov/patch

lib/uploader.ts#L519-L521

Added lines #L519 - L521 were not covered by tests

upload.response = await axios.request({
method: 'MOVE',
url: `${tempUrl}/.file`,
Expand All @@ -519,8 +531,9 @@ export class Uploader {
},
})

this.updateStats()
this._uploadQueue.push(upload)

Check warning on line 534 in lib/uploader.ts

View check run for this annotation

Codecov / codecov/patch

lib/uploader.ts#L534

Added line #L534 was not covered by tests
upload.status = UploadStatus.FINISHED
this.updateStats()

Check warning on line 536 in lib/uploader.ts

View check run for this annotation

Codecov / codecov/patch

lib/uploader.ts#L536

Added line #L536 was not covered by tests
logger.debug(`Successfully uploaded ${file.name}`, { file, upload })
resolve(upload)
} catch (error) {
Expand Down

0 comments on commit c468ae8

Please sign in to comment.