noStreams.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. const html = require('choo/html');
  2. const { bytes } = require('../utils');
  3. const assets = require('../../common/assets');
  4. module.exports = function(state, emit) {
  5. const archive = state.fileInfo;
  6. return html`
  7. <div
  8. class="flex flex-col w-full max-w-md h-full mx-auto items-center justify-center"
  9. >
  10. <h1 class="mb-4 text-3xl font-bold">${state.translate(
  11. 'downloadTitle'
  12. )}</h1>
  13. <p
  14. class="w-full p-2 border border-yellow-50 rounded md:w-4/5 text-orange-60 bg-yellow-40 text-center leading-normal"
  15. >
  16. ⚠️ ${state.translate('noStreamsWarning')} ⚠️
  17. </p>
  18. <form class="md:w-128" onsubmit=${submit}>
  19. <fieldset class="border rounded p-4 my-4" onchange=${optionChanged}>
  20. <div class="flex items-center mb-2">
  21. <img class="mr-3 flex-shrink-0" src="${assets.get(
  22. 'blue_file.svg'
  23. )}"/>
  24. <p class="flex-grow">
  25. <h1 class="text-base font-medium word-break-all">${
  26. archive.name
  27. }</h1>
  28. <div class="text-sm font-normal opacity-75 pt-1">${bytes(
  29. archive.size
  30. )}</div>
  31. </p>
  32. </div>
  33. <div class=" mt-6 mb-3">
  34. <input class="mx-2" type="radio" name="gus" id="copy" value="copy" checked>
  35. <label class="" for="copy">${state.translate(
  36. 'noStreamsOptionCopy'
  37. )}</label>
  38. </div>
  39. <div class="my-3">
  40. <input class="mx-2" type="radio" name="gus" id="firefox" value="firefox">
  41. <label class="" for="firefox">${state.translate(
  42. 'noStreamsOptionFirefox'
  43. )}</label>
  44. </div>
  45. <div class="mt-3">
  46. <input class="mx-2" type="radio" name="gus" id="download" value="download">
  47. <label class="" for="download">${state.translate(
  48. 'noStreamsOptionDownload'
  49. )}</label>
  50. </div>
  51. </fieldset>
  52. <input
  53. class="btn rounded-lg w-full flex flex-shrink-0 items-center justify-center"
  54. value="${state.translate('copyLinkButton')}"
  55. title="${state.translate('copyLinkButton')}"
  56. type="submit" />
  57. </form>
  58. </div>
  59. `;
  60. function optionChanged(event) {
  61. event.stopPropagation();
  62. const choice = event.target.value;
  63. const button = event.currentTarget.nextElementSibling;
  64. let title = button.title;
  65. switch (choice) {
  66. case 'copy':
  67. title = state.translate('copyLinkButton');
  68. break;
  69. case 'firefox':
  70. title = state.translate('downloadFirefox');
  71. break;
  72. case 'download':
  73. title = state.translate('downloadButtonLabel');
  74. break;
  75. }
  76. button.title = title;
  77. button.value = title;
  78. }
  79. function submit(event) {
  80. const action = document.querySelector('input[type="radio"]:checked').value;
  81. switch (action) {
  82. case 'copy':
  83. emit('copy', { url: window.location.href });
  84. document.querySelector('input[type="submit"]').value = state.translate(
  85. 'copiedUrl'
  86. );
  87. break;
  88. case 'firefox':
  89. window.open(
  90. 'https://www.mozilla.org/firefox/new/?utm_campaign=send-acquisition&utm_medium=referral&utm_source=send.firefox.com'
  91. );
  92. break;
  93. case 'download':
  94. emit('download', archive);
  95. break;
  96. }
  97. return false;
  98. }
  99. };