fox-send/app/templates/downloadButton/index.js

37 lines
1.0 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`
2018-07-31 18:09:18 +00:00
<button class="btn btn--download ${btnClass}"
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();
2018-07-31 18:09:18 +00:00
if (downloadState !== 'complete') {
emit('download', state.fileInfo);
}
2018-01-24 18:23:13 +00:00
}
};