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) {
|
2018-12-13 17:36:03 +01:00
|
|
|
content = html`
|
|
|
|
<div class="p-6 w-full">${archiveTile.uploading(state, emit)}</div>
|
|
|
|
`;
|
2019-01-08 21:46:16 +01:00
|
|
|
} else if (state.archive.numFiles > 0) {
|
2018-11-14 20:20:32 +01:00
|
|
|
content = archiveTile.wip(state, emit);
|
|
|
|
button = '';
|
|
|
|
} else {
|
|
|
|
content =
|
|
|
|
archives.length < 1
|
|
|
|
? intro(state)
|
2018-12-13 17:36:03 +01:00
|
|
|
: list(
|
|
|
|
archives,
|
|
|
|
'list-reset h-full overflow-y-scroll w-full p-6',
|
|
|
|
'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`
|
2018-12-13 17:36:03 +01:00
|
|
|
<main class="flex relative h-full w-full">
|
2018-11-14 20:20:32 +01:00
|
|
|
${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 18:07:12 +02:00
|
|
|
</div>
|
2018-11-14 20:20:32 +01:00
|
|
|
</main>
|
|
|
|
`;
|
|
|
|
};
|