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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // @flow
  2. import * as React from 'react';
  3. import {Avatar, Card, Text, withTheme} from 'react-native-paper';
  4. import {StyleSheet} from "react-native";
  5. import i18n from "i18n-js";
  6. import type {CustomTheme} from "../../managers/ThemeManager";
  7. type Props = {
  8. eventNumber: number;
  9. clickAction: () => void,
  10. theme: CustomTheme,
  11. children?: React.Node
  12. }
  13. /**
  14. * Component used to display a dashboard item containing a preview event
  15. */
  16. class EventDashBoardItem extends React.Component<Props> {
  17. shouldComponentUpdate(nextProps: Props) {
  18. return (nextProps.theme.dark !== this.props.theme.dark)
  19. || (nextProps.eventNumber !== this.props.eventNumber);
  20. }
  21. render() {
  22. const props = this.props;
  23. const colors = props.theme.colors;
  24. const isAvailable = props.eventNumber > 0;
  25. const iconColor = isAvailable ?
  26. colors.planningColor :
  27. colors.textDisabled;
  28. const textColor = isAvailable ?
  29. colors.text :
  30. colors.textDisabled;
  31. let subtitle;
  32. if (isAvailable) {
  33. subtitle =
  34. <Text>
  35. <Text style={{fontWeight: "bold"}}>{props.eventNumber}</Text>
  36. <Text>
  37. {props.eventNumber > 1
  38. ? i18n.t('screens.home.dashboard.todayEventsSubtitlePlural')
  39. : i18n.t('screens.home.dashboard.todayEventsSubtitle')}
  40. </Text>
  41. </Text>;
  42. } else
  43. subtitle = i18n.t('screens.home.dashboard.todayEventsSubtitleNA');
  44. return (
  45. <Card
  46. style={styles.card}
  47. onPress={props.clickAction}>
  48. <Card.Title
  49. title={i18n.t('screens.home.dashboard.todayEventsTitle')}
  50. titleStyle={{color: textColor}}
  51. subtitle={subtitle}
  52. subtitleStyle={{color: textColor}}
  53. left={() =>
  54. <Avatar.Icon
  55. icon={'calendar-range'}
  56. color={iconColor}
  57. size={60}
  58. style={styles.avatar}/>}
  59. />
  60. <Card.Content>
  61. {props.children}
  62. </Card.Content>
  63. </Card>
  64. );
  65. }
  66. }
  67. const styles = StyleSheet.create({
  68. card: {
  69. width: 'auto',
  70. marginLeft: 10,
  71. marginRight: 10,
  72. marginTop: 10,
  73. overflow: 'hidden',
  74. },
  75. avatar: {
  76. backgroundColor: 'transparent'
  77. }
  78. });
  79. export default withTheme(EventDashBoardItem);