2018-08-16 16:07:12 +00:00
|
|
|
const html = require('choo/html');
|
2018-11-14 19:20:32 +00:00
|
|
|
const { list } = require('../../app/utils');
|
|
|
|
const archiveTile = require('../../app/ui/archiveTile');
|
|
|
|
const modal = require('../../app/ui/modal');
|
|
|
|
const intro = require('../../app/ui/intro');
|
|
|
|
const assets = require('../../common/assets');
|
2018-08-16 16:07:12 +00:00
|
|
|
|
2018-11-14 19:20:32 +00:00
|
|
|
module.exports = function(state, emit) {
|
|
|
|
function onchange(event) {
|
2018-09-06 22:56:04 +00:00
|
|
|
event.preventDefault();
|
2018-11-14 19:20:32 +00:00
|
|
|
const newFiles = Array.from(event.target.files);
|
|
|
|
|
|
|
|
emit('addFiles', { files: newFiles });
|
2018-09-06 22:56:04 +00:00
|
|
|
}
|
2018-09-24 16:30:27 +00:00
|
|
|
|
2018-11-14 19:20:32 +00:00
|
|
|
function onclick() {
|
|
|
|
document.getElementById('file-upload').click();
|
|
|
|
}
|
2018-08-16 16:07:12 +00:00
|
|
|
|
2018-11-14 19:20:32 +00:00
|
|
|
const archives = state.storage.files
|
|
|
|
.map(archive => archiveTile(state, emit, archive))
|
|
|
|
.reverse();
|
|
|
|
|
|
|
|
let content = '';
|
|
|
|
let button = html`
|
|
|
|
<img
|
|
|
|
onclick="${onclick}"
|
|
|
|
style="padding: 1em"
|
|
|
|
src="${assets.get('addfile.svg')}"
|
|
|
|
/>
|
|
|
|
`;
|
|
|
|
if (state.uploading) {
|
|
|
|
content = archiveTile.uploading(state, emit);
|
|
|
|
} else if (state.archive) {
|
|
|
|
content = archiveTile.wip(state, emit);
|
|
|
|
button = '';
|
|
|
|
} else {
|
|
|
|
content =
|
|
|
|
archives.length < 1
|
|
|
|
? intro(state)
|
|
|
|
: list(archives, 'list-reset h-full overflow-y-scroll', 'mb-3');
|
2018-08-16 16:07:12 +00:00
|
|
|
}
|
2018-09-24 16:30:27 +00:00
|
|
|
|
2018-11-14 19:20:32 +00:00
|
|
|
return html`
|
|
|
|
<main class="main relative">
|
|
|
|
${state.modal && modal(state, emit)} ${content}
|
|
|
|
<div class="fixed pin-r pin-b">
|
|
|
|
${button}
|
|
|
|
<input
|
|
|
|
id="file-upload"
|
|
|
|
class="hidden"
|
|
|
|
type="file"
|
|
|
|
multiple
|
|
|
|
onchange="${onchange}"
|
|
|
|
onclick="${e => e.stopPropagation()}"
|
|
|
|
/>
|
2018-08-16 16:07:12 +00:00
|
|
|
</div>
|
2018-11-14 19:20:32 +00:00
|
|
|
</main>
|
|
|
|
`;
|
|
|
|
};
|