Skip to content

Commit

Permalink
[NEW] Add loading animation to webdav file picker (#14759)
Browse files Browse the repository at this point in the history
  • Loading branch information
ubarsaiyan authored and ggazzo committed Jun 19, 2019
1 parent d7a9968 commit 86eb9f6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 29 deletions.
4 changes: 4 additions & 0 deletions app/theme/client/imports/general/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ button {
animation-delay: -0.16s;
}

.file-picker-loading .loading-animation > .bounce {
background-color: #444444;
}

@keyframes loading-bouncedelay {
0%,
80%,
Expand Down
38 changes: 22 additions & 16 deletions app/webdav/client/webdavFilePicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,28 @@
</div>
</li>
{{/if}}
{{#each webdavNodes}}
<li class="attachments__item webdav_{{this.type}}">
{{#with iconType}}
<div class="attachments__thumb attachments__file--{{type}}">
{{>icon icon=icon}}
<div class="attachments__type">{{extension}}</div>
</div>
{{/with}}
<a title="{{this.basename}}" target="_blank" class="attachments__item">
<div class="attachments__content">
<div class="attachments__name">{{this.basename}}</div>
<div class="attachments__details">{{this.lastmod}}</div>
</div>
</a>
</li>
{{/each}}
{{#if isLoading}}
<div class="file-picker-loading">
{{> loading}}
</div>
{{else}}
{{#each webdavNodes}}
<li class="attachments__item webdav_{{this.type}}">
{{#with iconType}}
<div class="attachments__thumb attachments__file--{{type}}">
{{>icon icon=icon}}
<div class="attachments__type">{{extension}}</div>
</div>
{{/with}}
<a title="{{this.basename}}" target="_blank" class="attachments__item">
<div class="attachments__content">
<div class="attachments__name">{{this.basename}}</div>
<div class="attachments__details">{{this.lastmod}}</div>
</div>
</a>
</li>
{{/each}}
{{/if}}
</ul>
</div>
</template>
45 changes: 32 additions & 13 deletions app/webdav/client/webdavFilePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import _ from 'underscore';
import toastr from 'toastr';
import { Session } from 'meteor/session';
import { Handlebars } from 'meteor/ui';
import { ReactiveVar } from 'meteor/reactive-var';

import { modal, call } from '../../ui-utils';
import { t } from '../../utils';
Expand All @@ -18,10 +19,13 @@ Template.webdavFilePicker.rendered = async function() {
return toastr.error(t(response.message));
}
Session.set('webdavNodes', response.data);
this.isLoading.set(false);
};

Template.webdavFilePicker.destroyed = function() {
Session.set('webdavNodes', []);
};

Template.webdavFilePicker.helpers({
iconType() {
// add icon for different types
Expand Down Expand Up @@ -52,16 +56,22 @@ Template.webdavFilePicker.helpers({
}
return { icon, type, extension };
},
isLoading() {
return Template.instance().isLoading.get();
},
webdavNodes() {
return Session.get('webdavNodes');
},
webdavCurrentFolder() {
return Session.get('webdavCurrentFolder');
},
});

Template.webdavFilePicker.events({
async 'click #webdav-go-back'() {
const { accountId } = Template.instance().data;
const instance = Template.instance();
const { accountId } = instance.data;
instance.isLoading.set(true);
let currentFolder = Session.get('webdavCurrentFolder');

// determine parent directory to go back
Expand All @@ -75,16 +85,20 @@ Template.webdavFilePicker.events({
Session.set('webdavCurrentFolder', parentFolder);
Session.set('webdavNodes', []);
const response = await call('getWebdavFileList', accountId, parentFolder);
instance.isLoading.set(false);
if (!response.success) {
return toastr.error(t(response.message));
}
Session.set('webdavNodes', response.data);
},
async 'click .webdav_directory'() {
const { accountId } = Template.instance().data;
const instance = Template.instance();
const { accountId } = instance.data;
instance.isLoading.set(true);
Session.set('webdavCurrentFolder', this.filename);
Session.set('webdavNodes', []);
const response = await call('getWebdavFileList', accountId, this.filename);
instance.isLoading.set(false);
if (!response.success) {
modal.close();
return toastr.error(t(response.message));
Expand All @@ -93,10 +107,12 @@ Template.webdavFilePicker.events({
},
async 'click .webdav_file'() {
const roomId = Session.get('openedRoom');
const { accountId } = Template.instance().data;
const instance = Template.instance();
const { accountId } = instance.data;
instance.isLoading.set(true);
const file = this;
const response = await call('getFileFromWebdav', accountId, file);

instance.isLoading.set(false);
if (!response.success) {
modal.close();
return toastr.error(t('Failed_to_get_webdav_file'));
Expand All @@ -106,15 +122,14 @@ Template.webdavFilePicker.events({
blob.lastModified = file.lastmod;
blob.name = file.basename;
const text = `
<div class='upload-preview-title'>
<div class="rc-input__wrapper">
<input class="rc-input__element" id='file-name' style='display: inherit;' value='${ Handlebars._escape(blob.name) }' placeholder='${ t('Upload_file_name') }'>
</div>
<div class="rc-input__wrapper">
<input class="rc-input__element" id='file-description' style='display: inherit;' value='' placeholder='${ t('Upload_file_description') }'>
</div>
</div>`;

<div class='upload-preview-title'>
<div class="rc-input__wrapper">
<input class="rc-input__element" id='file-name' style='display: inherit;' value='${ Handlebars._escape(blob.name) }' placeholder='${ t('Upload_file_name') }'>
</div>
<div class="rc-input__wrapper">
<input class="rc-input__element" id='file-description' style='display: inherit;' value='' placeholder='${ t('Upload_file_description') }'>
</div>
</div>`;
return modal.open({
title: t('Upload_file_question'),
text,
Expand Down Expand Up @@ -200,3 +215,7 @@ Template.webdavFilePicker.events({
});
},
});

Template.webdavFilePicker.onCreated(function() {
this.isLoading = new ReactiveVar(true);
});

0 comments on commit 86eb9f6

Please sign in to comment.