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.tsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. import * as React from 'react';
  20. import {Card, Chip, List, Text} from 'react-native-paper';
  21. import {StyleSheet, View} from 'react-native';
  22. import i18n from 'i18n-js';
  23. import AnimatedAccordion from '../../Animations/AnimatedAccordion';
  24. import {isItemInCategoryFilter} from '../../../utils/Search';
  25. import type {ClubCategoryType} from '../../../screens/Amicale/Clubs/ClubListScreen';
  26. type PropsType = {
  27. categories: Array<ClubCategoryType>;
  28. onChipSelect: (id: number) => void;
  29. selectedCategories: Array<number>;
  30. };
  31. const styles = StyleSheet.create({
  32. card: {
  33. margin: 5,
  34. },
  35. text: {
  36. paddingLeft: 0,
  37. marginTop: 5,
  38. marginBottom: 10,
  39. marginLeft: 'auto',
  40. marginRight: 'auto',
  41. },
  42. chipContainer: {
  43. justifyContent: 'space-around',
  44. flexDirection: 'row',
  45. flexWrap: 'wrap',
  46. paddingLeft: 0,
  47. marginBottom: 5,
  48. },
  49. });
  50. function ClubListHeader(props: PropsType) {
  51. const getChipRender = (category: ClubCategoryType, key: string) => {
  52. const onPress = (): void => props.onChipSelect(category.id);
  53. return (
  54. <Chip
  55. selected={isItemInCategoryFilter(props.selectedCategories, [
  56. category.id,
  57. null,
  58. ])}
  59. mode="outlined"
  60. onPress={onPress}
  61. style={{marginRight: 5, marginLeft: 5, marginBottom: 5}}
  62. key={key}>
  63. {category.name}
  64. </Chip>
  65. );
  66. };
  67. const getCategoriesRender = () => {
  68. const final: Array<React.ReactNode> = [];
  69. props.categories.forEach((cat: ClubCategoryType) => {
  70. final.push(getChipRender(cat, cat.id.toString()));
  71. });
  72. return final;
  73. };
  74. return (
  75. <Card style={styles.card}>
  76. <AnimatedAccordion
  77. title={i18n.t('screens.clubs.categories')}
  78. left={(iconProps) => (
  79. <List.Icon
  80. color={iconProps.color}
  81. style={iconProps.style}
  82. icon="star"
  83. />
  84. )}
  85. opened>
  86. <Text style={styles.text}>
  87. {i18n.t('screens.clubs.categoriesFilterMessage')}
  88. </Text>
  89. <View style={styles.chipContainer}>{getCategoriesRender()}</View>
  90. </AnimatedAccordion>
  91. </Card>
  92. );
  93. }
  94. const areEqual = (prevProps: PropsType, nextProps: PropsType): boolean => {
  95. return (
  96. prevProps.selectedCategories.length === nextProps.selectedCategories.length
  97. );
  98. };
  99. export default React.memo(ClubListHeader, areEqual);