<commit_before>// @flow
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { StyleSheet, View, SectionList, Text } from 'react-native';
import * as Animatable from 'react-native-animatable';
import { TrelloCard, LottieAnimation } from 'DailyScrum/src/components';
import type { CardListsType, CardListType } from 'DailyScrum/src/modules/cards/reducer';
import type { CardType } from '../../types';
import { ListHeader } from './';
import { getTipIfNotReadSelector } from '../../modules/tips/reducer';
import type { TipType } from '../../modules/tips/reducer';
import TipCard from '../TipCard';

class CardsList extends Component {
  props: PropsType;

  renderCard = ({ item }: { item: CardType }) => <TrelloCard card={item} />;
  renderSectionHeader = ({ section }: { section: any }) =>
    section.data.length ? <ListHeader listKey={section.key} total={section.points} /> : null;

  renderEmpty = () =>
    <View style={styles.emptyContainer}>
      <Text>No cards yet</Text>
      <Text>Pull to refresh :)</Text>
      <LottieAnimation source={require('../../../assets/lottie/empty_status.json')} duration={6000} />
    </View>;

  renderTip = () =>
    this.props.tip &&
    <View style={styles.tipContainer}>
      <TipCard tip={this.props.tip} />
    </View>;

  render() {
    const { cardLists } = this.props;
    // $FlowFixMe https://github.com/facebook/flow/issues/2221
    const sections = Object.entries(cardLists)
      .map(([columnKey, column]: [string, CardListType]) => ({
        key: columnKey,
        points: column.points,
        data: column.list.filter(
          card => (this.props.filteredMember ? card.idMembers.includes(this.props.filteredMember) : true)
        ),
      }))
      .filter(section => section.data.length > 0);

    return (
      <View style={[styles.container, this.props.style]}>
        <Animatable.View animation="fadeIn" style={{ flex: 1 }}>
          <SectionList
            contentContainerStyle={styles.listsContainer}
            showsVerticalScrollIndicator={false}
            refreshing={this.props.isRefreshing}
            onRefresh={this.props.onRefresh}
            SectionSeparatorComponent={() => <View style={styles.listSeparator} />}
            renderSectionHeader={this.renderSectionHeader}
            renderItem={this.renderCard}
            ListHeaderComponent={this.renderTip}
            ListEmptyComponent={this.renderEmpty}
            keyExtractor={(card: CardType) => card.idShort}
            sections={sections}
          />
        </Animatable.View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flexGrow: 1,
  },
  emptyContainer: {
    marginTop: 100,
    alignItems: 'center',
  },
  listsContainer: {
    paddingVertical: 10,
  },
  listName: {
    marginBottom: 5,
  },
  listSeparator: {
    marginTop: 20,
  },
  tipContainer: {<commit_msg>[CardLists] Don't show tip if there are no cards<commit_after>// @flow
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { StyleSheet, View, SectionList, Text } from 'react-native';
import * as Animatable from 'react-native-animatable';
import { TrelloCard, LottieAnimation } from 'DailyScrum/src/components';
import type { CardListsType, CardListType } from 'DailyScrum/src/modules/cards/reducer';
import type { CardType } from '../../types';
import { ListHeader } from './';
import { getTipIfNotReadSelector } from '../../modules/tips/reducer';
import type { TipType } from '../../modules/tips/reducer';
import TipCard from '../TipCard';

class CardsList extends Component {
  props: PropsType;

  renderCard = ({ item }: { item: CardType }) => <TrelloCard card={item} />;
  renderSectionHeader = ({ section }: { section: any }) =>
    section.data.length ? <ListHeader listKey={section.key} total={section.points} /> : null;

  renderEmpty = () =>
    <View style={styles.emptyContainer}>
      <Text>No cards yet</Text>
      <Text>Pull to refresh :)</Text>
      <LottieAnimation source={require('../../../assets/lottie/empty_status.json')} duration={6000} />
    </View>;

  renderTip = () =>
    this.props.tip &&
    <View style={styles.tipContainer}>
      <TipCard tip={this.props.tip} />
    </View>;

  render() {
    const { cardLists } = this.props;
    // $FlowFixMe https://github.com/facebook/flow/issues/2221
    const sections = Object.entries(cardLists)
      .map(([columnKey, column]: [string, CardListType]) => ({
        key: columnKey,
        points: column.points,
        data: column.list.filter(
          card => (this.props.filteredMember ? card.idMembers.includes(this.props.filteredMember) : true)
        ),
      }))
      .filter(section => section.data.length > 0);

    return (
      <View style={[styles.container, this.props.style]}>
        <Animatable.View animation="fadeIn" style={{ flex: 1 }}>
          <SectionList
            contentContainerStyle={styles.listsContainer}
            showsVerticalScrollIndicator={false}
            refreshing={this.props.isRefreshing}
            onRefresh={this.props.onRefresh}
            SectionSeparatorComponent={() => <View style={styles.listSeparator} />}
            renderSectionHeader={this.renderSectionHeader}
            renderItem={this.renderCard}
            ListHeaderComponent={() => sections.length > 0 && this.renderTip()}
            ListEmptyComponent={this.renderEmpty}
            keyExtractor={(card: CardType) => card.idShort}
            sections={sections}
          />
        </Animatable.View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flexGrow: 1,
  },
  emptyContainer: {
    marginTop: 100,
    alignItems: 'center',
  },
  listsContainer: {
    paddingVertical: 10,
  },
  listName: {
    marginBottom: 5,
  },
  listSeparator: {
    marginTop: 20,
  },
  tipContainer: {
{'fraction_non_alphanumeric': 0.15202587674497786, 'fraction_numerical': 0.006639427987742594, 'mean_word_length': 2.9218958611481978, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 61, 'https://': 2, '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': '1994370', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1730, 'n_words': 353}