<commit_before>import { h, Component } 				from 'preact/preact';
import NavSpinner						from 'com/nav-spinner/spinner';

import ContentLoading					from 'com/content-loading/loading';
import ContentError						from 'com/content-error/error';

import ContentCommon					from 'com/content-common/common';
import ContentItemBox					from 'com/content-item/item-box';

import ContentCommonBody				from 'com/content-common/common-body';
import ContentCommonBodyTitle			from 'com/content-common/common-body-title';

//import ContentPost						from 'com/content-post/post';
//import ContentUser						from 'com/content-user/user';
import ContentMore						from 'com/content-more/more';

import $Node							from '../../shrub/js/node/node';

export default class ContentGames extends Component {

	constructor( props ) {
		super(props);

		this.state = {
			feed: [],
			hash: {},
			offset: 12-5, //10-5
			added: null,
			loaded: false
		};

		this.fetchMore = this.fetchMore.bind(this);

	}

	componentDidMount() {

		var props = this.props;

		this.getFeed(
			props.node.id,
			props.methods ? props.methods : ['parent', 'superparent'],
			props.types ? props.types : ['item'],
			props.subtypes ? props.subtypes : ['game'],
			props.subsubtypes ? props.subsubtypes : null,
			null,
			this.props.limit ? this.props.limit : 12
		);
	}

	appendFeed( newfeed ) {
		var feed = this.state.feed;
		var hash = this.state.hash;

		for ( var idx = 0; idx < newfeed.length; idx++ ) {
			var info = newfeed[idx];
			if ( !hash[info['id']] ) {
				hash[info['id']] = feed.length;
				feed.push(info);
			}
		}
		this.setState({'feed': feed, 'hash': hash, 'added': newfeed.length});
	}

	getFeedIdsWithoutNodes() {
		var feed = this.state.feed;
		var hash = this.state.hash;

		var keys = [];
		for (var idx = 0; idx < feed.length; idx++ ) {
			if ( !feed[idx]['node'] )
				keys.push(feed[idx]['id']);
		}
		return keys;
	}

	getMissingNodes() {
		var keys = this.getFeedIdsWithoutNodes();

		if ( keys.length ) {
			return $Node.GetKeyed( keys )
				.then(r => {
					var feed = this.state.feed;
					var hash = this.state.hash;

					for ( var node_id in r.node ) {
						var id = r.node[node_id].id;

						feed[hash[id]].node = r.node[node_id];
					}

					this.setState({'feed': feed, 'hash': hash});
				})
				.catch(err => {
					this.setState({ 'error': err });
				});
		}

	}

	getFeed( id, methods, types, subtypes, subsubtypes, more, limit ) {
		$Node.GetFeed( id, methods, types, subtypes, subsubtypes, more, limit )
		.then(r => {
			this.setState({ 'loaded': true });

			if ( r.feed && r.feed.length ) {
				this.appendFeed(r.feed);
				return this.getMissingNodes();
			}
		})
		.catch(err => {
			this.setState({ 'error': err });
		});
	}

	fetchMore( offset ) {

		console.log("loading more");

		var props = this.props;
		var offset = this.state.offset;
//		var morenode = this.state.feed[this.state.feed.length-1];
//		var more = morenode.created ? morenode.created : morenode.modified;

		this.getFeed(
			props.node.id,
			props.methods ? props.methods : ['parent', 'superparent'],
			props.types ? props.types : ['item'],
			props.subtypes ? props.subtypes : ['game'],
			props.subsubtypes ? props.subsubtypes : null,
			offset,
			this.props.limit ? this.props.limit : 12+5
		);

		this.setState({'offset': offset + 12});
	}

	static matchesFilter(node) {
		console.log(node);
		return true;
	}

	render( props, {feed, added, error, loaded} ) {

		var Class = ['content-base'];
//        props.class = typeof props.class == 'string' ? props.class.split(' ') : [];
//        props.class.push("content-games");
//        props.class.push("content-item-boxes");

		var LoadMore = null;
		const Games = [];
		const filter = 'll';

		if (error){
			return <ContentError code="400">"Bad Request : Couldn't load games"</ContentError>;
		}
		else if(feed && feed.length > 0)
		{
			feed.forEach( r => {
				if (ContentGames.matchesFilter(r.node, filter)) {
					Games.push(
						<ContentItemBox
							node={r.node}
							user={props.user}
							path={props.path}<commit_msg>Actually using filter<commit_after>import { h, Component } 				from 'preact/preact';
import NavSpinner						from 'com/nav-spinner/spinner';

import ContentLoading					from 'com/content-loading/loading';
import ContentError						from 'com/content-error/error';

import ContentCommon					from 'com/content-common/common';
import ContentItemBox					from 'com/content-item/item-box';

import ContentCommonBody				from 'com/content-common/common-body';
import ContentCommonBodyTitle			from 'com/content-common/common-body-title';

//import ContentPost						from 'com/content-post/post';
//import ContentUser						from 'com/content-user/user';
import ContentMore						from 'com/content-more/more';

import $Node							from '../../shrub/js/node/node';

export default class ContentGames extends Component {

	constructor( props ) {
		super(props);

		this.state = {
			feed: [],
			hash: {},
			offset: 12-5, //10-5
			added: null,
			loaded: false
		};

		this.fetchMore = this.fetchMore.bind(this);

	}

	componentDidMount() {

		var props = this.props;

		this.getFeed(
			props.node.id,
			props.methods ? props.methods : ['parent', 'superparent'],
			props.types ? props.types : ['item'],
			props.subtypes ? props.subtypes : ['game'],
			props.subsubtypes ? props.subsubtypes : null,
			null,
			this.props.limit ? this.props.limit : 12
		);
	}

	appendFeed( newfeed ) {
		var feed = this.state.feed;
		var hash = this.state.hash;

		for ( var idx = 0; idx < newfeed.length; idx++ ) {
			var info = newfeed[idx];
			if ( !hash[info['id']] ) {
				hash[info['id']] = feed.length;
				feed.push(info);
			}
		}
		this.setState({'feed': feed, 'hash': hash, 'added': newfeed.length});
	}

	getFeedIdsWithoutNodes() {
		var feed = this.state.feed;
		var hash = this.state.hash;

		var keys = [];
		for (var idx = 0; idx < feed.length; idx++ ) {
			if ( !feed[idx]['node'] )
				keys.push(feed[idx]['id']);
		}
		return keys;
	}

	getMissingNodes() {
		var keys = this.getFeedIdsWithoutNodes();

		if ( keys.length ) {
			return $Node.GetKeyed( keys )
				.then(r => {
					var feed = this.state.feed;
					var hash = this.state.hash;

					for ( var node_id in r.node ) {
						var id = r.node[node_id].id;

						feed[hash[id]].node = r.node[node_id];
					}

					this.setState({'feed': feed, 'hash': hash});
				})
				.catch(err => {
					this.setState({ 'error': err });
				});
		}

	}

	getFeed( id, methods, types, subtypes, subsubtypes, more, limit ) {
		$Node.GetFeed( id, methods, types, subtypes, subsubtypes, more, limit )
		.then(r => {
			this.setState({ 'loaded': true });

			if ( r.feed && r.feed.length ) {
				this.appendFeed(r.feed);
				return this.getMissingNodes();
			}
		})
		.catch(err => {
			this.setState({ 'error': err });
		});
	}

	fetchMore( offset ) {

		console.log("loading more");

		var props = this.props;
		var offset = this.state.offset;
//		var morenode = this.state.feed[this.state.feed.length-1];
//		var more = morenode.created ? morenode.created : morenode.modified;

		this.getFeed(
			props.node.id,
			props.methods ? props.methods : ['parent', 'superparent'],
			props.types ? props.types : ['item'],
			props.subtypes ? props.subtypes : ['game'],
			props.subsubtypes ? props.subsubtypes : null,
			offset,
			this.props.limit ? this.props.limit : 12+5
		);

		this.setState({'offset': offset + 12});
	}

	static matchesFilter(node, filter) {
		if (node === undefined) {
			return false;
		}
		//console.log(filter);
		if (filter && filter.active) {
			const {text} = filter;
			if (text && (node.name.indexOf(text) > -1 || node.body.indexOf(text) > -1)) {
				return true;
			}
			//TODO: check tags
			return !text;
		}
		return true;
	}

	render( props, {feed, added, error, loaded} ) {

		var Class = ['content-base'];
//        props.class = typeof props.class == 'string' ? props.class.split(' ') : [];
//        props.class.push("content-games");
//        props.class.push("content-item-boxes");

		var LoadMore = null;
		const Games = [];
		const {filter} = props;
		if (error){
			return <ContentError code="400">"Bad Request : Couldn't load games"</ContentError>;
		}
		else if(feed && feed.length > 0)
		{
			feed.forEach( r => {
				if (ContentGames.matchesFilter(r.node, filter)) {
					Games.push(
						<ContentItemBox
							node={r.node}
							user={props.user}
							path={props.path}
{'fraction_non_alphanumeric': 0.16757654877759318, 'fraction_numerical': 0.004984571564206029, 'mean_word_length': 2.9250116441546345, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '5875862', 'n_tokens_mistral': 3452, 'n_tokens_neox': 2885, 'n_words': 624}