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

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-07-31 18:09:18 +00:00
const html = require('choo/html');
const assets = require('../../../common/assets');
const bytes = require('../../utils').bytes;
const fileIcon = require('../fileIcon');
2018-08-03 19:24:41 +00:00
module.exports = function(file, index, state, emit, hasPassword) {
2018-07-31 18:09:18 +00:00
const transfer = state.transfer;
const transferState = transfer ? transfer.state : null;
const share = state.route.includes('share/');
const complete = share ? 'uploadedFile--completed' : '';
const cancelVisible =
2018-07-31 22:19:18 +00:00
state.route === '/' && !state.uploading
? 'uploadedFile__cancel--visible'
: '';
2018-07-31 18:09:18 +00:00
const stampClass =
share || transferState === 'complete' ? 'uploadedFile__stamp--visible' : '';
function cancel(event) {
event.preventDefault();
2018-07-31 22:19:18 +00:00
if (state.route === '/') {
2018-08-03 19:24:41 +00:00
emit('removeUpload', { index });
2018-07-31 18:09:18 +00:00
}
}
return html`
<li class="uploadedFile ${complete}" id="${file.id}"
>
2018-08-03 19:24:41 +00:00
${fileIcon(file.name, hasPassword)}
2018-07-31 18:09:18 +00:00
<div class="uploadedFile__cancel ${cancelVisible}"
onclick=${cancel}>
<img
src="${assets.get('close-16.svg')}"
alt="cancel"/>
</div>
<div class="uploadedFile__fileData">
<p class="uploadedFile__fileName">${file.name}</p>
<p class="uploadedFile__fileInfo">
<span>${bytes(file.size)}</span>
</p>
</div>
<img src="${assets.get('sent-done.svg')}"
class="uploadedFile__stamp ${stampClass}"/>
</li>
`;
};