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 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2019 - 2020 Arnaud Vergnet.
  3. *
  4. * This file is part of Campus INSAT.
  5. *
  6. * Campus INSAT is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Campus INSAT is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. // @flow
  20. import * as React from 'react';
  21. import {Card, Chip, List, Text} from 'react-native-paper';
  22. import {StyleSheet, View} from 'react-native';
  23. import i18n from 'i18n-js';
  24. import AnimatedAccordion from '../../Animations/AnimatedAccordion';
  25. import {isItemInCategoryFilter} from '../../../utils/Search';
  26. import type {ClubCategoryType} from '../../../screens/Amicale/Clubs/ClubListScreen';
  27. import type {ListIconPropsType} from '../../../constants/PaperStyles';
  28. type PropsType = {
  29. categories: Array<ClubCategoryType>,
  30. onChipSelect: (id: number) => void,
  31. selectedCategories: Array<number>,
  32. };
  33. const styles = StyleSheet.create({
  34. card: {
  35. margin: 5,
  36. },
  37. text: {
  38. paddingLeft: 0,
  39. marginTop: 5,
  40. marginBottom: 10,
  41. marginLeft: 'auto',
  42. marginRight: 'auto',
  43. },
  44. chipContainer: {
  45. justifyContent: 'space-around',
  46. flexDirection: 'row',
  47. flexWrap: 'wrap',
  48. paddingLeft: 0,
  49. marginBottom: 5,
  50. },
  51. });
  52. class ClubListHeader extends React.Component<PropsType> {
  53. shouldComponentUpdate(nextProps: PropsType): boolean {
  54. const {props} = this;
  55. return (
  56. nextProps.selectedCategories.length !== props.selectedCategories.length
  57. );
  58. }
  59. getChipRender = (category: ClubCategoryType, key: string): React.Node => {
  60. const {props} = this;
  61. const onPress = (): void => props.onChipSelect(category.id);
  62. return (
  63. <Chip
  64. selected={isItemInCategoryFilter(props.selectedCategories, [
  65. category.id,
  66. null,
  67. ])}
  68. mode="outlined"
  69. onPress={onPress}
  70. style={{marginRight: 5, marginLeft: 5, marginBottom: 5}}
  71. key={key}>
  72. {category.name}
  73. </Chip>
  74. );
  75. };
  76. getCategoriesRender(): React.Node {
  77. const {props} = this;
  78. const final = [];
  79. props.categories.forEach((cat: ClubCategoryType) => {
  80. final.push(this.getChipRender(cat, cat.id.toString()));
  81. });
  82. return final;
  83. }
  84. render(): React.Node {
  85. return (
  86. <Card style={styles.card}>
  87. <AnimatedAccordion
  88. title={i18n.t('screens.clubs.categories')}
  89. left={(props: ListIconPropsType): React.Node => (
  90. <List.Icon color={props.color} style={props.style} icon="star" />
  91. )}
  92. opened>
  93. <Text style={styles.text}>
  94. {i18n.t('screens.clubs.categoriesFilterMessage')}
  95. </Text>
  96. <View style={styles.chipContainer}>{this.getCategoriesRender()}</View>
  97. </AnimatedAccordion>
  98. </Card>
  99. );
  100. }
  101. }
  102. export default ClubListHeader;