<commit_before>"use strict";

const React = require("react");
const {DOM: dom} = React;
const { bindActionCreators } = require("redux");
const { connect } = require("react-redux");
const actions = require("../actions");
const { getSelectedSource } = require("../queries");
require("./Sources.css");

function renderSource({source, selectSource, selectedSource}) {
  const pathname = (new URL(source.get("url"))).pathname;
  const isSelected = (selectedSource &&
                      selectedSource.actor == source.get("actor"))
                      ? "selected" : "";

  return dom.li(
    { onClick: () => selectSource(source.toJS()),
      className: "source-item " + isSelected,
      style: { paddingLeft: "40px" },
      key: source.get("url")},
    pathname
  );
}

/**
 * Takes a sources object indexed by actor and
 * returns a sources object indexed by source domain.
 *
 * @returns Object
 */
function groupSourcesByDomain(sources) {
  return sources.valueSeq()
    .filter(source => !!source.get("url"))
    .groupBy(source => (new URL(source.get("url"))).hostname);
}

function Sources({ sources, selectSource, selectedSource }) {
  const sourcesByDomain = groupSourcesByDomain(sources);

  return dom.ul(
    {className: "sources-list"},
    sourcesByDomain.map((domainSources, domain) => {
      return dom.li({ key: domain, className: "domain" },
        dom.span({style: { paddingLeft: "20px" }}, domain),
        dom.ul(null,
          domainSources.map(source => renderSource({
            source, selectSource, selectedSource }))
        )
      );
    })
  );
}

module.exports = connect(
  state => ({ selectedSource: getSelectedSource(state) }),
  dispatch => bindActionCreators(actions, dispatch)
)(Sources);
<commit_msg>Fix isSelected comparison for source list<commit_after>"use strict";

const React = require("react");
const {DOM: dom} = React;
const { bindActionCreators } = require("redux");
const { connect } = require("react-redux");
const actions = require("../actions");
const { getSelectedSource } = require("../queries");
require("./Sources.css");

function renderSource({source, selectSource, selectedSource}) {
  const pathname = (new URL(source.get("url"))).pathname;
  const isSelected = (selectedSource &&
                      selectedSource.get("actor") == source.get("actor"))
                      ? "selected" : "";

  return dom.li(
    { onClick: () => selectSource(source.toJS()),
      className: "source-item " + isSelected,
      style: { paddingLeft: "40px" },
      key: source.get("url")},
    pathname
  );
}

/**
 * Takes a sources object indexed by actor and
 * returns a sources object indexed by source domain.
 *
 * @returns Object
 */
function groupSourcesByDomain(sources) {
  return sources.valueSeq()
    .filter(source => !!source.get("url"))
    .groupBy(source => (new URL(source.get("url"))).hostname);
}

function Sources({ sources, selectSource, selectedSource }) {
  const sourcesByDomain = groupSourcesByDomain(sources);

  return dom.ul(
    {className: "sources-list"},
    sourcesByDomain.map((domainSources, domain) => {
      return dom.li({ key: domain, className: "domain" },
        dom.span({style: { paddingLeft: "20px" }}, domain),
        dom.ul(null,
          domainSources.map(source => renderSource({
            source, selectSource, selectedSource }))
        )
      );
    })
  );
}

module.exports = connect(
  state => ({ selectedSource: getSelectedSource(state) }),
  dispatch => bindActionCreators(actions, dispatch)
)(Sources);

{'fraction_non_alphanumeric': 0.15990927133541252, 'fraction_numerical': 0.0022682166146867026, 'mean_word_length': 3.5, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '1969609', 'n_tokens_mistral': 1016, 'n_tokens_neox': 1001, 'n_words': 235}