report.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. const html = require('choo/html');
  2. const raw = require('choo/html/raw');
  3. const assets = require('../../common/assets');
  4. const REPORTABLES = ['Malware', 'Pii', 'Abuse'];
  5. module.exports = function(state, emit) {
  6. let submitting = false;
  7. const file = state.fileInfo;
  8. if (!file) {
  9. return html`
  10. <main class="main">
  11. <section
  12. class="flex flex-col items-center justify-center h-full w-full p-6 md:p-8 overflow-hidden md:rounded-xl md:shadow-big"
  13. >
  14. <p class="text-xl text-center mb-4 leading-normal">
  15. ${state.translate('reportUnknownDescription')}
  16. </p>
  17. <p class="text-center">
  18. ${raw(
  19. replaceLinks(state.translate('reportReasonCopyright'), [
  20. 'https://www.mozilla.org/about/legal/report-infringement/'
  21. ])
  22. )}
  23. </p>
  24. </section>
  25. </main>
  26. `;
  27. }
  28. if (file.reported) {
  29. return html`
  30. <main class="main">
  31. <section
  32. class="flex flex-col items-center justify-center h-full w-full p-6 md:p-8 overflow-hidden md:rounded-xl md:shadow-big"
  33. >
  34. <h1 class="text-center text-3xl font-bold my-2">
  35. ${state.translate('reportedTitle')}
  36. </h1>
  37. <p class="max-w-md text-center leading-normal">
  38. ${state.translate('reportedDescription')}
  39. </p>
  40. <img src="${assets.get('notFound.svg')}" class="my-12" />
  41. <p class="my-5">
  42. <a href="/" class="btn rounded-lg flex items-center" role="button"
  43. >${state.translate('okButton')}</a
  44. >
  45. </p>
  46. </section>
  47. </main>
  48. `;
  49. }
  50. return html`
  51. <main class="main">
  52. <section
  53. class="relative h-full w-full p-6 md:p-8 md:rounded-xl md:shadow-big"
  54. >
  55. <div
  56. class="flex flex-col w-full max-w-sm h-full mx-auto items-center justify-center"
  57. >
  58. <h1 class="text-2xl font-bold mb-4">
  59. ${state.translate('reportFile')}
  60. </h1>
  61. <p class="mb-4 leading-normal font-semibold">
  62. ${state.translate('reportDescription')}
  63. </p>
  64. <form onsubmit="${report}" data-no-csrf>
  65. <fieldset onchange="${optionChanged}">
  66. <ul
  67. class="list-none p-4 mb-6 rounded-sm bg-grey-10 dark:bg-black"
  68. >
  69. ${REPORTABLES.map(
  70. reportable =>
  71. html`
  72. <li class="mb-2 leading-normal">
  73. <label
  74. for="${reportable.toLowerCase()}"
  75. class="flex items-center"
  76. >
  77. <input
  78. type="radio"
  79. name="reason"
  80. id="${reportable.toLowerCase()}"
  81. value="${reportable.toLowerCase()}"
  82. class="mr-2 my-2 w-4 h-4 flex-none"
  83. />
  84. ${state.translate(`reportReason${reportable}`)}
  85. </label>
  86. </li>
  87. `
  88. )}
  89. <li class="mt-4 mb-2 leading-normal">
  90. ${raw(
  91. replaceLinks(state.translate('reportReasonCopyright'), [
  92. 'https://www.mozilla.org/about/legal/report-infringement/'
  93. ])
  94. )}
  95. </li>
  96. </ul>
  97. </fieldset>
  98. <input
  99. type="submit"
  100. disabled
  101. class="btn rounded-lg w-full flex-shrink-0 focus:outline"
  102. title="${state.translate('reportButton')}"
  103. value="${state.translate('reportButton')}"
  104. />
  105. </form>
  106. </div>
  107. </section>
  108. </main>
  109. `;
  110. function optionChanged(event) {
  111. event.stopPropagation();
  112. const button = event.currentTarget.nextElementSibling;
  113. button.disabled = false;
  114. }
  115. function report(event) {
  116. event.stopPropagation();
  117. event.preventDefault();
  118. if (submitting) {
  119. return;
  120. }
  121. submitting = true;
  122. state.fileInfo.reported = true;
  123. const form = event.target;
  124. emit('report', { reason: form.reason.value });
  125. }
  126. function replaceLinks(str, urls) {
  127. let i = 0;
  128. const s = str.replace(
  129. /<a>([^<]+)<\/a>/g,
  130. (m, v) => `<a class="text-blue" href="${urls[i++]}">${v}</a>`
  131. );
  132. return `<p>${s}</p>`;
  133. }
  134. };