Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
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.5KB

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