<commit_before>import React from 'react';

import Ide from './Ide';
import SourceboxProject from '../../models/project/sourceboxProject';
import { usageConsole } from '../../util/usageLogger';
import { MessageListModel } from '../../models/messages';
import { API } from '../../services';

export default class IdeWrapper extends React.Component {
  constructor(props) {
    super(props);

    this.onClick = this.onClick.bind(this);
    this.onDownloadErrorNoticed = this.onDownloadErrorNoticed.bind(this);

    this.state = {
      codeData: null,
      isDownloading: false,
      IdeComponent: null,
      error: null
    };
  }

  setErrorState(err) {
    this.setState({
      error: err,
      isDownloading: false
    })
  }

  onDownloadErrorNoticed(e) {
    this.setState({
      error: null
    })
  }

  onClick(e) {
    this.setState({
      codeData: null,
      isDownloading: true
    });

    if (this.state.IdeComponent === null) {
      require.ensure('./Ide', require => {
        const Ide = require('./Ide');

        this.setState({
          IdeComponent: Ide.default
        });
      });
    }

    API.embed.getEmbed({ id: this.props.codeID }).then(data => {
      if(!data.error) {
        this.setState({
          codeData: data,
          isDownloading: false
        });
      } else {
        this.setErrorState(data.error.title);
      }

    }).catch(err => {
      this.setErrorState(err);
      console.log(err);
    });
  }

  renderIdeWrapper() {
    let toRender;
    if (this.state.codeData == null || this.state.IdeComponent == null) {
      if(this.state.error == null) {
        let image = (!this.state.isDownloading) ? "/public/img/download.png" : "/public/img/reload.svg"
        toRender = <div className="container" onClick={this.onClick}>
          <img src={image} />
        </div>;
      } else {
        // TODO: replace hardcoded text by preconfigured text
        toRender = <div className="alert alert-danger alert-dismissable col-xs-12">
          <a href="#" onClick={this.onDownloadErrorNoticed} className="close" data-dismiss="alert" aria-label="close">&times;</a>
          <strong>Fehler:</strong> {this.state.error}
        </div>
      }<commit_msg>fixed page jump bug #151<commit_after>import React from 'react';

import Ide from './Ide';
import SourceboxProject from '../../models/project/sourceboxProject';
import { usageConsole } from '../../util/usageLogger';
import { MessageListModel } from '../../models/messages';
import { API } from '../../services';

export default class IdeWrapper extends React.Component {
  constructor(props) {
    super(props);

    this.onClick = this.onClick.bind(this);
    this.onDownloadErrorNoticed = this.onDownloadErrorNoticed.bind(this);

    this.state = {
      codeData: null,
      isDownloading: false,
      IdeComponent: null,
      error: null
    };
  }

  setErrorState(err) {
    this.setState({
      error: err,
      isDownloading: false
    })
  }

  onDownloadErrorNoticed(e) {
    this.setState({
      error: null
    })
  }

  onClick(e) {
    this.setState({
      codeData: null,
      isDownloading: true
    });

    if (this.state.IdeComponent === null) {
      require.ensure('./Ide', require => {
        const Ide = require('./Ide');

        this.setState({
          IdeComponent: Ide.default
        });
      });
    }

    API.embed.getEmbed({ id: this.props.codeIDgit  }).then(data => {
      if(!data.error) {
        this.setState({
          codeData: data,
          isDownloading: false
        });
      } else {
        this.setErrorState(data.error.title);
      }

    }).catch(err => {
      this.setErrorState(err);
      console.log(err);
    });
  }

  renderIdeWrapper() {
    let toRender;
    if (this.state.codeData == null || this.state.IdeComponent == null) {
      if(this.state.error == null) {
        let image = (!this.state.isDownloading) ? "/public/img/download.png" : "/public/img/reload.svg"
        toRender = <div className="container" onClick={this.onClick}>
          <img src={image} />
        </div>;
      } else {
        // TODO: replace hardcoded text by preconfigured text
        toRender = <div className="alert alert-danger alert-dismissable col-xs-12">
          <a onClick={this.onDownloadErrorNoticed} className="close" data-dismiss="alert" aria-label="close">&times;</a>
          <strong>Fehler:</strong> {this.state.error}
        </div>
      }
{'fraction_non_alphanumeric': 0.15223274695534506, 'fraction_numerical': 0.0015787099684258007, 'mean_word_length': 2.362395754359363, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3292819', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1327, 'n_words': 267}