<commit_before>import * as React from 'react'
import {debounce} from 'lodash-es'
import * as Container from '../../util/container'
import * as Kb from '../../common-adapters'
import * as Styles from '../../styles'
import * as TeamBuildingGen from '../../actions/team-building-gen'
import {AllowedNamespace} from '../../constants/types/team-building'
import {validateEmailAddress} from '../../util/email-address'
import ContinueButton from '../continue-button'

type EmailInputProps = {
  namespace: AllowedNamespace
}

const EmailInput = ({namespace}: EmailInputProps) => {
  const [isEmailValid, setEmailValidity] = React.useState(false)
  const [emailString, setEmailString] = React.useState('')
  const dispatch = Container.useDispatch()
  const user = Container.useSelector(state => {
    return state[namespace].teamBuilding.teamBuildingEmailResult
  })
  const isSearching = Container.useSelector(
    state => state[namespace].teamBuilding.teamBuildingEmailIsSearching
  )
  const canSubmit = user !== null && !isSearching && isEmailValid
  const emailHasKeybaseAccount =
    user !== null && user.serviceMap.keybase !== '' && emailString === user.username

  const debouncedSearch = React.useCallback(
    debounce((query: string) => dispatch(TeamBuildingGen.createSearchEmailAddress({namespace, query})), 200),
    [dispatch, namespace]
  )

  const onChange = React.useCallback(
    text => {
      setEmailString(text)
      const isNewInputValid = validateEmailAddress(text)
      if (isNewInputValid !== isEmailValid) {
        setEmailValidity(isNewInputValid)
      }
      if (isNewInputValid) {
        debouncedSearch(text)
      }
    },
    [isEmailValid, debouncedSearch]
  )

  const onSubmit = React.useCallback(() => {
    if (user === null || !canSubmit) {
      return
    }
<commit_msg>Trim whitespace in new chat->email address field (#19188)<commit_after>import * as React from 'react'
import {debounce} from 'lodash-es'
import * as Container from '../../util/container'
import * as Kb from '../../common-adapters'
import * as Styles from '../../styles'
import * as TeamBuildingGen from '../../actions/team-building-gen'
import {AllowedNamespace} from '../../constants/types/team-building'
import {validateEmailAddress} from '../../util/email-address'
import ContinueButton from '../continue-button'

type EmailInputProps = {
  namespace: AllowedNamespace
}

const EmailInput = ({namespace}: EmailInputProps) => {
  const [isEmailValid, setEmailValidity] = React.useState(false)
  const [emailString, setEmailString] = React.useState('')
  const dispatch = Container.useDispatch()
  const user = Container.useSelector(state => {
    return state[namespace].teamBuilding.teamBuildingEmailResult
  })
  const isSearching = Container.useSelector(
    state => state[namespace].teamBuilding.teamBuildingEmailIsSearching
  )
  const canSubmit = user !== null && !isSearching && isEmailValid
  const emailHasKeybaseAccount =
    user !== null && user.serviceMap.keybase !== '' && emailString === user.username

  const debouncedSearch = React.useCallback(
    debounce((query: string) => dispatch(TeamBuildingGen.createSearchEmailAddress({namespace, query})), 200),
    [dispatch, namespace]
  )

  const onChange = React.useCallback(
    text => {
      // Remove leading or trailing whitespace
      text = text.trim()
      setEmailString(text)
      const isNewInputValid = validateEmailAddress(text)
      if (isNewInputValid !== isEmailValid) {
        setEmailValidity(isNewInputValid)
      }
      if (isNewInputValid) {
        debouncedSearch(text)
      }
    },
    [isEmailValid, debouncedSearch]
  )

  const onSubmit = React.useCallback(() => {
    if (user === null || !canSubmit) {
      return
    }

{'fraction_non_alphanumeric': 0.13121325494388028, 'fraction_numerical': 0.002939604489577766, 'mean_word_length': 3.8296774193548386, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '5889146', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1047, 'n_words': 250}