Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClubListHeader.js 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // @flow
  2. import * as React from 'react';
  3. import {Card, Chip, List, Text} from 'react-native-paper';
  4. import {StyleSheet, View} from 'react-native';
  5. import i18n from 'i18n-js';
  6. import AnimatedAccordion from '../../Animations/AnimatedAccordion';
  7. import {isItemInCategoryFilter} from '../../../utils/Search';
  8. import type {ClubCategoryType} from '../../../screens/Amicale/Clubs/ClubListScreen';
  9. type PropsType = {
  10. categories: Array<ClubCategoryType>,
  11. onChipSelect: (id: number) => void,
  12. selectedCategories: Array<number>,
  13. };
  14. const styles = StyleSheet.create({
  15. card: {
  16. margin: 5,
  17. },
  18. text: {
  19. paddingLeft: 0,
  20. marginTop: 5,
  21. marginBottom: 10,
  22. marginLeft: 'auto',
  23. marginRight: 'auto',
  24. },
  25. chipContainer: {
  26. justifyContent: 'space-around',
  27. flexDirection: 'row',
  28. flexWrap: 'wrap',
  29. paddingLeft: 0,
  30. marginBottom: 5,
  31. },
  32. });
  33. class ClubListHeader extends React.Component<PropsType> {
  34. shouldComponentUpdate(nextProps: PropsType): boolean {
  35. const {props} = this;
  36. return (
  37. nextProps.selectedCategories.length !== props.selectedCategories.length
  38. );
  39. }
  40. getChipRender = (category: ClubCategoryType, key: string): React.Node => {
  41. const {props} = this;
  42. const onPress = (): void => props.onChipSelect(category.id);
  43. return (
  44. <Chip
  45. selected={isItemInCategoryFilter(props.selectedCategories, [
  46. category.id,
  47. null,
  48. ])}
  49. mode="outlined"
  50. onPress={onPress}
  51. style={{marginRight: 5, marginLeft: 5, marginBottom: 5}}
  52. key={key}>
  53. {category.name}
  54. </Chip>
  55. );
  56. };
  57. getCategoriesRender(): React.Node {
  58. const {props} = this;
  59. const final = [];
  60. props.categories.forEach((cat: ClubCategoryType) => {
  61. final.push(this.getChipRender(cat, cat.id.toString()));
  62. });
  63. return final;
  64. }
  65. render(): React.Node {
  66. return (
  67. <Card style={styles.card}>
  68. <AnimatedAccordion
  69. title={i18n.t('screens.clubs.categories')}
  70. left={({size}: {size: number}): React.Node => (
  71. <List.Icon size={size} icon="star" />
  72. )}
  73. opened>
  74. <Text style={styles.text}>
  75. {i18n.t('screens.clubs.categoriesFilterMessage')}
  76. </Text>
  77. <View style={styles.chipContainer}>{this.getCategoriesRender()}</View>
  78. </AnimatedAccordion>
  79. </Card>
  80. );
  81. }
  82. }
  83. export default ClubListHeader;