<commit_before>// 
// RendererPane component
// 
class RendererPane extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      repository: null,
      branch: null,
      fileActive: null,
      srcDoc: null,
      src: null
    };

    this.renderFile = this.renderFile.bind(this);
  }

  renderFile() {
    if(!this.state.fileActive) {
      this.setState({
        srcDoc: null,
        src: null
      });
    }
    else {
      let url = '/api/project/file/render';
      let self = this;
      $.ajax({
        url: url,
        method: 'POST',
        headers: { 'X-CSRFToken': window.glide.csrfToken },
        dataType: 'json',
        data: JSON.stringify({
          file: this.state.fileActive
        }),
        contentType: 'application/json; charset=utf-8',
        success: function(response) {
          // console.debug(response);
          if('error' in response) {
            // TODO
          }
          else {
            // Set state for changed files
            let src = 
              window.location.protocol + '//' +
              window.location.host + '/media/repos/'
              + self.state.repository.full_name + '/'
              + self.state.branch.name + '/'
              + window.glide.username.split('@')[0] + '/'
              + self.state.fileActive.path;

            self.setState({
              srcDoc: response.srcDoc,
              src: src
            }, function() {
              self.state.srcDoc == null &&
              self.state.src &&
              self.srcIFrame.contentWindow.location.reload();
            });
          }
        }
      });
    }
  }

  componentDidMount() {
    let self = this;
    this.setState({
      repository: this.props.repository,<commit_msg>fix bug that downloads non-md files when rendering requested<commit_after>// 
// RendererPane component
// 
class RendererPane extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      repository: null,
      branch: null,
      fileActive: null,
      srcDoc: null,
      src: null
    };

    this.renderFile = this.renderFile.bind(this);
  }

  renderFile() {
    if(!this.state.fileActive) {
      this.setState({
        srcDoc: null,
        src: null
      });
    }
    else {
      let url = '/api/project/file/render';
      let self = this;
      $.ajax({
        url: url,
        method: 'POST',
        headers: { 'X-CSRFToken': window.glide.csrfToken },
        dataType: 'json',
        data: JSON.stringify({
          file: this.state.fileActive
        }),
        contentType: 'application/json; charset=utf-8',
        success: function(response) {
          // console.debug(response);
          if('error' in response) {
            // TODO
          }
          else {
            // Set state for changed files
            let src = null;
            if(self.state.fileActive.path.endsWith('html') ||
              self.state.fileActive.path.endsWith('htm')) {
              src =
              window.location.protocol + '//' +
              window.location.host + '/media/repos/'
              + self.state.repository.full_name + '/'
              + self.state.branch.name + '/'
              + window.glide.username.split('@')[0] + '/'
              + self.state.fileActive.path;
            }

            self.setState({
              srcDoc: response.srcDoc,
              src: src
            }, function() {
              self.state.srcDoc == null &&
              self.state.src &&
              self.srcIFrame.contentWindow.location.reload();
            });
          }
        }
      });
    }
  }

  componentDidMount() {
    let self = this;
    this.setState({
      repository: this.props.repository,
{'fraction_non_alphanumeric': 0.13267485317672184, 'fraction_numerical': 0.0010678056593699946, 'mean_word_length': 1.4700065919578114, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3613045', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1061, 'n_words': 195}