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.

EventDashboardItem.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 {
  22. Avatar,
  23. Card,
  24. Text,
  25. TouchableRipple,
  26. withTheme,
  27. } from 'react-native-paper';
  28. import {StyleSheet, View} from 'react-native';
  29. import i18n from 'i18n-js';
  30. import type {CustomThemeType} from '../../managers/ThemeManager';
  31. import type {CardTitleIconPropsType} from '../../constants/PaperStyles';
  32. type PropsType = {
  33. eventNumber: number,
  34. clickAction: () => void,
  35. theme: CustomThemeType,
  36. children?: React.Node,
  37. };
  38. const styles = StyleSheet.create({
  39. card: {
  40. width: 'auto',
  41. marginLeft: 10,
  42. marginRight: 10,
  43. marginTop: 10,
  44. overflow: 'hidden',
  45. },
  46. avatar: {
  47. backgroundColor: 'transparent',
  48. },
  49. });
  50. /**
  51. * Component used to display a dashboard item containing a preview event
  52. */
  53. class EventDashBoardItem extends React.Component<PropsType> {
  54. static defaultProps = {
  55. children: null,
  56. };
  57. shouldComponentUpdate(nextProps: PropsType): boolean {
  58. const {props} = this;
  59. return (
  60. nextProps.theme.dark !== props.theme.dark ||
  61. nextProps.eventNumber !== props.eventNumber
  62. );
  63. }
  64. render(): React.Node {
  65. const {props} = this;
  66. const {colors} = props.theme;
  67. const isAvailable = props.eventNumber > 0;
  68. const iconColor = isAvailable ? colors.planningColor : colors.textDisabled;
  69. const textColor = isAvailable ? colors.text : colors.textDisabled;
  70. let subtitle;
  71. if (isAvailable) {
  72. subtitle = (
  73. <Text>
  74. <Text style={{fontWeight: 'bold'}}>{props.eventNumber}</Text>
  75. <Text>
  76. {props.eventNumber > 1
  77. ? i18n.t('screens.home.dashboard.todayEventsSubtitlePlural')
  78. : i18n.t('screens.home.dashboard.todayEventsSubtitle')}
  79. </Text>
  80. </Text>
  81. );
  82. } else subtitle = i18n.t('screens.home.dashboard.todayEventsSubtitleNA');
  83. return (
  84. <Card style={styles.card}>
  85. <TouchableRipple style={{flex: 1}} onPress={props.clickAction}>
  86. <View>
  87. <Card.Title
  88. title={i18n.t('screens.home.dashboard.todayEventsTitle')}
  89. titleStyle={{color: textColor}}
  90. subtitle={subtitle}
  91. subtitleStyle={{color: textColor}}
  92. left={(iconProps: CardTitleIconPropsType): React.Node => (
  93. <Avatar.Icon
  94. icon="calendar-range"
  95. color={iconColor}
  96. size={iconProps.size}
  97. style={styles.avatar}
  98. />
  99. )}
  100. />
  101. <Card.Content>{props.children}</Card.Content>
  102. </View>
  103. </TouchableRipple>
  104. </Card>
  105. );
  106. }
  107. }
  108. export default withTheme(EventDashBoardItem);