import React, { useState } from 'react'; import { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, Image, TouchableOpacity } from 'react-native'; import { Header, LearnMoreLinks, Colors, DebugInstructions, ReloadInstructions, } from 'react-native/Libraries/NewAppScreen'; //import I18n from './i18n'; import { url } from './resources/fetchInfo.json' class StudentWeek extends React.Component { constructor(props) { super(props) this.state = { isLoading: true, hobbyExpanded: false, achievementExpanded: false, messageExpanded: false, hobbyArrow:require('./assets/expand.png'), achievementArrow:require('./assets/expand.png'), messageArrow:require('./assets/expand.png') } } clickHobby() { if (!this.state.hobbyExpanded) this.setState({hobbyExpanded:true, hobbyArrow: require('./assets/collapse.png')}); else this.setState({hobbyExpanded: false,hobbyArrow:require('./assets/expand.png')}); } clickAchievements() { if (!this.state.achievementExpanded) this.setState({achievementExpanded:true, achievementArrow: require('./assets/collapse.png')}); else this.setState({achievementExpanded: false, achievementArrow:require('./assets/expand.png')}); } clickMessages() { if (!this.state.messageExpanded) this.setState({messageExpanded:true, messageArrow: require('./assets/collapse.png')}); else this.setState({messageExpanded: false, messageArrow:require('./assets/expand.png')}); } componentDidMount() { fetch(`${url}/api/en/student`,{ headers: { 'Cache-Control': 'no-cache' }} ).then((response) => { return response.text(); }).then((json) => { this.setState({data: JSON.parse(json),isLoading:false}); }).catch((error) => console.error(error)) } render() { if (this.state.isLoading) { return } else { const iconURI = this.state.data.icon !== undefined?`data:image/png;charset=utf-8;base64,${this.state.data.icon}`:''; const hobbyText = ({this.state.data.hobbies}) const achievementText = ({this.state.data.achievements}) const messageText = ({this.state.data.messages}) return ( {this.state.data.name} Grade {this.state.data.year} Hobbies {this.state.hobbyExpanded?hobbyText:<>} Achievements {this.state.achievementExpanded?achievementText:<>} Messages {this.state.messageExpanded?messageText:<>} ) } } } export default StudentWeek;