2018-08-16 18:07:12 +02:00
|
|
|
const html = require('choo/html');
|
2018-11-14 20:20:32 +01: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 18:07:12 +02:00
|
|
|
|
2018-11-14 20:20:32 +01:00
|
|
|
module.exports = function(state, emit) {
|
|
|
|
function onchange(event) {
|
2018-09-07 00:56:04 +02:00
|
|
|
event.preventDefault();
|
2018-11-14 20:20:32 +01:00
|
|
|
const newFiles = Array.from(event.target.files);
|
|
|
|
|
|
|
|
emit('addFiles', { files: newFiles });
|
2018-09-07 00:56:04 +02:00
|
|
|
}
|
2018-09-24 18:30:27 +02:00
|
|
|
|
2018-11-14 20:20:32 +01:00
|
|
|
function onclick() {
|
|
|
|
document.getElementById('file-upload').click();
|
|
|
|
}
|
2018-08-16 18:07:12 +02:00
|
|
|
|
2018-11-14 20:20:32 +01:00
|
|
|
const archives = state.storage.files
|
2018-11-16 21:30:15 +01:00
|
|
|
.filter(archive => !archive.expired)
|
2018-11-14 20:20:32 +01:00
|
|
|
.map(archive => archiveTile(state, emit, archive))
|
|
|
|
.reverse();
|
|
|
|
|
|
|
|
let content = '';
|
|
|
|
let button = html`
|
2018-12-13 17:36:03 +01:00
|
|
|
<div
|
|
|
|
class="bg-blue rounded-full m-4 flex items-center justify-center shadow-lg"
|
|
|
|
style="width: 56px; height: 56px"
|
2018-11-14 20:20:32 +01:00
|
|
|
onclick="${onclick}"
|
2018-12-13 17:36:03 +01:00
|
|
|
>
|
|
|
|
<img src="${assets.get('add.svg')}" />
|
|
|
|
</div>
|
2018-11-14 20:20:32 +01:00
|
|
|
`;
|
|
|
|
if (state.uploading) {
|
2019-03-08 22:04:46 +01:00
|
|
|
content = archiveTile.uploading(state, emit);
|
2019-01-16 16:26:52 +01:00
|
|
|
button = '';
|
2019-01-08 21:46:16 +01:00
|
|
|
} else if (state.archive.numFiles > 0) {
|
2019-03-08 22:04:46 +01:00
|
|
|
content = archiveTile.wip(state, emit);
|
2018-11-14 20:20:32 +01:00
|
|
|
button = '';
|
|
|
|
} else {
|
|
|
|
content =
|
|
|
|
archives.length < 1
|
|
|
|
? intro(state)
|
2019-06-14 20:30:43 +02:00
|
|
|
: list(archives, 'h-full overflow-y-auto w-full', 'mb-3 w-full');
|
2018-08-16 18:07:12 +02:00
|
|
|
}
|
2018-09-24 18:30:27 +02:00
|
|
|
|
2018-11-14 20:20:32 +01:00
|
|
|
return html`
|
2019-02-26 20:11:06 +01:00
|
|
|
<main class="main">
|
2019-03-08 22:04:46 +01:00
|
|
|
${state.modal && modal(state, emit)}
|
|
|
|
<section
|
|
|
|
class="h-full w-full p-6 z-10 overflow-hidden md:flex md:flex-row md:rounded-lg md:shadow-big"
|
|
|
|
>
|
|
|
|
${content}
|
|
|
|
</section>
|
2019-06-14 20:30:43 +02:00
|
|
|
<div class="fixed right-0 bottom-0 z-20">
|
2018-11-14 20:20:32 +01:00
|
|
|
${button}
|
|
|
|
<input
|
|
|
|
id="file-upload"
|
|
|
|
class="hidden"
|
|
|
|
type="file"
|
|
|
|
multiple
|
|
|
|
onchange="${onchange}"
|
|
|
|
onclick="${e => e.stopPropagation()}"
|
|
|
|
/>
|
2018-08-16 18:07:12 +02:00
|
|
|
</div>
|
2018-11-14 20:20:32 +01:00
|
|
|
</main>
|
|
|
|
`;
|
|
|
|
};
|