<commit_before>import { Box, Sans, Spacer } from "@artsy/palette"
import { PartnerOverview_partner } from "__generated__/PartnerOverview_partner.graphql"
import { ArtistListItemContainer as ArtistListItem } from "lib/Components/ArtistListItem"
import { ReadMore } from "lib/Components/ReadMore"
import { truncatedTextLimit } from "lib/Scenes/Artwork/hardware"
import { get } from "lib/utils/get"
import { isCloseToBottom } from "lib/utils/isCloseToBottom"
import React, { useState } from "react"
import { ScrollView } from "react-native"
import { createPaginationContainer, graphql, RelayPaginationProp } from "react-relay"
import { PartnerEmptyState } from "./PartnerEmptyState"
import { PartnerLocationSectionContainer as PartnerLocationSection } from "./PartnerLocationSection"

const textLimit = truncatedTextLimit()
const PAGE_SIZE = 10

export const PartnerOverview: React.FC<{
  partner: PartnerOverview_partner
  relay: RelayPaginationProp
}> = ({ partner, relay }) => {
  const [fetchingNextPage, setFetchingNextPage] = useState(false)
  const artists = partner.artists && partner.artists.edges

  const fetchNextPage = () => {
    if (fetchingNextPage || !partner.artists.pageInfo.endCursor) {
      return
    }
    setFetchingNextPage(true)
    relay.loadMore(PAGE_SIZE, error => {
      if (error) {
        // FIXME: Handle error
        console.error("PartnerArtwork.tsx", error.message)
      }
      setFetchingNextPage(false)
    })
  }

  const renderArtists = () => {
    return artists.map(artist => {
      const node = artist.node
      if (!node) {
        return null
      }
      return (
        <Box key={node.id}>
          <ArtistListItem artist={node} />
          <Spacer mb={2} />
        </Box>
      )
    })
  }

  const aboutText = get(partner, p => p.profile.bio)

  if (!aboutText && !artists && !partner.locations) {
    return <PartnerEmptyState text="There is no information for this gallery yet" />
  }

  return (
    <ScrollView onScroll={isCloseToBottom(fetchNextPage)}>
      <Box px={2} py={3}>
        {!!aboutText && (
          <>
            <Sans size="3t" weight="medium">
              About
            </Sans>
            <Spacer mb={2} />
            <ReadMore content={aboutText} maxChars={textLimit} />
            <Spacer mb={3} />
          </>
        )}
        <PartnerLocationSection partner={partner} />
        {!!artists && (
          <>
            <Sans size="3t" weight="medium">
              Artists
            </Sans>
            <Spacer mb={2} />
            {renderArtists()}
            <Spacer mb={3} />
          </>
        )}
      </Box>
    </ScrollView>
  )
}

export const PartnerOverviewFragmentContainer = createPaginationContainer(
  PartnerOverview,
  {
    partner: graphql`
      fragment PartnerOverview_partner on Partner
        @argumentDefinitions(count: { type: "Int", defaultValue: 10 }, cursor: { type: "String" }) {
        internalID
        name
        locations {
          city
        }<commit_msg>hide artists list when no artists (#1963)<commit_after>import { Box, Sans, Spacer } from "@artsy/palette"
import { PartnerOverview_partner } from "__generated__/PartnerOverview_partner.graphql"
import { ArtistListItemContainer as ArtistListItem } from "lib/Components/ArtistListItem"
import { ReadMore } from "lib/Components/ReadMore"
import { truncatedTextLimit } from "lib/Scenes/Artwork/hardware"
import { get } from "lib/utils/get"
import { isCloseToBottom } from "lib/utils/isCloseToBottom"
import React, { useState } from "react"
import { ScrollView } from "react-native"
import { createPaginationContainer, graphql, RelayPaginationProp } from "react-relay"
import { PartnerEmptyState } from "./PartnerEmptyState"
import { PartnerLocationSectionContainer as PartnerLocationSection } from "./PartnerLocationSection"

const textLimit = truncatedTextLimit()
const PAGE_SIZE = 10

export const PartnerOverview: React.FC<{
  partner: PartnerOverview_partner
  relay: RelayPaginationProp
}> = ({ partner, relay }) => {
  const [fetchingNextPage, setFetchingNextPage] = useState(false)
  const artists = partner.artists && partner.artists.edges

  const fetchNextPage = () => {
    if (fetchingNextPage || !partner.artists.pageInfo.endCursor) {
      return
    }
    setFetchingNextPage(true)
    relay.loadMore(PAGE_SIZE, error => {
      if (error) {
        // FIXME: Handle error
        console.error("PartnerArtwork.tsx", error.message)
      }
      setFetchingNextPage(false)
    })
  }

  const renderArtists = () => {
    return artists.map(artist => {
      const node = artist.node
      if (!node) {
        return null
      }
      return (
        <Box key={node.id}>
          <ArtistListItem artist={node} />
          <Spacer mb={2} />
        </Box>
      )
    })
  }

  const aboutText = get(partner, p => p.profile.bio)

  if (!aboutText && !artists && !partner.locations) {
    return <PartnerEmptyState text="There is no information for this gallery yet" />
  }

  return (
    <ScrollView onScroll={isCloseToBottom(fetchNextPage)}>
      <Box px={2} py={3}>
        {!!aboutText && (
          <>
            <Sans size="3t" weight="medium">
              About
            </Sans>
            <Spacer mb={2} />
            <ReadMore content={aboutText} maxChars={textLimit} />
            <Spacer mb={3} />
          </>
        )}
        <PartnerLocationSection partner={partner} />
        {!!artists &&
          artists.length > 0 && (
            <>
              <Sans size="3t" weight="medium">
                Artists
              </Sans>
              <Spacer mb={2} />
              {renderArtists()}
              <Spacer mb={3} />
            </>
          )}
      </Box>
    </ScrollView>
  )
}

export const PartnerOverviewFragmentContainer = createPaginationContainer(
  PartnerOverview,
  {
    partner: graphql`
      fragment PartnerOverview_partner on Partner
        @argumentDefinitions(count: { type: "Int", defaultValue: 10 }, cursor: { type: "String" }) {
        internalID
        name
        locations {
          city
        }
{'fraction_non_alphanumeric': 0.1212668198227765, 'fraction_numerical': 0.00508697079094191, 'mean_word_length': 2.551864801864802, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 64, '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': '7655529', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1799, 'n_words': 394}