home.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const html = require('choo/html');
  2. const { list } = require('../../app/utils');
  3. const archiveTile = require('../../app/ui/archiveTile');
  4. const modal = require('../../app/ui/modal');
  5. const intro = require('../../app/ui/intro');
  6. const assets = require('../../common/assets');
  7. module.exports = function(state, emit) {
  8. function onchange(event) {
  9. event.preventDefault();
  10. const newFiles = Array.from(event.target.files);
  11. emit('addFiles', { files: newFiles });
  12. }
  13. function onclick() {
  14. document.getElementById('file-upload').click();
  15. }
  16. const archives = state.storage.files
  17. .filter(archive => !archive.expired)
  18. .map(archive => archiveTile(state, emit, archive))
  19. .reverse();
  20. let content = '';
  21. let button = html`
  22. <div
  23. class="bg-blue rounded-full m-4 flex items-center justify-center shadow-lg"
  24. style="width: 56px; height: 56px"
  25. onclick="${onclick}"
  26. >
  27. <img src="${assets.get('add.svg')}" />
  28. </div>
  29. `;
  30. if (state.uploading) {
  31. content = archiveTile.uploading(state, emit);
  32. button = '';
  33. } else if (state.archive.numFiles > 0) {
  34. content = archiveTile.wip(state, emit);
  35. button = '';
  36. } else {
  37. content =
  38. archives.length < 1
  39. ? intro(state)
  40. : list(
  41. archives,
  42. 'list-reset h-full overflow-y-auto w-full',
  43. 'mb-3 w-full'
  44. );
  45. }
  46. return html`
  47. <main class="main">
  48. ${state.modal && modal(state, emit)}
  49. <section
  50. class="h-full w-full p-6 z-10 overflow-hidden md:flex md:flex-row md:rounded-lg md:shadow-big"
  51. >
  52. ${content}
  53. </section>
  54. <div class="fixed pin-r pin-b z-20">
  55. ${button}
  56. <input
  57. id="file-upload"
  58. class="hidden"
  59. type="file"
  60. multiple
  61. onchange="${onchange}"
  62. onclick="${e => e.stopPropagation()}"
  63. />
  64. </div>
  65. </main>
  66. `;
  67. };