<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { ActionType, Thunk, Dispatch, GetState } from '../types/redux/actions';
import { showSuccessNotification, showErrorNotification } from '../utils/notifications';
import translate from '../utils/translate';
import * as t from '../types/redux/meters';
import { metersApi } from '../utils/api';

export function requestMetersDetails(): t.RequestMetersDetailsAction {
	return { type: ActionType.RequestMetersDetails };
}

export function receiveMetersDetails(data: t.MeterData[]): t.ReceiveMetersDetailsAction {
	return { type: ActionType.ReceiveMetersDetails, data };
}

export function fetchMetersDetails(): Thunk {
	return async (dispatch: Dispatch, getState: GetState) => {
		// ensure a fetch is not currently happening
		if (!getState().meters.isFetching) {
			// set isFetching to true
			dispatch(requestMetersDetails());
			// attempt to retrieve meters details from database
			const meters = await metersApi.getMetersDetails();
			console.log(meters);
			// update the state with the meters details and set isFetching to false<commit_msg>remove console log<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { ActionType, Thunk, Dispatch, GetState } from '../types/redux/actions';
import { showSuccessNotification, showErrorNotification } from '../utils/notifications';
import translate from '../utils/translate';
import * as t from '../types/redux/meters';
import { metersApi } from '../utils/api';

export function requestMetersDetails(): t.RequestMetersDetailsAction {
	return { type: ActionType.RequestMetersDetails };
}

export function receiveMetersDetails(data: t.MeterData[]): t.ReceiveMetersDetailsAction {
	return { type: ActionType.ReceiveMetersDetails, data };
}

export function fetchMetersDetails(): Thunk {
	return async (dispatch: Dispatch, getState: GetState) => {
		// ensure a fetch is not currently happening
		if (!getState().meters.isFetching) {
			// set isFetching to true
			dispatch(requestMetersDetails());
			// attempt to retrieve meters details from database
			const meters = await metersApi.getMetersDetails();
			// update the state with the meters details and set isFetching to false
{'fraction_non_alphanumeric': 0.10904780719083366, 'fraction_numerical': 0.0031608060055314103, 'mean_word_length': 4.410256410256411, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6866137', 'n_tokens_mistral': 726, 'n_tokens_neox': 693, 'n_words': 248}