<commit_before>import React, {Component} from 'react';
import Helmet from 'react-helmet';
import { connect } from 'react-redux';
import cookie from 'react-cookie';
import superagent from 'superagent';
import { push } from 'react-router-redux';

import { getSearchEntries } from '../../redux/actions/getSearchEntriesActions';

@connect((store) => {
  return {
    getSearchEntriesState: store.getSearchEntries.articleList,
  };
})

export default class Suche extends Component {
  state = {
    techObjectSearch: {}
  }

  componentDidMount() {
    this.props.dispatch(getSearchEntries({articleList: ""}));
  }

  onChangeCheckboxSearch = (event, t, tValue) => {
      let checkValue = '';
      if(event.target.checked === true){
        checkValue = tValue;
      }
      let chObject = {}
      chObject[t] = checkValue;
      this.setState({ techObjectSearch: Object.assign(this.state.techObjectSearch, chObject) });
  }

  searchDB = () => {
      const searchQuery = this.refs.searchquery.value;
      const searchCategory = this.refs.categorySearch.value;
      const techObject = this.state.techObjectSearch;

      superagent
      .post('/searchQuery')
      .send({ searchQuery: searchQuery, searchCategory: searchCategory, techObject: techObject })
      .set('Accept', 'application/json')
      .end((error, res) => {
        if(res.body.status === 1) {
          this.props.dispatch(getSearchEntries(res.body.searchArticles));
          console.log("yep search results: " + JSON.stringify(res.body.searchArticles));
        } else{
          this.props.dispatch(getSearchEntries({articleList: "Keine Suchergebnisse"}));
        }
      })
  }

  loadArticle = (id) => {
    superagent
    .post('/getSpecificArticle')
    .send({ artId: id })
    .set('Accept', 'application/json')
    .end((error, res) => {
      if(res.body.status === 1) {
        this.props.dispatch(push('community/'+res.body.specificArticleData.urlFriendlyTitel));
      }
    });
  }


  render() {
    const stylesCommunity = require('../Community/Community.scss');
    const stylesHome = require('../Home/Home.scss');
    const stylesMyProfile = require('../MyProfile/MyProfile.scss');

    const { getSearchEntriesState } = this.props;
    console.log("length"+getSearchEntriesState.articles.length);

    let searchResults = [];
    getSearchEntriesState.articles.forEach(function(entry){
      searchResults.push(
        <div onClick={() => this.loadArticle(entry.articleId)} className={stylesHome.topLine + ' animated fadeIn col-xs-12 ' + stylesHome.hover}>
          <div className='row'>
            <div className={'col-sm-1 col-xs-4 ' + stylesHome.mt5 + ' ' + stylesHome.mr35minus}>
              <div className={stylesMyProfile['avatar'+entry.userAvatar] + ' ' + stylesMyProfile.avatarRound + ' ' + stylesMyProfile.avatarMain + ' ' + stylesMyProfile.avatarMini}></div>
              <div className={stylesMyProfile['flag'+entry.userKanton] + ' ' + stylesMyProfile.avatarRound + ' ' + stylesMyProfile.avatarMain + ' ' + stylesMyProfile.avatarMini}></div>
            </div>
            <div className={'col-sm-2 col-xs-8 ' + stylesHome.mt5 + ' ' + stylesHome.oh}>{entry.userNickname}</div>
            <div className={'col-sm-4 col-xs-12 ' + stylesHome.mt5 + ' ' + stylesHome.oh + ' ' + stylesHome.fs18}><strong>{entry.titel}</strong></div>
            <div className={'col-sm-3 col-xs-12 ' + stylesHome.techStyle + ' ' + stylesHome.mt5}>{ Object.keys(entry.technologies[0]).map(key => entry.technologies[0][key].length > 1 ? <span title={entry.technologies[0][key]} className={stylesCommunity.cbs00Home + ' ' + stylesCommunity['cbs'+key]}></span> : null ) }</div>
            <div className={'col-sm-2 col-xs-12 text-right ' + stylesHome.dateStyle + ' ' + stylesHome.mt5 + ' ' + stylesHome.mb10}>{entry.timeFormatted} | <strong>{entry.category}</strong></div>
          </div>
        </div>
      );
    }.bind(this));

    return (
        <div className="container searchPage">
          <h1>Suche</h1>
          <Helmet title="Suche"/>

          {searchResults}

          <div className="form-group">
            <div className="row">
              <div className="col-xs-12 col-sm-10 col-md-10 col-lg-11">
                <input type="text" ref="searchquery" name="searchquery" id="searchquery" placeholder="Suche nach Schlagwörtern" autocorrect="off" autocapitalize="none" className="form-control"/>
              </div>
              <div className="search2 col-xs-12 col-sm-2 col-md-2 col-lg-1 text-right">
                <button className="btn btn-primary" onClick={() => this.searchDB()}>Suchen</button>
              </div>
            </div>
          </div>

          <div id="search-category-form">
            <form className="search-category-form form-inline">
              <div className="form-group">
                <select ref="categorySearch" className="titleStyle form-control">
                  <option value="Alles">Artikel + Projekte</option>
                  <option value="Artikel">Nur Artikel</option>
                  <option value="Projekt">Nur Projekte</option>
                </select>
              </div><commit_msg>asdee1222qa<commit_after>import React, {Component} from 'react';
import Helmet from 'react-helmet';
import { connect } from 'react-redux';
import cookie from 'react-cookie';
import superagent from 'superagent';
import { push } from 'react-router-redux';

import { getSearchEntries } from '../../redux/actions/getSearchEntriesActions';

@connect((store) => {
  return {
    getSearchEntriesState: store.getSearchEntries.articleList,
  };
})

export default class Suche extends Component {
  state = {
    techObjectSearch: {}
  }

  componentDidMount() {
    this.props.dispatch(getSearchEntries({articleList.articles: []}));
  }

  onChangeCheckboxSearch = (event, t, tValue) => {
      let checkValue = '';
      if(event.target.checked === true){
        checkValue = tValue;
      }
      let chObject = {}
      chObject[t] = checkValue;
      this.setState({ techObjectSearch: Object.assign(this.state.techObjectSearch, chObject) });
  }

  searchDB = () => {
      const searchQuery = this.refs.searchquery.value;
      const searchCategory = this.refs.categorySearch.value;
      const techObject = this.state.techObjectSearch;

      superagent
      .post('/searchQuery')
      .send({ searchQuery: searchQuery, searchCategory: searchCategory, techObject: techObject })
      .set('Accept', 'application/json')
      .end((error, res) => {
        if(res.body.status === 1) {
          this.props.dispatch(getSearchEntries(res.body.searchArticles));
          console.log("yep search results: " + JSON.stringify(res.body.searchArticles));
        } else{
          this.props.dispatch(getSearchEntries({articleList.articles: "Keine Suchergebnisse"}));
        }
      })
  }

  loadArticle = (id) => {
    superagent
    .post('/getSpecificArticle')
    .send({ artId: id })
    .set('Accept', 'application/json')
    .end((error, res) => {
      if(res.body.status === 1) {
        this.props.dispatch(push('community/'+res.body.specificArticleData.urlFriendlyTitel));
      }
    });
  }


  render() {
    const stylesCommunity = require('../Community/Community.scss');
    const stylesHome = require('../Home/Home.scss');
    const stylesMyProfile = require('../MyProfile/MyProfile.scss');

    const { getSearchEntriesState } = this.props;
    
    console.log("length"+getSearchEntriesState.articles.length);
    if(getSearchEntriesState.articles.length > 0){
      let searchResults = [];
      getSearchEntriesState.articles.forEach(function(entry){
        searchResults.push(
          <div onClick={() => this.loadArticle(entry.articleId)} className={stylesHome.topLine + ' animated fadeIn col-xs-12 ' + stylesHome.hover}>
            <div className='row'>
              <div className={'col-sm-1 col-xs-4 ' + stylesHome.mt5 + ' ' + stylesHome.mr35minus}>
                <div className={stylesMyProfile['avatar'+entry.userAvatar] + ' ' + stylesMyProfile.avatarRound + ' ' + stylesMyProfile.avatarMain + ' ' + stylesMyProfile.avatarMini}></div>
                <div className={stylesMyProfile['flag'+entry.userKanton] + ' ' + stylesMyProfile.avatarRound + ' ' + stylesMyProfile.avatarMain + ' ' + stylesMyProfile.avatarMini}></div>
              </div>
              <div className={'col-sm-2 col-xs-8 ' + stylesHome.mt5 + ' ' + stylesHome.oh}>{entry.userNickname}</div>
              <div className={'col-sm-4 col-xs-12 ' + stylesHome.mt5 + ' ' + stylesHome.oh + ' ' + stylesHome.fs18}><strong>{entry.titel}</strong></div>
              <div className={'col-sm-3 col-xs-12 ' + stylesHome.techStyle + ' ' + stylesHome.mt5}>{ Object.keys(entry.technologies[0]).map(key => entry.technologies[0][key].length > 1 ? <span title={entry.technologies[0][key]} className={stylesCommunity.cbs00Home + ' ' + stylesCommunity['cbs'+key]}></span> : null ) }</div>
              <div className={'col-sm-2 col-xs-12 text-right ' + stylesHome.dateStyle + ' ' + stylesHome.mt5 + ' ' + stylesHome.mb10}>{entry.timeFormatted} | <strong>{entry.category}</strong></div>
            </div>
          </div>
        );
      }.bind(this));
    }

    return (
        <div className="container searchPage">
          <h1>Suche</h1>
          <Helmet title="Suche"/>

          {searchResults}

          <div className="form-group">
            <div className="row">
              <div className="col-xs-12 col-sm-10 col-md-10 col-lg-11">
                <input type="text" ref="searchquery" name="searchquery" id="searchquery" placeholder="Suche nach Schlagwörtern" autocorrect="off" autocapitalize="none" className="form-control"/>
              </div>
              <div className="search2 col-xs-12 col-sm-2 col-md-2 col-lg-1 text-right">
                <button className="btn btn-primary" onClick={() => this.searchDB()}>Suchen</button>
              </div>
            </div>
          </div>

          <div id="search-category-form">
            <form className="search-category-form form-inline">
              <div className="form-group">
                <select ref="categorySearch" className="titleStyle form-control">
                  <option value="Alles">Artikel + Projekte</option>
                  <option value="Artikel">Nur Artikel</option>
                  <option value="Projekt">Nur Projekte</option>
                </select>
              </div>
{'fraction_non_alphanumeric': 0.15795530833413254, 'fraction_numerical': 0.010070010549534861, 'mean_word_length': 2.8072289156626504, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 126, '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': '3195886', 'n_tokens_mistral': 3186, 'n_tokens_neox': 3099, 'n_words': 511}