<commit_before>import React, {Component} from 'react';
import {
  Dropdown,
  DropdownMenu,
  DropdownToggle,
  DropdownItem,
} from 'reactstrap';
import FontAwesomeIcon from '@fortawesome/react-fontawesome';

class NotificationIcon extends Component {
  constructor(props) {
    super(props);

    this.state = {
      dropdownOpen: false,
      notifications: [
        {
          url: 'https://example.com/register',
          message: 'time to register for finals',
          isRead: false,
        },
        {
          url: 'https://example.com/game',
          message: 'get tickets to the big game',
          isRead: true,
        },
      ],
    };
  }

  toggle = () => {
    this.setState({
      dropdownOpen: !this.state.dropdownOpen,
    });
  };

  renderEmpty = () => (
    <DropdownItem className="up-notification--menu-item" disabled>
      congrats no notifications
    </DropdownItem>
  );

  renderOneOrMany = () =>
    this.state.notifications.map(({url, message, isRead}) => (
      <DropdownItem
        tag="a"
        className={'up-notification--menu-item ' + (isRead ? 'read' : 'unread')}
        href={url}
      >
        {message}
      </DropdownItem>
    ));

  render() {
    return (
      <Dropdown
        isOpen={this.state.dropdownOpen}
        toggle={this.toggle}
        className="up-notification"
      >
        <DropdownToggle
          onClick={this.toggle}
          className="up-notification--toggle"
        >
          <span className="sr-only">notifications</span>
          <FontAwesomeIcon icon="bell" />
        </DropdownToggle>
        <DropdownMenu className="up-notification--menu">
          <DropdownItem className="up-notification--menu-header" header>
            Notifications
          </DropdownItem>
          {this.state.notifications.length < 1
            ? this.renderEmpty()
            : this.renderOneOrMany()}
          <DropdownItem
            className="up-notification--menu-footer"
            tag="a"
            href="/p/notifications"
            header
          >
            see all notifications
          </DropdownItem>
        </DropdownMenu>
      </Dropdown>
    );
  }
}

export default NotificationIcon;<commit_msg>refactor: combine render empty and one or many into render notifications<commit_after>import React, {Component} from 'react';
import {
  Dropdown,
  DropdownMenu,
  DropdownToggle,
  DropdownItem,
} from 'reactstrap';
import FontAwesomeIcon from '@fortawesome/react-fontawesome';

class NotificationIcon extends Component {
  constructor(props) {
    super(props);

    this.state = {
      dropdownOpen: false,
      notifications: [
        {
          url: 'https://example.com/register',
          message: 'time to register for finals',
          isRead: false,
        },
        {
          url: 'https://example.com/game',
          message: 'get tickets to the big game',
          isRead: true,
        },
      ],
    };
  }

  toggle = () => {
    this.setState({
      dropdownOpen: !this.state.dropdownOpen,
    });
  };

  renderNotifications = () =>
    this.state.notifications.length < 1 ? (
      <DropdownItem className="up-notification--menu-item" disabled>
        congrats no notifications
      </DropdownItem>
    ) : (
      this.state.notifications.map(({url, message, isRead}) => (
        <DropdownItem
          tag="a"
          className={
            'up-notification--menu-item ' + (isRead ? 'read' : 'unread')
          }
          href={url}
        >
          {message}
        </DropdownItem>
      ))
    );

  render = () => (
    <Dropdown
      isOpen={this.state.dropdownOpen}
      toggle={this.toggle}
      className="up-notification"
    >
      <DropdownToggle onClick={this.toggle} className="up-notification--toggle">
        <span className="sr-only">notifications</span>
        <FontAwesomeIcon icon="bell" />
      </DropdownToggle>
      <DropdownMenu className="up-notification--menu">
        <DropdownItem className="up-notification--menu-header" header>
          Notifications
        </DropdownItem>
        {this.renderNotifications()}
        <DropdownItem
          className="up-notification--menu-footer"
          tag="a"
          href="/p/notifications"
          header
        >
          see all notifications
        </DropdownItem>
      </DropdownMenu>
    </Dropdown>
  );
}

export default NotificationIcon;
{'fraction_non_alphanumeric': 0.12801273306048203, 'fraction_numerical': 0.00045475216007276033, 'mean_word_length': 2.044290657439446, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 45, 'https://': 4, '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': '4934121', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1238, 'n_words': 229}