123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- const html = require('choo/html');
- const raw = require('choo/html/raw');
- const assets = require('../../common/assets');
- const REPORTABLES = ['Malware', 'Pii', 'Abuse'];
- module.exports = function(state, emit) {
- let submitting = false;
- const file = state.fileInfo;
- if (!file) {
- return html`
- <main class="main">
- <section
- 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"
- >
- <p class="text-xl text-center mb-4 leading-normal">
- ${state.translate('reportUnknownDescription')}
- </p>
- <p class="text-center">
- ${raw(
- replaceLinks(state.translate('reportReasonCopyright'), [
- 'https://www.mozilla.org/about/legal/report-infringement/'
- ])
- )}
- </p>
- </section>
- </main>
- `;
- }
- if (file.reported) {
- return html`
- <main class="main">
- <section
- 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"
- >
- <h1 class="text-center text-3xl font-bold my-2">
- ${state.translate('reportedTitle')}
- </h1>
- <p class="max-w-md text-center leading-normal">
- ${state.translate('reportedDescription')}
- </p>
- <img src="${assets.get('notFound.svg')}" class="my-12" />
- <p class="my-5">
- <a href="/" class="btn rounded-lg flex items-center" role="button"
- >${state.translate('okButton')}</a
- >
- </p>
- </section>
- </main>
- `;
- }
- return html`
- <main class="main">
- <section
- class="relative h-full w-full p-6 md:p-8 md:rounded-xl md:shadow-big"
- >
- <div
- class="flex flex-col w-full max-w-sm h-full mx-auto items-center justify-center"
- >
- <h1 class="text-2xl font-bold mb-4">
- ${state.translate('reportFile')}
- </h1>
- <p class="mb-4 leading-normal font-semibold">
- ${state.translate('reportDescription')}
- </p>
- <form onsubmit="${report}" data-no-csrf>
- <fieldset onchange="${optionChanged}">
- <ul
- class="list-none p-4 mb-6 rounded-sm bg-grey-10 dark:bg-black"
- >
- ${REPORTABLES.map(
- reportable =>
- html`
- <li class="mb-2 leading-normal">
- <label
- for="${reportable.toLowerCase()}"
- class="flex items-center"
- >
- <input
- type="radio"
- name="reason"
- id="${reportable.toLowerCase()}"
- value="${reportable.toLowerCase()}"
- class="mr-2 my-2 w-4 h-4 flex-none"
- />
- ${state.translate(`reportReason${reportable}`)}
- </label>
- </li>
- `
- )}
- <li class="mt-4 mb-2 leading-normal">
- ${raw(
- replaceLinks(state.translate('reportReasonCopyright'), [
- 'https://www.mozilla.org/about/legal/report-infringement/'
- ])
- )}
- </li>
- </ul>
- </fieldset>
- <input
- type="submit"
- disabled
- class="btn rounded-lg w-full flex-shrink-0 focus:outline"
- title="${state.translate('reportButton')}"
- value="${state.translate('reportButton')}"
- />
- </form>
- </div>
- </section>
- </main>
- `;
- function optionChanged(event) {
- event.stopPropagation();
- const button = event.currentTarget.nextElementSibling;
- button.disabled = false;
- }
- function report(event) {
- event.stopPropagation();
- event.preventDefault();
- if (submitting) {
- return;
- }
- submitting = true;
- state.fileInfo.reported = true;
- const form = event.target;
- emit('report', { reason: form.reason.value });
- }
- function replaceLinks(str, urls) {
- let i = 0;
- const s = str.replace(
- /<a>([^<]+)<\/a>/g,
- (m, v) => `<a class="text-blue" href="${urls[i++]}">${v}</a>`
- );
- return `<p>${s}</p>`;
- }
- };
|