<commit_before>require('normalize.css');
require('styles/App.css');

import React from 'react';
import { Grid, Row, Col } from 'react-bootstrap';
import HeaderComponent from './HeaderComponent';
import PalettePanelComponent from './PalettePanelComponent';
import AddColorPanelComponent from './AddColorPanelComponent';
import EditColorPanelComponent from './EditColorPanelComponent';
import {union, uniqueId, findWhere, without, times, random, sample} from 'lodash';
import randomColor from 'randomcolor';
import away from 'away';

const SLEEP_ANIMATION_TIMEOUT = 5000;

class AppComponent extends React.Component {
	constructor() {
		super();
		let colors = [];
		times(90, () => {
			let color = randomColor();
			colors.push({
				id: uniqueId('color'),
				code: color,
				name: color,
				selected: false,
				hovered: false
			});
		});
		this.state = {
			colors: colors,
			multiselect: true,
			isIdle: false
		};

		let timer = away(SLEEP_ANIMATION_TIMEOUT);
		timer.on('idle', () => {
			this.setState({
				isIdle: true
			}, this._startSleepAnimation);
		});
		timer.on('active', () => {
			this._stopSleepAnimation();
		});
	}

	handleAddColor(color) {
		this.setState({
			colors: union(this.state.colors, [color])
		});
	}

	getColorById(colorId) {
		return findWhere(this.state.colors, {id: colorId});
	}
	updateColors() {
		this.setState({
			colors: this.state.colors
		});
	}

	handleChangeColor(color) {
		let curentColor = this.getColorById(color.id);
		curentColor.code = color.code;
		curentColor.name = color.name;
		this.updateColors();
	}

	handleDeleteColor(colorId) {
		let color = this.getColorById(colorId);
		this.setState({
			colors: without(this.state.colors, color)
		});
	}

	handleDeleteAllSelected() {
		let notSelected = this.state.colors.filter(color => !color.selected);
		this.setState({
			colors: notSelected
		});
	}

	getSelectedColors() {
		return this.state.colors.filter(color => color.selected);
	}

	handleColorClick(colorId) {
		let color = this.getColorById(colorId);
		let selected = !color.selected;
		if (!this.state.multiselect) {
			this.state.colors.forEach(color => {color.selected = false});
		}
		color.selected = selected;
		this.updateColors();
	}

	handleMouseEnterColor(colorId) {
		let color = this.getColorById(colorId);
		color.hovered = true;
		this.updateColors();
	}

	handleMouseLeaveColor(colorId) {
		let color = this.getColorById(colorId);
		color.hovered = false;
		this.updateColors();
	}

	handleSelectAllChange(selected) {
		this.state.colors.forEach(color => {color.selected = selected});
		this.updateColors();
	}

	handleMultiselectChange(selected) {
		this.setState({
			multiselect: selected
		});
	}

	_startSleepAnimation() {
		if (!this.state.isIdle) {
			return;
		}
		let wait = random(1, 10) * 100;
		setTimeout(() => {
			this._selectRandomColor();
			this._startSleepAnimation();
		}, wait);
	}

	_stopSleepAnimation() {
		this.setState({
			isIdle: false
		});
	}

	_selectRandomColor() {
		if (!this.state.colors) {
			return;
		}

		let color = sample(this.state.colors);
		color.hovered = true;
		this.setState({colors: this.state.colors});<commit_msg>Colors animation on idle #6<commit_after>require('normalize.css');
require('styles/App.css');

import React from 'react';
import { Grid, Row, Col } from 'react-bootstrap';
import HeaderComponent from './HeaderComponent';
import PalettePanelComponent from './PalettePanelComponent';
import AddColorPanelComponent from './AddColorPanelComponent';
import EditColorPanelComponent from './EditColorPanelComponent';
import {union, uniqueId, findWhere, without, times, random, sample} from 'lodash';
import randomColor from 'randomcolor';
import away from 'away';

const SLEEP_ANIMATION_TIMEOUT = 5000;

class AppComponent extends React.Component {
	constructor() {
		super();
		let colors = [];
		times(90, () => {
			let color = randomColor();
			colors.push({
				id: uniqueId('color'),
				code: color,
				name: color,
				selected: false,
				hovered: false
			});
		});
		this.state = {
			colors: colors,
			multiselect: true,
			isIdle: false
		};

		this._initSleepAnimation();
	}

	handleAddColor(color) {
		this.setState({
			colors: union(this.state.colors, [color])
		});
	}

	getColorById(colorId) {
		return findWhere(this.state.colors, {id: colorId});
	}
	updateColors() {
		this.setState({
			colors: this.state.colors
		});
	}

	handleChangeColor(color) {
		let curentColor = this.getColorById(color.id);
		curentColor.code = color.code;
		curentColor.name = color.name;
		this.updateColors();
	}

	handleDeleteColor(colorId) {
		let color = this.getColorById(colorId);
		this.setState({
			colors: without(this.state.colors, color)
		});
	}

	handleDeleteAllSelected() {
		let notSelected = this.state.colors.filter(color => !color.selected);
		this.setState({
			colors: notSelected
		});
	}

	getSelectedColors() {
		return this.state.colors.filter(color => color.selected);
	}

	handleColorClick(colorId) {
		let color = this.getColorById(colorId);
		let selected = !color.selected;
		if (!this.state.multiselect) {
			this.state.colors.forEach(color => {color.selected = false});
		}
		color.selected = selected;
		this.updateColors();
	}

	handleMouseEnterColor(colorId) {
		let color = this.getColorById(colorId);
		color.hovered = true;
		this.updateColors();
	}

	handleMouseLeaveColor(colorId) {
		let color = this.getColorById(colorId);
		color.hovered = false;
		this.updateColors();
	}

	handleSelectAllChange(selected) {
		this.state.colors.forEach(color => {color.selected = selected});
		this.updateColors();
	}

	handleMultiselectChange(selected) {
		this.setState({
			multiselect: selected
		});
	}

	_initSleepAnimation() {
		let timer = away(SLEEP_ANIMATION_TIMEOUT);
		timer.on('idle', () => {
			this.setState({
				isIdle: true
			}, this._startSleepAnimation);
		});
		timer.on('active', () => {
			this._stopSleepAnimation();
		});
	}

	_startSleepAnimation() {
		if (!this.state.isIdle) {
			return;
		}
		let wait = random(1, 10) * 100;
		setTimeout(() => {
			this._selectRandomColor();
			this._startSleepAnimation();
		}, wait);
	}

	_stopSleepAnimation() {
		this.setState({
			isIdle: false
		});
	}

	_selectRandomColor() {
		if (!this.state.colors) {
			return;
		}

		let color = sample(this.state.colors);
		color.hovered = true;
		this.setState({colors: this.state.colors});
{'fraction_non_alphanumeric': 0.14729411764705883, 'fraction_numerical': 0.00392156862745098, 'mean_word_length': 4.104883907125701, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '6400960', 'n_tokens_mistral': 2379, 'n_tokens_neox': 2119, 'n_words': 401}