<commit_before>// @flow

import {
  logOutActionTypes,
  deleteAccountActionTypes,
  logInActionTypes,
} from '../actions/user-actions';
import { isStaff } from '../shared/user-utils';
import type { BaseAction } from '../types/redux-types';
import {
  type ReportStore,
  defaultEnabledReports,
  defaultDevEnabledReports,
} from '../types/report-types';
import { setNewSessionActionType } from '../utils/action-utils';
import { isDev } from '../utils/dev-utils';

export const updateReportsEnabledActionType = 'UPDATE_REPORTS_ENABLED';

export default function reduceReportStore(
  state: ReportStore,
  action: BaseAction,
): ReportStore {
  if (action.type === updateReportsEnabledActionType) {
    return {
      ...state,
      enabledReports: { ...state.enabledReports, ...action.payload },
    };
  } else if (
    action.type === logOutActionTypes.success ||
    action.type === deleteAccountActionTypes.success ||
    (action.type === setNewSessionActionType &&
      action.payload.sessionChange.cookieInvalidated)
  ) {
    return {
      ...state,
      enabledReports: isDev ? defaultDevEnabledReports : defaultEnabledReports,
    };
  } else if (action.type === logInActionTypes.success) {
    return {
      ...state,
      enabledReports:
        isStaff(action.payload.currentUserInfo.id) || isDev
          ? defaultDevEnabledReports
          : defaultEnabledReports,
    };
  }
  return state;
}
<commit_msg>[lib] Modify `reportStoreReducer to add media reports to `state.reportStore.queuedReports`<commit_after>// @flow

import {
  sendReportActionTypes,
  sendReportsActionTypes,
  queueReportsActionType,
} from '../actions/report-actions';
import {
  logOutActionTypes,
  deleteAccountActionTypes,
  logInActionTypes,
} from '../actions/user-actions';
import { isStaff } from '../shared/user-utils';
import type { BaseAction } from '../types/redux-types';
import {
  type ReportStore,
  defaultEnabledReports,
  defaultDevEnabledReports,
} from '../types/report-types';
import { setNewSessionActionType } from '../utils/action-utils';
import { isDev } from '../utils/dev-utils';

export const updateReportsEnabledActionType = 'UPDATE_REPORTS_ENABLED';

export default function reduceReportStore(
  state: ReportStore,
  action: BaseAction,
): ReportStore {
  if (action.type === updateReportsEnabledActionType) {
    return {
      ...state,
      enabledReports: { ...state.enabledReports, ...action.payload },
    };
  } else if (
    action.type === logOutActionTypes.success ||
    action.type === deleteAccountActionTypes.success ||
    (action.type === setNewSessionActionType &&
      action.payload.sessionChange.cookieInvalidated)
  ) {
    return {
      ...state,
      enabledReports: isDev ? defaultDevEnabledReports : defaultEnabledReports,
    };
  } else if (action.type === logInActionTypes.success) {
    return {
      ...state,
      enabledReports:
        isStaff(action.payload.currentUserInfo.id) || isDev
          ? defaultDevEnabledReports
          : defaultEnabledReports,
    };
  } else if (
    (action.type === sendReportActionTypes.success ||
      action.type === sendReportsActionTypes.success) &&
    action.payload
  ) {
    const { payload } = action;
    const updatedReports = state.queuedReports.filter(
      (response) => !payload.reports.includes(response),
    );
    if (updatedReports.length === state.queuedReports.length) {
      return state;
    }
    return { ...state, queuedReports: updatedReports };
  } else if (action.type === queueReportsActionType) {
    const { reports } = action.payload;
    return { ...state, queuedReports: [...state.queuedReports, ...reports] };
  }
  return state;
}

{'fraction_non_alphanumeric': 0.1287074829931973, 'fraction_numerical': 0.0, 'mean_word_length': 3.397129186602871, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4211477', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1070, 'n_words': 212}