<commit_before>import * as React from 'react'
import { Repository as Repo } from '../models/repository'
import { UiView } from './ui-view'
import { Changes } from './changes'
import { History } from './history'
import { TabBar } from './tab-bar'
import { IRepositoryState as IRepositoryModelState, RepositorySection } from '../lib/app-state'
import { Dispatcher } from '../lib/dispatcher'

interface IRepositoryProps {
  readonly repository: Repo
  readonly state: IRepositoryModelState
  readonly dispatcher: Dispatcher
  readonly emoji: Map<string, string>
}

const enum Tab {
  Changes = 0,
  History = 1,
}

export class RepositoryView extends React.Component<IRepositoryProps, void> {

  private renderTabs() {
    const hasChanges = this.props.state.changesState.workingDirectory.files.length > 0
    const selectedTab = this.props.state.selectedSection === RepositorySection.Changes
      ? Tab.Changes
      : Tab.History

    return (
      <TabBar selectedIndex={selectedTab} onTabClicked={index => this.onTabClicked(index)}>
        <span>
          <span>Changes</span>
          {hasChanges ? <span className='indicator'/> : null}
        </span>
        <span>History</span>
      </TabBar>
    )
  }

  private renderContent() {
    if (this.props.state.selectedSection === RepositorySection.Changes) {
      const branch = this.props.state.branchesState.currentBranch
      const localCommitSHAs = this.props.state.localCommitSHAs
      const mostRecentLocalCommitSHA = localCommitSHAs.length > 0 ? localCommitSHAs[0] : null
      const mostRecentLocalCommit = (mostRecentLocalCommitSHA ? this.props.state.commits.get(mostRecentLocalCommitSHA) : null) || null

      return <Changes repository={this.props.repository}
                      dispatcher={this.props.dispatcher}
                      changes={this.props.state.changesState}
                      branch={branch ? branch.name : null}
                      commitAuthor={this.props.state.commitAuthor}
                      gitHubUsers={this.props.state.gitHubUsers}
                      emoji={this.props.emoji}
                      mostRecentLocalCommit={mostRecentLocalCommit}/>
    } else if (this.props.state.selectedSection === RepositorySection.History) {
      return <History repository={this.props.repository}
                      dispatcher={this.props.dispatcher}
                      history={this.props.state.historyState}
                      gitHubUsers={this.props.state.gitHubUsers}
                      emoji={this.props.emoji}
                      commits={this.props.state.commits}/>
    } else {
      return null
    }
  }

  public render() {
    return (
      <UiView id='repository' onKeyDown={(e) => this.onKeyDown(e)}>
        {this.renderTabs()}
        {this.renderContent()}
      </UiView>
    )
  }

  private onKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {
    // Toggle tab selection on Ctrl+Tab. Note that we don't care
    // about the shift key here, we can get away with that as long
    // as there's only two tabs.
    if (e.ctrlKey && e.key === 'Tab') {<commit_msg>Exhaustive check<commit_after>import * as React from 'react'
import { Repository as Repo } from '../models/repository'
import { UiView } from './ui-view'
import { Changes } from './changes'
import { History } from './history'
import { TabBar } from './tab-bar'
import { IRepositoryState as IRepositoryModelState, RepositorySection } from '../lib/app-state'
import { Dispatcher } from '../lib/dispatcher'
import { assertNever } from '../lib/fatal-error'

interface IRepositoryProps {
  readonly repository: Repo
  readonly state: IRepositoryModelState
  readonly dispatcher: Dispatcher
  readonly emoji: Map<string, string>
}

const enum Tab {
  Changes = 0,
  History = 1,
}

export class RepositoryView extends React.Component<IRepositoryProps, void> {

  private renderTabs() {
    const hasChanges = this.props.state.changesState.workingDirectory.files.length > 0
    const selectedTab = this.props.state.selectedSection === RepositorySection.Changes
      ? Tab.Changes
      : Tab.History

    return (
      <TabBar selectedIndex={selectedTab} onTabClicked={index => this.onTabClicked(index)}>
        <span>
          <span>Changes</span>
          {hasChanges ? <span className='indicator'/> : null}
        </span>
        <span>History</span>
      </TabBar>
    )
  }

  private renderContent() {
    const selectedSection = this.props.state.selectedSection

    if (selectedSection === RepositorySection.Changes) {
      const branch = this.props.state.branchesState.currentBranch
      const localCommitSHAs = this.props.state.localCommitSHAs
      const mostRecentLocalCommitSHA = localCommitSHAs.length > 0 ? localCommitSHAs[0] : null
      const mostRecentLocalCommit = (mostRecentLocalCommitSHA ? this.props.state.commits.get(mostRecentLocalCommitSHA) : null) || null

      return <Changes repository={this.props.repository}
                      dispatcher={this.props.dispatcher}
                      changes={this.props.state.changesState}
                      branch={branch ? branch.name : null}
                      commitAuthor={this.props.state.commitAuthor}
                      gitHubUsers={this.props.state.gitHubUsers}
                      emoji={this.props.emoji}
                      mostRecentLocalCommit={mostRecentLocalCommit}/>
    } else if (selectedSection === RepositorySection.History) {
      return <History repository={this.props.repository}
                      dispatcher={this.props.dispatcher}
                      history={this.props.state.historyState}
                      gitHubUsers={this.props.state.gitHubUsers}
                      emoji={this.props.emoji}
                      commits={this.props.state.commits}/>
    } else {
      return assertNever(selectedSection, 'Unknown repository section')
    }
  }

  public render() {
    return (
      <UiView id='repository' onKeyDown={(e) => this.onKeyDown(e)}>
        {this.renderTabs()}
        {this.renderContent()}
      </UiView>
    )
  }

  private onKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {
    // Toggle tab selection on Ctrl+Tab. Note that we don't care
    // about the shift key here, we can get away with that as long
    // as there's only two tabs.
    if (e.ctrlKey && e.key === 'Tab') {
{'fraction_non_alphanumeric': 0.11191906417957635, 'fraction_numerical': 0.0015807777426493834, 'mean_word_length': 2.640391254315305, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 43, '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': '6311555', 'n_tokens_mistral': 1786, 'n_tokens_neox': 1745, 'n_words': 385}