logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

reports.js (2066B)


  1. import api from '../api';
  2. import { openModal, closeModal } from './modal';
  3. export const REPORT_INIT = 'REPORT_INIT';
  4. export const REPORT_CANCEL = 'REPORT_CANCEL';
  5. export const REPORT_SUBMIT_REQUEST = 'REPORT_SUBMIT_REQUEST';
  6. export const REPORT_SUBMIT_SUCCESS = 'REPORT_SUBMIT_SUCCESS';
  7. export const REPORT_SUBMIT_FAIL = 'REPORT_SUBMIT_FAIL';
  8. export const REPORT_STATUS_TOGGLE = 'REPORT_STATUS_TOGGLE';
  9. export const REPORT_COMMENT_CHANGE = 'REPORT_COMMENT_CHANGE';
  10. export const REPORT_FORWARD_CHANGE = 'REPORT_FORWARD_CHANGE';
  11. export function initReport(account, status) {
  12. return dispatch => {
  13. dispatch({
  14. type: REPORT_INIT,
  15. account,
  16. status,
  17. });
  18. dispatch(openModal('REPORT'));
  19. };
  20. };
  21. export function cancelReport() {
  22. return {
  23. type: REPORT_CANCEL,
  24. };
  25. };
  26. export function toggleStatusReport(statusId, checked) {
  27. return {
  28. type: REPORT_STATUS_TOGGLE,
  29. statusId,
  30. checked,
  31. };
  32. };
  33. export function submitReport() {
  34. return (dispatch, getState) => {
  35. dispatch(submitReportRequest());
  36. api(getState).post('/api/v1/reports', {
  37. account_id: getState().getIn(['reports', 'new', 'account_id']),
  38. status_ids: getState().getIn(['reports', 'new', 'status_ids']),
  39. comment: getState().getIn(['reports', 'new', 'comment']),
  40. forward: getState().getIn(['reports', 'new', 'forward']),
  41. }).then(response => {
  42. dispatch(closeModal());
  43. dispatch(submitReportSuccess(response.data));
  44. }).catch(error => dispatch(submitReportFail(error)));
  45. };
  46. };
  47. export function submitReportRequest() {
  48. return {
  49. type: REPORT_SUBMIT_REQUEST,
  50. };
  51. };
  52. export function submitReportSuccess(report) {
  53. return {
  54. type: REPORT_SUBMIT_SUCCESS,
  55. report,
  56. };
  57. };
  58. export function submitReportFail(error) {
  59. return {
  60. type: REPORT_SUBMIT_FAIL,
  61. error,
  62. };
  63. };
  64. export function changeReportComment(comment) {
  65. return {
  66. type: REPORT_COMMENT_CHANGE,
  67. comment,
  68. };
  69. };
  70. export function changeReportForward(forward) {
  71. return {
  72. type: REPORT_FORWARD_CHANGE,
  73. forward,
  74. };
  75. };