home.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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-50 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(archives, 'h-full overflow-y-auto w-full', 'mb-3 w-full');
  41. }
  42. return html`
  43. <main class="main">
  44. ${state.modal && modal(state, emit)}
  45. <section
  46. class="h-full w-full p-6 z-10 overflow-hidden md:flex md:flex-row md:rounded-lg md:shadow-big"
  47. >
  48. ${content}
  49. </section>
  50. <div class="fixed right-0 bottom-0 z-20">
  51. ${button}
  52. <input
  53. id="file-upload"
  54. class="hidden"
  55. type="file"
  56. multiple
  57. onchange="${onchange}"
  58. onclick="${e => e.stopPropagation()}"
  59. />
  60. </div>
  61. </main>
  62. `;
  63. };