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.

PreviewEventDashboardItem.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 {StyleSheet, View} from 'react-native';
  22. import i18n from 'i18n-js';
  23. import {Avatar, Button, Card, TouchableRipple} from 'react-native-paper';
  24. import {getTimeOnlyString, isDescriptionEmpty} from '../../utils/Planning';
  25. import CustomHTML from '../Overrides/CustomHTML';
  26. import type {PlanningEventType} from '../../utils/Planning';
  27. type PropsType = {
  28. event?: PlanningEventType | null,
  29. clickAction: () => void,
  30. };
  31. const styles = StyleSheet.create({
  32. card: {
  33. marginBottom: 10,
  34. },
  35. content: {
  36. maxHeight: 150,
  37. overflow: 'hidden',
  38. },
  39. actions: {
  40. marginLeft: 'auto',
  41. marginTop: 'auto',
  42. flexDirection: 'row',
  43. },
  44. avatar: {
  45. backgroundColor: 'transparent',
  46. },
  47. });
  48. /**
  49. * Component used to display an event preview if an event is available
  50. */
  51. // eslint-disable-next-line react/prefer-stateless-function
  52. class PreviewEventDashboardItem extends React.Component<PropsType> {
  53. static defaultProps = {
  54. event: null,
  55. };
  56. render(): React.Node {
  57. const {props} = this;
  58. const {event} = props;
  59. const isEmpty =
  60. event == null ? true : isDescriptionEmpty(event.description);
  61. if (event != null) {
  62. const hasImage = event.logo !== '' && event.logo != null;
  63. const getImage = (): React.Node => (
  64. <Avatar.Image
  65. source={{uri: event.logo}}
  66. size={50}
  67. style={styles.avatar}
  68. />
  69. );
  70. return (
  71. <Card style={styles.card} elevation={3}>
  72. <TouchableRipple style={{flex: 1}} onPress={props.clickAction}>
  73. <View>
  74. {hasImage ? (
  75. <Card.Title
  76. title={event.title}
  77. subtitle={getTimeOnlyString(event.date_begin)}
  78. left={getImage}
  79. />
  80. ) : (
  81. <Card.Title
  82. title={event.title}
  83. subtitle={getTimeOnlyString(event.date_begin)}
  84. />
  85. )}
  86. {!isEmpty ? (
  87. <Card.Content style={styles.content}>
  88. <CustomHTML html={event.description} />
  89. </Card.Content>
  90. ) : null}
  91. <Card.Actions style={styles.actions}>
  92. <Button icon="chevron-right">
  93. {i18n.t('screens.home.dashboard.seeMore')}
  94. </Button>
  95. </Card.Actions>
  96. </View>
  97. </TouchableRipple>
  98. </Card>
  99. );
  100. }
  101. return null;
  102. }
  103. }
  104. export default PreviewEventDashboardItem;