<commit_before>import React, { PropTypes } from 'react';
import { renderToString } from 'react-dom/lib/ReactServerRendering';

const LOGIN_BOX_ID = 'login-box';

const fetchRawSvg = (url) => {
  const request = new XMLHttpRequest();
  request.open('GET', url, false);
  request.send();
  return request.responseText;
};

const Logo = (props) => {
  const existing = document.querySelector('.logo');
  if (existing !== null) existing.remove();

  if (props.src.endsWith('svg')) {
    const elementHtml = fetchRawSvg(props.src);
    document.getElementById(LOGIN_BOX_ID).insertAdjacentHTML(
      'afterbegin',
      elementHtml
    );
    const inlined = document.querySelector('svg');
    inlined.removeAttribute('height');
    inlined.setAttribute('class', 'logo');
  } else {
    const img = <img src={props.src} className={'logo'} />;
    document.getElementById(LOGIN_BOX_ID).insertAdjacentHTML(
      'afterbegin',
      renderToString(img)
    );
  }
  return null;
};

Logo.propTypes = {
  src: PropTypes.string,<commit_msg>refactors some common logic in Logo<commit_after>import React, { PropTypes } from 'react';
import { renderToString } from 'react-dom/lib/ReactServerRendering';

const LOGIN_BOX_ID = 'login-box';
const LOGO_CLASS = 'logo';

const fetchRawSvg = (url) => {
  const request = new XMLHttpRequest();
  request.open('GET', url, false);
  request.send();
  return request.responseText;
};

const insertHtmlAtMountpoint = (html) =>
  document.getElementById(LOGIN_BOX_ID).insertAdjacentHTML('afterbegin', html);

const Logo = (props) => {
  const existing = document.querySelector(`.${LOGO_CLASS}`);
  if (existing !== null) existing.remove();

  if (props.src.endsWith('svg')) {
    insertHtmlAtMountpoint(fetchRawSvg(props.src));
    const inlined = document.querySelector('svg');
    inlined.removeAttribute('height');
    inlined.setAttribute('class', LOGO_CLASS);
  } else {
    const img = <img src={props.src} className={LOGO_CLASS} />;
    insertHtmlAtMountpoint(renderToString(img))
  }
  return null;
};

Logo.propTypes = {
  src: PropTypes.string.isRequired,
{'fraction_non_alphanumeric': 0.1492109038737446, 'fraction_numerical': 0.0, 'mean_word_length': 4.578666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '2389230', 'n_tokens_mistral': 654, 'n_tokens_neox': 666, 'n_words': 131}