Skip to content

Commit

Permalink
feat: Show loading indicator on file assembling
Browse files Browse the repository at this point in the history
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
  • Loading branch information
Koc committed Dec 17, 2024
1 parent 070d762 commit 58e4d3f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
3 changes: 3 additions & 0 deletions l10n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ msgstr ""
msgid "Preview image"
msgstr ""

msgid "Processing..."
msgstr ""

msgid "Rename"
msgstr ""

Expand Down
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="!isUploading && isAssembling" class="upload-picker__loading">
<NcLoadingIcon />
<p>{{ t('Processing...') }}</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
},
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
17 changes: 15 additions & 2 deletions lib/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ 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 {
davGetClient,
davRemoteURL,
davRootPath,
FileType,
Folder,
Permission,
} from '@nextcloud/files'
import { encodePath } from '@nextcloud/paths'
import { normalize } from 'path'

Expand Down Expand Up @@ -512,6 +519,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()

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

this.updateStats()
this._uploadQueue.push(upload)
upload.status = UploadStatus.FINISHED
this.updateStats()
logger.debug(`Successfully uploaded ${file.name}`, { file, upload })
resolve(upload)
} catch (error) {
Expand Down

0 comments on commit 58e4d3f

Please sign in to comment.