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.

DashboardItem.js 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // @flow
  2. import * as React from 'react';
  3. import {Body, Card, CardItem, H3, Left, Text, Thumbnail} from "native-base";
  4. import CustomMaterialIcon from "./CustomMaterialIcon";
  5. import {View} from "react-native";
  6. import ThemeManager from "../utils/ThemeManager";
  7. import HTML from "react-native-render-html";
  8. import {LinearGradient} from "expo-linear-gradient";
  9. import PlatformTouchable from "react-native-platform-touchable";
  10. import i18n from "i18n-js";
  11. const CARD_BORDER_RADIUS = 10;
  12. type Props = {
  13. isAvailable: boolean,
  14. icon: string,
  15. color: string,
  16. title: string,
  17. subtitle: React.Node,
  18. clickAction: Function,
  19. isSquare: boolean,
  20. isSquareLeft: boolean,
  21. displayEvent: ?Object,
  22. }
  23. export default class DashboardItem extends React.Component<Props> {
  24. static defaultProps = {
  25. isSquare: false,
  26. isSquareLeft: true,
  27. displayEvent: undefined,
  28. };
  29. /**
  30. * Convert the date string given by in the event list json to a date object
  31. * @param dateString
  32. * @return {Date}
  33. */
  34. stringToDate(dateString: ?string): ?Date {
  35. let date = new Date();
  36. if (dateString === undefined || dateString === null)
  37. date = undefined;
  38. else if (dateString.split(' ').length > 1) {
  39. let timeStr = dateString.split(' ')[1];
  40. date.setHours(parseInt(timeStr.split(':')[0]), parseInt(timeStr.split(':')[1]), 0);
  41. } else
  42. date = undefined;
  43. return date;
  44. }
  45. padStr(i: number) {
  46. return (i < 10) ? "0" + i : "" + i;
  47. }
  48. getFormattedEventTime(event: Object): string {
  49. let formattedStr = '';
  50. let startDate = this.stringToDate(event['date_begin']);
  51. let endDate = this.stringToDate(event['date_end']);
  52. if (startDate !== undefined && startDate !== null && endDate !== undefined && endDate !== null)
  53. formattedStr = this.padStr(startDate.getHours()) + ':' + this.padStr(startDate.getMinutes()) +
  54. ' - ' + this.padStr(endDate.getHours()) + ':' + this.padStr(endDate.getMinutes());
  55. else if (startDate !== undefined && startDate !== null)
  56. formattedStr = this.padStr(startDate.getHours()) + ':' + this.padStr(startDate.getMinutes());
  57. return formattedStr
  58. }
  59. getEventPreviewContainer() {
  60. if (this.props.displayEvent !== undefined && this.props.displayEvent !== null) {
  61. return (
  62. <View>
  63. <CardItem style={{
  64. paddingTop: 0,
  65. paddingBottom: 0,
  66. backgroundColor: 'transparent',
  67. }}>
  68. <Left>
  69. {this.props.displayEvent['logo'] !== '' && this.props.displayEvent['logo'] !== null ?
  70. <Thumbnail source={{uri: this.props.displayEvent['logo']}} square/> :
  71. <View/>}
  72. <Body>
  73. <Text>{this.props.displayEvent['title']}</Text>
  74. <Text note>{this.getFormattedEventTime(this.props.displayEvent)}</Text>
  75. </Body>
  76. </Left>
  77. </CardItem>
  78. <CardItem style={{
  79. borderRadius: CARD_BORDER_RADIUS,
  80. backgroundColor: 'transparent',
  81. }}>
  82. <Body style={{
  83. height: this.props.displayEvent['description'].length > 50 ? 70 : 20,
  84. overflow: 'hidden',
  85. }}>
  86. <HTML html={"<div>" + this.props.displayEvent['description'] + "</div>"}
  87. tagsStyles={{
  88. p: {
  89. color: ThemeManager.getCurrentThemeVariables().textColor,
  90. fontSize: ThemeManager.getCurrentThemeVariables().fontSizeBase,
  91. },
  92. div: {color: ThemeManager.getCurrentThemeVariables().textColor},
  93. }}/>
  94. <LinearGradient
  95. colors={['rgba(255,255,255,0)', ThemeManager.getCurrentThemeVariables().cardDefaultBg]}
  96. start={{x: 0, y: 0}}
  97. end={{x: 0, y: 0.6}}
  98. // end={[0, 0.6]}
  99. style={{
  100. position: 'absolute',
  101. width: '100%',
  102. height: 65,
  103. bottom: -5,
  104. }}>
  105. <View style={{
  106. marginLeft: 'auto',
  107. marginTop: 'auto',
  108. flexDirection: 'row'
  109. }}>
  110. <Text style={{
  111. marginTop: 'auto',
  112. marginBottom: 'auto',
  113. padding: 0,
  114. }}>
  115. {i18n.t("homeScreen.dashboard.seeMore")}
  116. </Text>
  117. <CustomMaterialIcon icon={'chevron-right'}/>
  118. </View>
  119. </LinearGradient>
  120. </Body>
  121. </CardItem>
  122. </View>
  123. );
  124. } else
  125. return <View/>
  126. }
  127. getIcon() {
  128. return (
  129. <CustomMaterialIcon
  130. icon={this.props.icon}
  131. color={
  132. this.props.isAvailable ?
  133. this.props.color :
  134. ThemeManager.getCurrentThemeVariables().textDisabledColor
  135. }
  136. fontSize={this.props.isSquare ? 50 : 40}
  137. width={this.props.isSquare ? 50 : 40}/>
  138. );
  139. }
  140. getText() {
  141. return (
  142. <View style={{
  143. width: this.props.isSquare ? '100%' : 'auto',
  144. }}>
  145. <H3 style={{
  146. color: this.props.isAvailable ?
  147. ThemeManager.getCurrentThemeVariables().textColor :
  148. ThemeManager.getCurrentThemeVariables().listNoteColor,
  149. textAlign: this.props.isSquare ? 'center' : 'left',
  150. width: this.props.isSquare ? '100%' : 'auto',
  151. }}>
  152. {this.props.title}
  153. </H3>
  154. <Text style={{
  155. color: this.props.isAvailable ?
  156. ThemeManager.getCurrentThemeVariables().listNoteColor :
  157. ThemeManager.getCurrentThemeVariables().textDisabledColor,
  158. textAlign: this.props.isSquare ? 'center' : 'left',
  159. width: this.props.isSquare ? '100%' : 'auto',
  160. }}>
  161. {this.props.subtitle}
  162. </Text>
  163. </View>
  164. );
  165. }
  166. getContent() {
  167. if (this.props.isSquare) {
  168. return (
  169. <Body>
  170. <View style={{marginLeft: 'auto', marginRight: 'auto'}}>
  171. {this.getIcon()}
  172. </View>
  173. {this.getText()}
  174. </Body>
  175. );
  176. } else {
  177. return (
  178. <Left>
  179. {this.getIcon()}
  180. <Body>
  181. {this.getText()}
  182. </Body>
  183. </Left>
  184. );
  185. }
  186. }
  187. render() {
  188. let marginRight = 10;
  189. if (this.props.isSquare) {
  190. if (this.props.isSquareLeft)
  191. marginRight = '4%';
  192. else
  193. marginRight = 0
  194. }
  195. return (
  196. <Card style={{
  197. flex: 0,
  198. width: this.props.isSquare ? '48%' : 'auto',
  199. marginLeft: this.props.isSquare ? 0 : 10,
  200. marginRight: marginRight,
  201. marginTop: 10,
  202. borderRadius: CARD_BORDER_RADIUS,
  203. backgroundColor: ThemeManager.getCurrentThemeVariables().cardDefaultBg,
  204. overflow: 'hidden',
  205. }}>
  206. <PlatformTouchable
  207. onPress={this.props.clickAction}
  208. style={{
  209. zIndex: 100,
  210. minHeight: this.props.isSquare ? 150 : 'auto',
  211. }}
  212. >
  213. <View>
  214. <CardItem style={{
  215. backgroundColor: 'transparent',
  216. }}>
  217. {this.getContent()}
  218. </CardItem>
  219. {this.getEventPreviewContainer()}
  220. </View>
  221. </PlatformTouchable>
  222. </Card>
  223. );
  224. }
  225. }