<commit_before>// @flow
/* eslint-disable import/prefer-default-export */

import * as types from "constants/actionTypes";
import * as optionTypes from "constants/optionTypes";
import { paletteList } from "palettes";
import { THEMES } from "palettes/user";

import type { ColorRGBA, Filter, FilterFunc } from "types";

export const loadImage = (image: HTMLImageElement) => ({
  type: types.LOAD_IMAGE,
  image
});

export const loadImageAsync = (file: Blob) => (dispatch: Dispatch) => {
  const reader = new FileReader();
  const image = new Image();

  reader.onload = event => {
    image.onload = () => {
      dispatch(loadImage(image));
    };
    image.src = event.target.result;
  };

  reader.readAsDataURL(file);
};

export const setConvertGrayscale = (value: boolean) => ({
  type: types.SET_GRAYSCALE,
  value
});

export const selectFilter = (name: string, filter: Filter) => ({
  type: types.SELECT_FILTER,
  name,
  filter
});

export const filterImage = (image: HTMLImageElement) => ({
  type: types.FILTER_IMAGE,
  image
});<commit_msg>Add action to load image from URL<commit_after>// @flow
/* eslint-disable import/prefer-default-export */

import * as types from "constants/actionTypes";
import * as optionTypes from "constants/optionTypes";
import { paletteList } from "palettes";
import { THEMES } from "palettes/user";

import type { ColorRGBA, Filter, FilterFunc } from "types";

export const loadImage = (image: HTMLImageElement) => ({
  type: types.LOAD_IMAGE,
  image
});

export const loadImageAsync = (file: Blob) => (dispatch: Dispatch) => {
  const reader = new FileReader();
  const image = new Image();

  reader.onload = event => {
    image.onload = () => {
      dispatch(loadImage(image));
    };
    image.src = event.target.result;
  };

  reader.readAsDataURL(file);
};

export const loadImageURLAsync = (url: string) => (dispatch: Dispatch) => {
  try {
    const image = new Image();
    image.onload = () => {
      dispatch(loadImage(image));
    };
    image.src = url;
  } catch (e) {
    console.error(e);
  }
};

export const setConvertGrayscale = (value: boolean) => ({
  type: types.SET_GRAYSCALE,
  value
});

export const selectFilter = (name: string, filter: Filter) => ({
  type: types.SELECT_FILTER,
  name,
  filter
});

export const filterImage = (image: HTMLImageElement) => ({
  type: types.FILTER_IMAGE,
  image
});
{'fraction_non_alphanumeric': 0.14785172704296545, 'fraction_numerical': 0.0, 'mean_word_length': 3.8868312757201644, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '4852411', 'n_tokens_mistral': 759, 'n_tokens_neox': 752, 'n_words': 197}