send/app/templates/downloadButton/index.js

38 lines
1 KiB
JavaScript
Raw Normal View History

2018-01-24 18:23:13 +00:00
const html = require('choo/html');
2018-07-31 18:09:18 +00:00
const percent = require('../../utils').percent;
2018-01-24 18:23:13 +00:00
module.exports = function(state, emit) {
2018-07-31 18:09:18 +00:00
const downloadState = state.transfer.state;
const progress = percent(state.transfer.progressRatio);
let btnText = '';
let btnClass = '';
if (downloadState === 'complete') {
btnText = state.translate('downloadFinish');
btnClass = 'btn--complete';
} else if (downloadState === 'decrypting') {
btnText = state.translate('decryptingFile');
btnClass = 'btn--blueStripes';
} else if (downloadState === 'downloading') {
btnText = state.translate('downloadProgressButton', { progress });
btnClass = 'btn--blueStripes';
} else {
btnText = state.translate('downloadButtonLabel');
}
2018-02-16 20:56:53 +00:00
return html`
<button class="btn btn--download ${btnClass}"
2018-07-31 18:09:18 +00:00
onclick=${download}>
${btnText}
2018-02-16 20:56:53 +00:00
</button>`;
2018-01-24 18:23:13 +00:00
function download(event) {
event.preventDefault();
event.target.disabled = true;
if (downloadState === 'ready') {
2018-07-31 18:09:18 +00:00
emit('download', state.fileInfo);
}
2018-01-24 18:23:13 +00:00
}
};