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.

PlanningDisplayScreen.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // @flow
  2. import * as React from 'react';
  3. import {ScrollView, View} from 'react-native';
  4. import {getDateOnlyString, getFormattedEventTime} from '../../utils/Planning';
  5. import {Card, withTheme} from 'react-native-paper';
  6. import DateManager from "../../managers/DateManager";
  7. import ImageModal from 'react-native-image-modal';
  8. import BasicLoadingScreen from "../../components/Screens/BasicLoadingScreen";
  9. import {apiRequest} from "../../utils/WebData";
  10. import ErrorView from "../../components/Screens/ErrorView";
  11. import CustomHTML from "../../components/Overrides/CustomHTML";
  12. import CustomTabBar from "../../components/Tabbar/CustomTabBar";
  13. type Props = {
  14. navigation: Object,
  15. route: Object
  16. };
  17. type State = {
  18. loading: boolean
  19. };
  20. const CLUB_INFO_PATH = "event/info";
  21. /**
  22. * Class defining a planning event information page.
  23. */
  24. class PlanningDisplayScreen extends React.Component<Props, State> {
  25. displayData: Object;
  26. shouldFetchData: boolean;
  27. eventId: number;
  28. errorCode: number;
  29. colors: Object;
  30. constructor(props) {
  31. super(props);
  32. this.colors = props.theme.colors;
  33. if (this.props.route.params.data !== undefined) {
  34. this.displayData = this.props.route.params.data;
  35. this.eventId = this.displayData.id;
  36. this.shouldFetchData = false;
  37. this.errorCode = 0;
  38. this.state = {
  39. loading: false,
  40. };
  41. } else {
  42. this.displayData = null;
  43. this.eventId = this.props.route.params.eventId;
  44. this.shouldFetchData = true;
  45. this.errorCode = 0;
  46. this.state = {
  47. loading: true,
  48. };
  49. this.fetchData();
  50. }
  51. }
  52. fetchData = () => {
  53. this.setState({loading: true});
  54. apiRequest(CLUB_INFO_PATH, 'POST', {id: this.eventId})
  55. .then(this.onFetchSuccess)
  56. .catch(this.onFetchError);
  57. };
  58. onFetchSuccess = (data: Object) => {
  59. this.displayData = data;
  60. this.setState({loading: false});
  61. };
  62. onFetchError = (error: number) => {
  63. this.errorCode = error;
  64. this.setState({loading: false});
  65. };
  66. getContent() {
  67. let subtitle = getFormattedEventTime(
  68. this.displayData["date_begin"], this.displayData["date_end"]);
  69. let dateString = getDateOnlyString(this.displayData["date_begin"]);
  70. if (dateString !== null)
  71. subtitle += ' | ' + DateManager.getInstance().getTranslatedDate(dateString);
  72. return (
  73. <ScrollView style={{paddingLeft: 5, paddingRight: 5}}>
  74. <Card.Title
  75. title={this.displayData.title}
  76. subtitle={subtitle}
  77. />
  78. {this.displayData.logo !== null ?
  79. <View style={{marginLeft: 'auto', marginRight: 'auto'}}>
  80. <ImageModal
  81. resizeMode="contain"
  82. imageBackgroundColor={this.colors.background}
  83. style={{
  84. width: 300,
  85. height: 300,
  86. }}
  87. source={{
  88. uri: this.displayData.logo,
  89. }}
  90. /></View>
  91. : <View/>}
  92. {this.displayData.description !== null ?
  93. <Card.Content style={{paddingBottom: CustomTabBar.TAB_BAR_HEIGHT + 20}}>
  94. <CustomHTML html={this.displayData.description}/>
  95. </Card.Content>
  96. : <View/>}
  97. </ScrollView>
  98. );
  99. }
  100. render() {
  101. if (this.state.loading)
  102. return <BasicLoadingScreen/>;
  103. else if (this.errorCode === 0)
  104. return this.getContent();
  105. else
  106. return <ErrorView {...this.props} errorCode={this.errorCode} onRefresh={this.fetchData}/>;
  107. }
  108. }
  109. export default withTheme(PlanningDisplayScreen);