// @flow import * as React from 'react'; import {View} from 'react-native'; import DateManager from "../utils/DateManager"; import WebSectionList from "../components/WebSectionList"; import {Card, Text, withTheme} from 'react-native-paper'; import AprilFoolsManager from "../utils/AprilFoolsManager"; const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/menu/menu_data.json"; type Props = { navigation: Object, } /** * Class defining the app's menu screen. * This screen fetches data from etud to render the RU menu */ class SelfMenuScreen extends React.Component { getRenderItem: Function; getRenderSectionHeader: Function; createDataset: Function; colors: Object; constructor(props) { super(props); this.getRenderItem = this.getRenderItem.bind(this); this.getRenderSectionHeader = this.getRenderSectionHeader.bind(this); this.createDataset = this.createDataset.bind(this); this.colors = props.theme.colors; } getKeyExtractor(item: Object) { return item !== undefined ? item['name'] : undefined; } createDataset(fetchedData: Object) { let result = []; // Prevent crash by giving a default value when fetchedData is empty (not yet available) if (Object.keys(fetchedData).length === 0) { result = [ { title: '', data: [], extraData: super.state, keyExtractor: this.getKeyExtractor } ]; } if (AprilFoolsManager.getInstance().isAprilFoolsEnabled() && fetchedData.length > 0) fetchedData[0].meal[0].foodcategory = AprilFoolsManager.getFakeMenuItem(fetchedData[0].meal[0].foodcategory); // fetched data is an array here for (let i = 0; i < fetchedData.length; i++) { result.push( { title: DateManager.getInstance().getTranslatedDate(fetchedData[i].date), data: fetchedData[i].meal[0].foodcategory, extraData: super.state, keyExtractor: this.getKeyExtractor, } ); } return result } getRenderSectionHeader({section}: Object) { return ( ); } getRenderItem({item}: Object) { return ( {item.dishes.map((object) => {object.name !== "" ? {this.formatName(object.name)} : } )} ); } formatName(name: String) { return name.charAt(0) + name.substr(1).toLowerCase(); } render() { const nav = this.props.navigation; return ( ); } } export default withTheme(SelfMenuScreen);