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

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