<commit_before>/* global embedly */
import PropTypes from 'prop-types';

import React from 'react';
import { connect } from 'react-redux';
import 'element-closest';

import ScrollSafe from './scroll-helpers/scroll-safe';
import * as heightCache from './scroll-helpers/size-cache';


class EmbedlyPreview extends React.Component {
  static propTypes = { url: PropTypes.string.isRequired, };

  link = null;
  state = { updCounter: 0, };

  setLink = (el) => this.link = el;

  componentDidMount() {
    embedly('card', this.link);
  }

  componentDidUpdate() {
    embedly('card', this.link);
  }

  componentWillReceiveProps(nextProps) {
    if (this.props.feedIsLoading && !nextProps.feedIsLoading) {
      this.setState({ updCounter: this.state.updCounter + 1 });
    }
  }

  render() {
    // We use 'key' to force re-render HTML-code on
    // the feed update or on the props.url change
    return (
      <div
        key={`${this.props.url}##${this.state.updCounter}`}
        className="embedly-preview link-preview-content"
        data-url={this.props.url}
        style={{ height: `${heightCache.get(this.props.url, 0)}px` }}
      >
        <a
          ref={this.setLink}
          href={this.props.url}
          data-card-controls="0"
          data-card-width="400px"
          data-card-recommend="0"
          data-card-align="left"
        />
      </div>
    );
  }
}

function select(state) {
  return { feedIsLoading: state.routeLoadingState, };
}

export default ScrollSafe(connect(select)(EmbedlyPreview));

embedly('on', 'card.resize', (iframe) => {
  const cont = iframe.closest('.embedly-preview');
  if (!cont) {
    return;
  }
  const height = iframe.offsetHeight;
  cont.style.height = `${height}px`;
  heightCache.set(cont.dataset.url, height);
});
<commit_msg>Use dark theme in embedlies<commit_after>/* global embedly */
import PropTypes from 'prop-types';

import React from 'react';
import { connect } from 'react-redux';
import 'element-closest';

import { darkTheme } from '../select-utils';
import ScrollSafe from './scroll-helpers/scroll-safe';
import * as heightCache from './scroll-helpers/size-cache';


class EmbedlyPreview extends React.Component {
  static propTypes = { url: PropTypes.string.isRequired, };

  link = null;
  state = { updCounter: 0, };

  setLink = (el) => this.link = el;

  componentDidMount() {
    embedly('card', this.link);
  }

  componentDidUpdate() {
    embedly('card', this.link);
  }

  componentWillReceiveProps(nextProps) {
    if (this.props.feedIsLoading && !nextProps.feedIsLoading) {
      this.setState({ updCounter: this.state.updCounter + 1 });
    }
  }

  render() {
    // We use 'key' to force re-render HTML-code on
    // the feed update or on the props.url change
    return (
      <div
        key={`${this.props.url}##${this.state.updCounter}`}
        className="embedly-preview link-preview-content"
        data-url={this.props.url}
        style={{ height: `${heightCache.get(this.props.url, 0)}px` }}
      >
        <a
          ref={this.setLink}
          href={this.props.url}
          data-card-controls="0"
          data-card-width="400px"
          data-card-recommend="0"
          data-card-align="left"
          data-card-theme={this.props.darkTheme ? 'dark' : 'light'}
        />
      </div>
    );
  }
}

function select(state) {
  return {
    feedIsLoading: state.routeLoadingState,
    darkTheme:     darkTheme(state),
  };
}

export default ScrollSafe(connect(select)(EmbedlyPreview));

embedly('on', 'card.resize', (iframe) => {
  const cont = iframe.closest('.embedly-preview');
  if (!cont) {
    return;
  }
  const height = iframe.offsetHeight;
  cont.style.height = `${height}px`;
  heightCache.set(cont.dataset.url, height);
});

{'fraction_non_alphanumeric': 0.15601703940362088, 'fraction_numerical': 0.004259850905218318, 'mean_word_length': 2.921711899791232, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '2875274', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1210, 'n_words': 245}