<commit_before>import React, { Component } from 'react'
import classnames from 'classnames'
import ReactVirtualizedList from 'react-virtualized/dist/es/List'
import ReactVirtualizedAutoSizer from 'react-virtualized/dist/es/AutoSizer'

import getTotalScore from 'utils/getTotalScore'
import getMostRecentStudyDate from 'utils/getMostRecentStudyDate'

import './List.css'

export default class List extends Component {
  constructor(props) {
    super(props)

    // We are using local state to cache the sorted filtered words
    // so that it doesn't get computed with each render.
    // We pass in the props, because we want to reuse this function
    // in component will receive props.
    this.state = {
      filterSortedWords: this.filterAndSortWords(
        props.words,
        props.scores,
        props.tagFilter,
        props.wordsRoute.searchText,
        props.wordsRoute.sortBy
      )
    }
  }

  filterAndSortWords = (words, scores, tagFilter, searchText, sortBy) => {
    if (words.fetchStatus !== 'SUCCESS') {
      return []
    }

    const filteredSortedWords = []

    // The words are pre sorted by tags or hashmap by id
    // so if we have specified a tag, we don't have to look
    // as every word, we can directly look at the words that have that tag
    let wordsList
    if (tagFilter) {
      wordsList = words.byTag[tagFilter] || []
    } else {
      wordsList = Object.keys(words.byId)
    }

    for (let i = 0; i < wordsList.length; i++) {
      const word = words.byId[wordsList[i]]

      if (!searchText) {
        filteredSortedWords.push(word)
      } else if (
        word.english.toLowerCase().includes(searchText) ||
        word.persian.includes(searchText) ||
        word.phonetic.includes(searchText)
      ) {
        filteredSortedWords.push(word)
      }
    }

    filteredSortedWords.sort((wordA, wordB) => {
      if (sortBy === 'score') {
        const scoreA = getTotalScore(wordA._id, scores)
        const scoreB = getTotalScore(wordB._id, scores)

        // if one of the values is null
        if (scoreA === null) {
          if (scoreB === null) {
            return 0
          } else {
            return 1
          }
        } else if (scoreB === null) {
          return -1
        } else {
          return scoreB - scoreA
        }
      } else if (sortBy === 'mostRecentlyStudied') {
        const dateA = getMostRecentStudyDate(wordA._id, scores)
        const dateB = getMostRecentStudyDate(wordB._id, scores)

        if (dateA === null) {
          if (dateB === null) {
            return 0<commit_msg>make word search case-insensitve<commit_after>import React, { Component } from 'react'
import classnames from 'classnames'
import ReactVirtualizedList from 'react-virtualized/dist/es/List'
import ReactVirtualizedAutoSizer from 'react-virtualized/dist/es/AutoSizer'

import getTotalScore from 'utils/getTotalScore'
import getMostRecentStudyDate from 'utils/getMostRecentStudyDate'

import './List.css'

export default class List extends Component {
  constructor(props) {
    super(props)

    // We are using local state to cache the sorted filtered words
    // so that it doesn't get computed with each render.
    // We pass in the props, because we want to reuse this function
    // in component will receive props.
    this.state = {
      filterSortedWords: this.filterAndSortWords(
        props.words,
        props.scores,
        props.tagFilter,
        props.wordsRoute.searchText,
        props.wordsRoute.sortBy
      )
    }
  }

  filterAndSortWords = (words, scores, tagFilter, searchText, sortBy) => {
    if (words.fetchStatus !== 'SUCCESS') {
      return []
    }

    const filteredSortedWords = []

    // The words are pre sorted by tags or hashmap by id
    // so if we have specified a tag, we don't have to look
    // as every word, we can directly look at the words that have that tag
    let wordsList
    if (tagFilter) {
      wordsList = words.byTag[tagFilter] || []
    } else {
      wordsList = Object.keys(words.byId)
    }

    for (let i = 0; i < wordsList.length; i++) {
      const word = words.byId[wordsList[i]]

      if (!searchText) {
        filteredSortedWords.push(word)
      } else if (
        word.english.toLowerCase().includes(searchText) ||
        word.persian.toLowerCase().includes(searchText) ||
        word.phonetic.toLowerCase().includes(searchText)
      ) {
        filteredSortedWords.push(word)
      }
    }

    filteredSortedWords.sort((wordA, wordB) => {
      if (sortBy === 'score') {
        const scoreA = getTotalScore(wordA._id, scores)
        const scoreB = getTotalScore(wordB._id, scores)

        // if one of the values is null
        if (scoreA === null) {
          if (scoreB === null) {
            return 0
          } else {
            return 1
          }
        } else if (scoreB === null) {
          return -1
        } else {
          return scoreB - scoreA
        }
      } else if (sortBy === 'mostRecentlyStudied') {
        const dateA = getMostRecentStudyDate(wordA._id, scores)
        const dateB = getMostRecentStudyDate(wordB._id, scores)

        if (dateA === null) {
          if (dateB === null) {
            return 0
{'fraction_non_alphanumeric': 0.10143815915627996, 'fraction_numerical': 0.0019175455417066154, 'mean_word_length': 2.324410452517527, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1187459', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1503, 'n_words': 438}