drop.chapril.org-firefoxsend/app/templates/downloadButton/index.js

37 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-01-24 19:23:13 +01:00
const html = require('choo/html');
2018-07-31 20:09:18 +02:00
const percent = require('../../utils').percent;
2018-01-24 19:23:13 +01:00
module.exports = function(state, emit) {
2018-07-31 20:09:18 +02: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 21:56:53 +01:00
return html`
2018-07-31 20:09:18 +02:00
<button class="btn btn--download ${btnClass}"
onclick=${download}>
${btnText}
2018-02-16 21:56:53 +01:00
</button>`;
2018-01-24 19:23:13 +01:00
function download(event) {
event.preventDefault();
2018-07-31 20:09:18 +02:00
if (downloadState !== 'complete') {
emit('download', state.fileInfo);
}
2018-01-24 19:23:13 +01:00
}
};