1
0
mirror of https://gitlab.com/timvisee/send.git synced 2024-11-15 07:32:48 +01:00
send/android/pages/home.js

70 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-08-16 18:07:12 +02:00
const html = require('choo/html');
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
module.exports = function(state, emit) {
function onchange(event) {
event.preventDefault();
const newFiles = Array.from(event.target.files);
emit('addFiles', { files: newFiles });
}
function onclick() {
document.getElementById('file-upload').click();
}
2018-08-16 18:07:12 +02:00
const archives = state.storage.files
2018-11-16 21:30:15 +01:00
.filter(archive => !archive.expired)
.map(archive => archiveTile(state, emit, archive))
.reverse();
let content = '';
let button = html`
<div
2019-09-09 19:34:55 +02:00
class="bg-blue-50 rounded-full m-4 flex items-center justify-center shadow-lg"
style="width: 56px; height: 56px"
onclick="${onclick}"
>
<img src="${assets.get('add.svg')}" />
</div>
`;
if (state.uploading) {
2019-03-08 22:04:46 +01:00
content = archiveTile.uploading(state, emit);
button = '';
} else if (state.archive.numFiles > 0) {
2019-03-08 22:04:46 +01:00
content = archiveTile.wip(state, emit);
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
}
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">
${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>
</main>
`;
};