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.

SelfMenuScreen.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // @flow
  2. import * as React from 'react';
  3. import {View} from 'react-native';
  4. import {Text, H2, H3, Card, CardItem} from 'native-base';
  5. import ThemeManager from "../utils/ThemeManager";
  6. import i18n from "i18n-js";
  7. import FetchedDataSectionList from "../components/FetchedDataSectionList";
  8. import LocaleManager from "../utils/LocaleManager";
  9. const DATA_URL = "https://srv-falcon.etud.insa-toulouse.fr/~amicale_app/menu/menu_data.json";
  10. /**
  11. * Class defining the app's menu screen.
  12. * This screen fetches data from etud to render the RU menu
  13. */
  14. export default class SelfMenuScreen extends FetchedDataSectionList {
  15. // Hard code strings as toLocaleDateString does not work on current android JS engine
  16. daysOfWeek = [];
  17. monthsOfYear = [];
  18. constructor() {
  19. super(DATA_URL, 0);
  20. this.daysOfWeek.push(i18n.t("date.daysOfWeek.monday"));
  21. this.daysOfWeek.push(i18n.t("date.daysOfWeek.tuesday"));
  22. this.daysOfWeek.push(i18n.t("date.daysOfWeek.wednesday"));
  23. this.daysOfWeek.push(i18n.t("date.daysOfWeek.thursday"));
  24. this.daysOfWeek.push(i18n.t("date.daysOfWeek.friday"));
  25. this.daysOfWeek.push(i18n.t("date.daysOfWeek.saturday"));
  26. this.daysOfWeek.push(i18n.t("date.daysOfWeek.sunday"));
  27. this.monthsOfYear.push(i18n.t("date.monthsOfYear.january"));
  28. this.monthsOfYear.push(i18n.t("date.monthsOfYear.february"));
  29. this.monthsOfYear.push(i18n.t("date.monthsOfYear.march"));
  30. this.monthsOfYear.push(i18n.t("date.monthsOfYear.april"));
  31. this.monthsOfYear.push(i18n.t("date.monthsOfYear.may"));
  32. this.monthsOfYear.push(i18n.t("date.monthsOfYear.june"));
  33. this.monthsOfYear.push(i18n.t("date.monthsOfYear.july"));
  34. this.monthsOfYear.push(i18n.t("date.monthsOfYear.august"));
  35. this.monthsOfYear.push(i18n.t("date.monthsOfYear.september"));
  36. this.monthsOfYear.push(i18n.t("date.monthsOfYear.october"));
  37. this.monthsOfYear.push(i18n.t("date.monthsOfYear.november"));
  38. this.monthsOfYear.push(i18n.t("date.monthsOfYear.december"));
  39. }
  40. getHeaderTranslation() {
  41. return i18n.t("screens.menuSelf");
  42. }
  43. getUpdateToastTranslations() {
  44. return [i18n.t("homeScreen.listUpdated"), i18n.t("homeScreen.listUpdateFail")];
  45. }
  46. getKeyExtractor(item: Object) {
  47. return item !== undefined ? item.name : undefined;
  48. }
  49. hasBackButton() {
  50. return true;
  51. }
  52. createDataset(fetchedData: Object) {
  53. let result = [];
  54. // Prevent crash by giving a default value when fetchedData is empty (not yet available)
  55. if (Object.keys(fetchedData).length === 0) {
  56. result = [
  57. {
  58. title: '',
  59. data: {},
  60. extraData: super.state,
  61. keyExtractor: this.getKeyExtractor
  62. }
  63. ];
  64. }
  65. // fetched data is an array here
  66. for (let i = 0; i < fetchedData.length; i++) {
  67. result.push(
  68. {
  69. title: this.getFormattedDate(fetchedData[i].date),
  70. data: fetchedData[i].meal[0].foodcategory,
  71. extraData: super.state,
  72. keyExtractor: this.getKeyExtractor
  73. }
  74. );
  75. }
  76. return result
  77. }
  78. getFormattedDate(dateString: string) {
  79. let dateArray = dateString.split('-');
  80. let date = new Date();
  81. date.setFullYear(parseInt(dateArray[0]), parseInt(dateArray[1]) - 1, parseInt(dateArray[2]));
  82. return this.daysOfWeek[date.getDay() - 1] + " " + date.getDate() + " " + this.monthsOfYear[date.getMonth()] + " " + date.getFullYear();
  83. }
  84. getRenderSectionHeader(title: String) {
  85. return (
  86. <Card style={{
  87. marginLeft: 10,
  88. marginRight: 10,
  89. marginTop: 10,
  90. marginBottom: 10,
  91. }}>
  92. <H2 style={{
  93. textAlign: 'center',
  94. marginTop: 10,
  95. marginBottom: 10
  96. }}>{title}</H2>
  97. </Card>
  98. );
  99. }
  100. getRenderItem(item: Object, section: Object, data: Object) {
  101. return (
  102. <Card style={{
  103. flex: 0,
  104. marginLeft: 20,
  105. marginRight: 20
  106. }}>
  107. <CardItem style={{
  108. paddingBottom: 0,
  109. flexDirection: 'column'
  110. }}>
  111. <H3 style={{
  112. marginTop: 10,
  113. marginBottom: 0,
  114. color: ThemeManager.getCurrentThemeVariables().listNoteColor
  115. }}>{item.name}</H3>
  116. <View style={{
  117. width: '80%',
  118. marginLeft: 'auto',
  119. marginRight: 'auto',
  120. borderBottomWidth: 1,
  121. borderBottomColor: ThemeManager.getCurrentThemeVariables().listBorderColor,
  122. marginTop: 10,
  123. marginBottom: 5,
  124. }}/>
  125. </CardItem>
  126. <CardItem style={{
  127. flexDirection: 'column',
  128. paddingTop: 0,
  129. }}>
  130. {item.dishes.map((object, i) =>
  131. <View>
  132. {object.name !== "" ?
  133. <Text style={{
  134. marginTop: 5,
  135. marginBottom: 5
  136. }}>{object.name.toLowerCase()}</Text>
  137. : <View/>}
  138. </View>)}
  139. </CardItem>
  140. </Card>
  141. );
  142. }
  143. }