<commit_before>import React from 'react';
import {Link} from 'react-router-dom';
import Chessboard from './chessboard';
import {GameStorage, SettingsStorage} from './storage';
import './search.css';

export default class Search extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			result: [],
			last: []
		};
		this.storage = new GameStorage();
		this.settingsStorage = new SettingsStorage();
	}

	componentDidMount(){
		const limit = this.settingsStorage.loadKey('lastEditLimit', 2);
		this.setState({
			last: this.storage
						.loadGames()
						.sort((a,b) => b.edit - a.edit)
						.splice(0, limit)
		});
	}

	search(event) {
		event.preventDefault();
		const term = event.target.value.trim();
		if(term === '') {
			// Nothing to search
			this.setState({
				result: []
			});
			return;
		}
		let re = RegExp(term, 'gi');
		let result = [];
		let games = this.storage.loadGames().map(game => {
			if(game.title.match(re)){
				result.push(game);
				return null;
			}
			else {
				return game;
			}
		});
		games.map(game => {
			if(game) {
				let added = false;
				game.lines.map(line => {
					if(!added && line.comment.match(re)) {
						result.push(game);
						added = true;
					}
					return true;
				});
			}
			return true;
		});
		this.setState({
			result: result
		});
	}

	render(){
		return (
			<div className="Search">
				<input type="text" placeholder="Search..." onChange={this.search.bind(this)}/>

				<ul className="list">
					{
						this.state.result.map((result, i) =>
							<li key={i}>
								<SearchResult {...result}/>
							</li>
						)
					}
				</ul>

				<h2>Last games</h2>
				<ul className="list">
					{
						this.state.last.map((result, i) =>
							<li key={i}>
								<SearchResult {...result}/>
							</li>
						)
					}
				</ul>
			</div>
		);
	}<commit_msg>Don't show last edit if it's empty<commit_after>import React from 'react';
import {Link} from 'react-router-dom';
import Chessboard from './chessboard';
import {GameStorage, SettingsStorage} from './storage';
import './search.css';

export default class Search extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			result: [],
			last: []
		};
		this.storage = new GameStorage();
		this.settingsStorage = new SettingsStorage();
	}

	componentDidMount(){
		const limit = this.settingsStorage.loadKey('lastEditLimit', 2);
		this.setState({
			last: this.storage
						.loadGames()
						.sort((a,b) => b.edit - a.edit)
						.splice(0, limit)
		});
	}

	search(event) {
		event.preventDefault();
		const term = event.target.value.trim();
		if(term === '') {
			// Nothing to search
			this.setState({
				result: [],
				term: null
			});
			return;
		}
		let re = RegExp(term, 'gi');
		let result = [];
		let games = this.storage.loadGames().map(game => {
			if(game.title.match(re)){
				result.push(game);
				return null;
			}
			else {
				return game;
			}
		});
		games.map(game => {
			if(game) {
				let added = false;
				game.lines.map(line => {
					if(!added && line.comment.match(re)) {
						result.push(game);
						added = true;
					}
					return true;
				});
			}
			return true;
		});
		this.setState({
			result: result,
			term: term
		});
	}

	render(){
		return (
			<div className="Search">
				<input type="text" placeholder="Search..." onChange={this.search.bind(this)}/>

				<ul className="list">
					{
						this.state.result.map((result, i) =>
							<li key={i}>
								<SearchResult {...result}/>
							</li>
						)
					}
				</ul>

				{this.state.last.length > 0 ? [
					<h2 key="h2">Last games</h2>,
					<ul key="ul" className="list">
						{
							this.state.last.map((result, i) =>
								<li key={i}>
									<SearchResult {...result}/>
								</li>
							)
						}
					</ul>
				] : ''}
			</div>
		);
	}
{'fraction_non_alphanumeric': 0.1824095758521988, 'fraction_numerical': 0.0026021337496747333, 'mean_word_length': 2.3513513513513513, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 46, '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': '2918550', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1316, 'n_words': 268}