<commit_before>/* eslint-disable jsx-a11y/click-events-have-key-events,no-return-assign,react/forbid-prop-types */
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import SmallWaitCursor from '../../react-chayns-smallwaitcursor/component/SmallWaitCursor';
import { getImageMetaDataFromApi, getImageMetaDataFromPreview } from '../utils/getImageMetaData';
import { getDataUrlFromBase64, getDataUrlFromFile } from '../utils/getDataUrl';
import './Image.scss';
import { isString } from '../../utils/is';
import getOrientation from '../utils/getOrientation';

export default class Image extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            ready: false,
            imageUrl: null,
            metaData: null,
            elementDimensions: null,
            rotate: 0,
            mirror: false,
        };
        this.imageRef = React.createRef();
    }

    componentDidMount() {
        this.init();
    }

    componentDidUpdate(prevProps) {
        if (prevProps !== this.props) {
            this.init();
        }
    }

    getElementDimensions = () => {
        this.setState({
            elementDimensions: {
                height: this.imageRef.current.clientHeight,
                width: this.imageRef.current.clientWidth,
            },
        });
    };

    init = async () => { // set url and metadata
        this.getElementDimensions();

        const { image, styleLandscape, stylePortrait } = this.props;

        if (isString(image)) { // url
            if (Image.imageMetaData[image]) { // use cached metadata
                this.setState({
                    metaData: Image.imageMetaData[image],
                    imageUrl: image,
                });
            } else if (image.indexOf('tsimg.cloud') >= 0) { // get preview and dimensions from tsimg.cloud
                const metaData = await getImageMetaDataFromApi(image);
                Image.imageMetaData[image] = metaData;
                this.setState({<commit_msg>Update image height and width to 50px steps<commit_after>/* eslint-disable jsx-a11y/click-events-have-key-events,no-return-assign,react/forbid-prop-types */
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import SmallWaitCursor from '../../react-chayns-smallwaitcursor/component/SmallWaitCursor';
import { getImageMetaDataFromApi, getImageMetaDataFromPreview } from '../utils/getImageMetaData';
import { getDataUrlFromBase64, getDataUrlFromFile } from '../utils/getDataUrl';
import './Image.scss';
import { isString } from '../../utils/is';
import getOrientation from '../utils/getOrientation';

export default class Image extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            ready: false,
            imageUrl: null,
            metaData: null,
            elementDimensions: null,
            rotate: 0,
            mirror: false,
        };
        this.imageRef = React.createRef();
    }

    componentDidMount() {
        this.init();
    }

    componentDidUpdate(prevProps) {
        if (prevProps !== this.props) {
            this.init();
        }
    }

    getElementDimensions = () => {
        this.setState({
            elementDimensions: {
                height: Math.ceil(this.imageRef.current.clientHeight / 50) * 50,
                width: Math.ceil(this.imageRef.current.clientWidth / 50) * 50,
            },
        });
    };

    init = async () => { // set url and metadata
        this.getElementDimensions();

        const { image, styleLandscape, stylePortrait } = this.props;

        if (isString(image)) { // url
            if (Image.imageMetaData[image]) { // use cached metadata
                this.setState({
                    metaData: Image.imageMetaData[image],
                    imageUrl: image,
                });
            } else if (image.indexOf('tsimg.cloud') >= 0) { // get preview and dimensions from tsimg.cloud
                const metaData = await getImageMetaDataFromApi(image);
                Image.imageMetaData[image] = metaData;
                this.setState({
{'fraction_non_alphanumeric': 0.12003780718336483, 'fraction_numerical': 0.005198487712665407, 'mean_word_length': 2.1170839469808542, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6429813', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1120, 'n_words': 248}