<commit_before>import React, { Component } from "react"
import { createPaginationContainer, graphql, RelayPaginationProp } from "react-relay"

import { ActivityIndicator, FlatList, View } from "react-native"

import SwitchBoard from "../../../NativeModules/SwitchBoard"
import ConversationSnippet from "./ConversationSnippet"

import { PAGE_SIZE } from "lib/data/constants"

import { Flex, Serif, Spacer } from "@artsy/palette"
import { Conversations_me } from "__generated__/Conversations_me.graphql"
import { get } from "lib/utils/get"

interface Props {
  me: Conversations_me
  relay: RelayPaginationProp
  headerView?: JSX.Element
  onRefresh?: () => any
}

interface State {
  isLoading?: boolean
}

export class Conversations extends Component<Props, State> {
  state = {
    isLoading: false,
  }

  fetchData = () => {
    const { relay } = this.props

    if (relay.hasMore() && !relay.isLoading()) {
      this.setState({
        isLoading: true,
      })
      relay.loadMore(PAGE_SIZE, error => {
        if (error) {
          console.error("Conversations/index.tsx #fetchData", error.message)
          // FIXME: Handle error
        }

        this.setState({
          isLoading: false,
        })
      })
    }
  }

  refreshConversations = (callback?: () => void) => {
    const { relay } = this.props

    if (!relay.isLoading()) {
      relay.refetchConnection(PAGE_SIZE, error => {
        if (error) {
          console.error("Conversations/index.tsx #refreshConversations", error.message)
          // FIXME: Handle error
        }

        if (callback) {
          callback()
        }
      })
    } else {
      if (callback) {
        callback()
      }
    }
  }

  render() {
    const conversations = get(this.props, ({ me }) => me.conversations.edges.map(edge => edge.node), [])

    return (
      <View>
        <Flex m={2}>{conversations.length > 0 && <Serif size="8">Messages</Serif>}</Flex>
        <FlatList
          data={conversations}
          keyExtractor={(_item, index) => String(index)}
          scrollEventThrottle={500}
          ItemSeparatorComponent={() => <Spacer mb={1} />}
          renderItem={({ item }) => {
            return (
              <ConversationSnippet<commit_msg>cleanup Conversations<commit_after>import React, { Component } from "react"
import { createPaginationContainer, graphql, RelayPaginationProp } from "react-relay"

import { ActivityIndicator, FlatList, View } from "react-native"

import SwitchBoard from "../../../NativeModules/SwitchBoard"
import ConversationSnippet from "./ConversationSnippet"

import { PAGE_SIZE } from "lib/data/constants"

import { Flex, Serif, Spacer } from "@artsy/palette"
import { Conversations_me } from "__generated__/Conversations_me.graphql"
import { get } from "lib/utils/get"

interface Props {
  me: Conversations_me
  relay: RelayPaginationProp
  headerView?: JSX.Element
  onRefresh?: () => any
}

interface State {
  isLoading?: boolean
}

export class Conversations extends Component<Props, State> {
  state = {
    isLoading: false,
  }

  fetchData = () => {
    const { relay } = this.props

    if (relay.hasMore() && !relay.isLoading()) {
      this.setState({
        isLoading: true,
      })
      relay.loadMore(PAGE_SIZE, error => {
        if (error) {
          console.error("Conversations/index.tsx #fetchData", error.message)
          // FIXME: Handle error
        }

        this.setState({
          isLoading: false,
        })
      })
    }
  }

  refreshConversations = (callback?: () => void) => {
    const { relay } = this.props

    if (!relay.isLoading()) {
      relay.refetchConnection(PAGE_SIZE, error => {
        if (error) {
          console.error("Conversations/index.tsx #refreshConversations", error.message)
          // FIXME: Handle error
        }

        if (callback) {
          callback()
        }
      })
    } else {
      if (callback) {
        callback()
      }
    }
  }

  render() {
    const conversations = get(this.props, ({ me }) => me.conversations.edges.map(edge => edge.node), [])

    if (conversations.length === 0) {
      return null
    }

    return (
      <View>
        <Serif m={2} size="8">
          Messages
        </Serif>
        <FlatList
          data={conversations}
          keyExtractor={item => item.internalID}
          ItemSeparatorComponent={() => <Spacer mb={1} />}
          renderItem={({ item }) => {
            return (
              <ConversationSnippet
{'fraction_non_alphanumeric': 0.1353887399463807, 'fraction_numerical': 0.0024575513851653264, 'mean_word_length': 2.4201680672268906, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 38, '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': '5322176', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1369, 'n_words': 285}