const html = require('choo/html');
const raw = require('choo/html/raw');
const assets = require('../../common/assets');
const { bytes, copyToClipboard, list, percent, timeLeft } = require('../utils');
const expiryOptions = require('./expiryOptions');
function expiryInfo(translate, archive) {
const l10n = timeLeft(archive.expiresAt - Date.now());
return raw(
translate('frontPageExpireInfo', {
downloadCount: translate('downloadCount', {
num: archive.dlimit - archive.dtotal
}),
timespan: translate(l10n.id, l10n)
})
);
}
function fileInfo(file, action) {
return html`
${file.name}
${bytes(file.size)}
${file.type}
${action}
`;
}
function archiveDetails(translate, archive) {
if (archive.manifest.files.length > 1) {
return html`
${translate('fileCount', {
num: archive.manifest.files.length
})}
${list(archive.manifest.files.map(f => fileInfo(f)), 'list-reset')}
`;
}
}
module.exports = function(state, emit, archive) {
return html`
${archive.name}
${bytes(archive.size)}
${expiryInfo(state.translate, archive)}
${archiveDetails(state.translate, archive)}
`;
function copy(event) {
event.stopPropagation();
copyToClipboard(archive.url);
}
function del(event) {
event.stopPropagation();
emit('delete', { file: archive, location: 'success-screen' });
}
};
module.exports.wip = function(state, emit) {
return html`
${list(
state.archive.files.map(f => fileInfo(f, remove(f))),
'list-reset h-full overflow-y-scroll'
)}
${expiryOptions(state, emit)}
`;
function upload(event) {
event.preventDefault();
event.target.disabled = true;
if (!state.uploading) {
emit('upload', {
type: 'click',
dlimit: state.downloadCount || 1,
password: state.password
});
}
}
function add(event) {
event.preventDefault();
const newFiles = Array.from(event.target.files);
emit('addFiles', { files: newFiles });
}
function remove(file) {
return html`
`;
function del(event) {
event.stopPropagation();
emit('removeUpload', file);
}
}
};
module.exports.uploading = function(state, emit) {
const progress = state.transfer.progressRatio;
const progressPercent = percent(progress);
const archive = state.archive;
return html`
${archive.name}
${bytes(archive.size)}
${expiryInfo(state.translate, {
dlimit: state.downloadCount || 1,
dtotal: 0,
expiresAt: Date.now() + 500 + state.timeLimit * 1000
})}
${progressPercent}
`;
function cancel(event) {
event.stopPropagation();
event.target.disabled = true;
emit('cancel');
}
};
module.exports.empty = function(state, emit) {
return html`
${state.translate('uploadDropDragMessage')}
`;
function add(event) {
event.preventDefault();
const newFiles = Array.from(event.target.files);
emit('addFiles', { files: newFiles });
}
};
module.exports.preview = function(state, emit) {
const archive = state.fileInfo;
return html`
${archive.name}
${bytes(archive.size)}
${archiveDetails(state.translate, archive)}
`;
function download(event) {
event.preventDefault();
event.target.disabled = true;
emit('download', archive);
}
};
module.exports.downloading = function(state, emit) {
const archive = state.fileInfo;
const progress = state.transfer.progressRatio;
const progressPercent = percent(progress);
return html`
${archive.name}
${bytes(archive.size)}
${progressPercent}
`;
function cancel(event) {
event.preventDefault();
event.target.disabled = true;
emit('download', archive);
}
};