blazerapp/app/ChallengeWeek.js

73 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

2020-08-14 11:57:45 -04:00
import React from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
2020-10-25 02:57:39 -04:00
Linking,
2021-07-30 00:36:45 -04:00
Animated,
TouchableOpacity,
Image
2020-08-14 11:57:45 -04:00
} from 'react-native';
import {
Header,
LearnMoreLinks,
Colors,
DebugInstructions,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
2020-10-25 02:57:39 -04:00
import styles from './styles/liststyles';
2020-08-14 11:57:45 -04:00
import { url } from './resources/fetchInfo.json'
2021-08-17 21:18:32 -04:00
import I18n from 'i18n-js';
2020-08-14 11:57:45 -04:00
class ChallengeWeek extends React.Component {
constructor(props) {
super(props)
this.state = {
2021-07-30 00:36:45 -04:00
isLoading: true,
2021-09-12 15:08:49 -04:00
flip: true,
data:[]
2020-08-14 11:57:45 -04:00
}
}
componentDidMount() {
2021-09-08 23:50:20 -04:00
fetch(`${url}/api/`+String(I18n.locale).split('-')[0]+`/challenge`,{
2020-08-14 11:57:45 -04:00
headers: {
'Cache-Control': 'no-cache'
}}
).then((response) => {
return response.text();
}).then((json) => {
2021-09-12 15:08:49 -04:00
const data = JSON.parse(json)
data.sort((a,b)=>a.id-b.id)
this.setState({data: data,isLoading:false});
2020-08-14 11:57:45 -04:00
}).catch((error) => console.error(error))
2021-07-30 00:36:45 -04:00
}
2020-08-14 11:57:45 -04:00
render() {
if (this.state.isLoading) {
return <View/>
} else {
2021-09-12 15:08:49 -04:00
if (this.state.data[this.state.data.length-1]==undefined) {
return (
<View style={{alignItems:'center',paddingiorizontal:'10%', height: '100%', backgroundColor: 'white', justifyContent: 'center', padding: '2%'}}>
<Text style={{fontSize: 32, fontWeight: 'bold', marginBottom: '10%', color: 'red', textAlign: 'center'}}>No challenge</Text>
</View>
)
} else {
return (
<View style={{alignItems:'center',paddingiorizontal:'10%', height: '100%', backgroundColor: 'white', justifyContent: 'center', padding: '2%'}}>
<Text style={{fontSize: 32, fontWeight: 'bold', marginBottom: '10%', color: 'red', textAlign: 'center'}}>{this.state.data[this.state.data.length-1].title}</Text>
<Text style={{textAlign:'center', fontSize: 24, marginBottom: '5%', textAlign: 'center', fontWeight: '200'}}>{this.state.data[this.state.data.length-1].text}</Text>
<Text style={{textAlign:'center', fontSize: 20, textDecorationLine: 'underline', textDecorationStyle: "solid", textDecorationColor: "#000"}} onPress={() => Linking.openURL(this.state.data[this.state.data.length-1].link)}>{I18n.t("challenge.link")}</Text>
</View>
)
}
2020-08-14 11:57:45 -04:00
}
}
}
export default ChallengeWeek;