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

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