import { h, render } from 'preact';
import { useState, useRef } from 'preact/hooks';
import PropTypes from 'prop-types';
import { request } from '../utilities/http';
import { ButtonNew as Button, Link } from '@crayons';
import RemoveIcon from '@images/x.svg';
async function confirmFlagUser({ reactableType, category, reactableId }) {
const body = JSON.stringify({
reactable_type: reactableType,
category,
reactable_id: reactableId,
});
try {
const response = await request('/reactions', {
method: 'POST',
body,
});
const outcome = await response.json();
if (outcome.result === 'create') {
top.addSnackbarItem({
message: 'All posts by this author will be less visible.',
addCloseButton: true,
});
} else if (outcome.result === null) {
top.addSnackbarItem({
message:
"It seems you've already reduced the visibility of this author's posts.",
addCloseButton: true,
});
} else {
top.addSnackbarItem({
message: `Response from server: ${JSON.stringify(outcome)}`,
addCloseButton: true,
});
}
} catch (error) {
top.addSnackbarItem({
message: error,
addCloseButton: true,
});
}
toggleFlagUserModal();
}
/**
* Shows or hides the flag user modal.
*/
export function toggleFlagUserModal() {
const modalContainer = top.document.getElementsByClassName(
'flag-user-modal-container',
)[0];
modalContainer.classList.toggle('hidden');
if (!modalContainer.classList.contains('hidden')) {
top.window.scrollTo(0, 0);
top.document.body.style.height = '100vh';
top.document.body.style.overflowY = 'hidden';
} else {
top.document.body.style.height = 'inherit';
top.document.body.style.overflowY = 'inherit';
}
}
/**
* Initializes the flag user modal for the given author ID.
*
* @param {number} authorId
*/
export function initializeFlagUserModal(authorId) {
// Check whether context is ModCenter or Friday-Night-Mode
const modContainer = document.getElementById('mod-container');
if (!modContainer) {
return;
}
render(
{`Thanks for keeping ${communityName} safe. Here is what you can do to flag this user:`}
Report other inappropriate conduct