import React from 'react'; import { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, Linking, Animated, TouchableOpacity, Image } from 'react-native'; import { Header, LearnMoreLinks, Colors, DebugInstructions, ReloadInstructions, } from 'react-native/Libraries/NewAppScreen'; import styles from './styles/liststyles'; import { url } from './resources/fetchInfo.json' import I18n from 'i18n-js'; class ChallengeWeek extends React.Component { constructor(props) { super(props) this.state = { isLoading: true, flip: true, data:[] } } componentDidMount() { fetch(`${url}/api/`+String(I18n.locale).split('-')[0]+`/challenge`,{ 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}); }).catch((error) => console.error(error)) } render() { if (this.state.isLoading) { return } else { if (this.state.data[this.state.data.length-1]==undefined) { return ( No challenge ) } else { return ( {this.state.data[this.state.data.length-1].title} {this.state.data[this.state.data.length-1].text} Linking.openURL(this.state.data[this.state.data.length-1].link)}>{I18n.t("challenge.link")} ) } } } } export default ChallengeWeek;