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'
import LinearGradient from 'react-native-linear-gradient';
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/`+String(I18n.locale).split('-')[0]+`/student`,{
headers: {
'Cache-Control': 'no-cache'
}}
).then((response) => {
return response.text();
}).then((json) => {
const data = JSON.parse(json)
data.sort((a,b)=>a.id-b.id)
this.setState({data: data,isLoading:false});
console.log(this.state.data)
}).catch((error) => console.error(error))
}
render() {
if (this.state.isLoading) {
return
} else {
console.log(this.state.data[this.state.data.length-1].image)
const iconURI = this.state.data[this.state.data.length-1].image !== undefined?`data:image/png;charset=utf-8;base64,${this.state.data[this.state.data.length-1].image}`:'';
const hobbyText = ({this.state.data[this.state.data.length-1].hobbies})
const achievementText = ({this.state.data[this.state.data.length-1].achievements})
const messageText = ({this.state.data[this.state.data.length-1].messages})
return (
{this.state.data[this.state.data.length-1].name}
{I18n.t('student.Grade')} {this.state.data[this.state.data.length-1].grade}
{I18n.t('student.Hobbies')}
{this.state.hobbyExpanded?:}
{this.state.hobbyExpanded?hobbyText:<>>}
{I18n.t('student.Achievements')}
{this.state.achievementExpanded?:}
{this.state.achievementExpanded?achievementText:<>>}
{I18n.t('student.Messages')}
{this.state.messageExpanded?:}
{this.state.messageExpanded?messageText:<>>}
)
}
}
}
export default StudentWeek;