2020-11-06 20:39:39 -05:00
|
|
|
import React, {useState} from 'react';
|
2020-08-09 17:01:25 -04:00
|
|
|
import {
|
|
|
|
SafeAreaView,
|
|
|
|
StyleSheet,
|
|
|
|
ScrollView,
|
|
|
|
View,
|
|
|
|
Text,
|
|
|
|
StatusBar,
|
2020-11-06 20:39:39 -05:00
|
|
|
FlatList,
|
2020-12-07 01:07:07 -05:00
|
|
|
TouchableOpacity,
|
|
|
|
Image,
|
2020-08-09 17:01:25 -04:00
|
|
|
} from 'react-native';
|
|
|
|
|
2020-12-07 01:07:07 -05:00
|
|
|
import {
|
2020-08-09 17:01:25 -04:00
|
|
|
ReloadInstructions,
|
|
|
|
} from 'react-native/Libraries/NewAppScreen';
|
|
|
|
|
2020-12-07 01:07:07 -05:00
|
|
|
import LinearGradient from 'react-native-linear-gradient';
|
|
|
|
|
2020-11-06 20:39:39 -05:00
|
|
|
import styles from './styles/liststyles'
|
|
|
|
import { url } from './resources/fetchInfo.json'
|
|
|
|
|
2020-12-07 01:07:07 -05:00
|
|
|
const getCurrentDate=()=>{
|
|
|
|
var date = new Date().getDate();
|
|
|
|
var month = new Date().getMonth() + 1;
|
|
|
|
var year = new Date().getFullYear();
|
|
|
|
|
|
|
|
return year + '-' + month + '-' + date;
|
|
|
|
}
|
|
|
|
|
2020-11-06 20:39:39 -05:00
|
|
|
const Event = ({item}) => {
|
|
|
|
const [visible, setVisible] = useState(false)
|
2020-12-07 01:07:07 -05:00
|
|
|
const date = item.item.date.split('-')
|
|
|
|
const today = new Date(getCurrentDate())
|
|
|
|
const itemDate = new Date(item.item.date)
|
|
|
|
|
2020-11-06 20:39:39 -05:00
|
|
|
const extra = (
|
|
|
|
<>
|
|
|
|
<Text style={{fontSize:20}}>{item.item.text}</Text>
|
|
|
|
<Text style={{fontSize:20}}>Location: {item.item.location}</Text>
|
2020-12-07 01:07:07 -05:00
|
|
|
<Text style={{fontSize:20}}>Date: {`${date[1]}/${date[2]}/${date[0]}`}</Text>
|
2020-11-06 20:39:39 -05:00
|
|
|
</>
|
2020-12-07 01:07:07 -05:00
|
|
|
)
|
|
|
|
if (itemDate >= today) {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity style={styles.item1} onPress={()=>setVisible(!visible)} activeOpacity={0.8}>
|
|
|
|
<View style = {{display: 'flex', flexDirection: 'row'}}>
|
|
|
|
<Image source ={require('./assets/calendar.png')} style = {{height: 40, width: 40, marginRight: 15}}/>
|
|
|
|
<Text style={styles.title3}>{item.item.title}</Text>
|
|
|
|
</View>
|
|
|
|
{visible?extra:<></>}
|
|
|
|
</TouchableOpacity>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity style={{backgroundColor: '#e3e3e3', padding: 15, borderBottomWidth: 1, borderColor: 'black', width: '100%',}} onPress={()=>setVisible(!visible)} activeOpacity={0.8}>
|
|
|
|
<View style = {{display: 'flex', flexDirection: 'row', alignContent: 'center'}}>
|
|
|
|
<Image source ={require('./assets/calendar.png')} style = {{height: 40, width: 40, marginRight: 15}}/>
|
|
|
|
<Text style={styles.title3}>{item.item.title}</Text>
|
|
|
|
</View>
|
2020-11-06 20:39:39 -05:00
|
|
|
{visible?extra:<></>}
|
|
|
|
</TouchableOpacity>
|
2020-12-07 01:07:07 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-06 20:39:39 -05:00
|
|
|
}
|
|
|
|
|
2020-08-09 17:01:25 -04:00
|
|
|
class Calendar extends React.Component {
|
2020-12-07 01:07:07 -05:00
|
|
|
|
2020-11-06 20:39:39 -05:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {
|
|
|
|
data: []
|
|
|
|
}
|
|
|
|
}
|
2020-12-07 01:07:07 -05:00
|
|
|
|
2020-11-06 20:39:39 -05:00
|
|
|
componentDidMount() {
|
|
|
|
this.getData()
|
|
|
|
this.props.navigation.addListener(
|
|
|
|
'focus',
|
|
|
|
() => {
|
|
|
|
this.getData()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-12-07 01:07:07 -05:00
|
|
|
|
2020-11-06 20:39:39 -05:00
|
|
|
getData() {
|
|
|
|
fetch(`${url}/api/en/events`,{
|
|
|
|
headers: {
|
|
|
|
'Cache-Control': 'no-cache'
|
|
|
|
} })
|
|
|
|
.then((response) => {
|
|
|
|
return response.text();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
const data = JSON.parse(json).data
|
|
|
|
data.sort((a,b)=>new Date(b.date).getTime()-new Date(a.date).getTime())
|
|
|
|
this.setState({data: data});
|
|
|
|
})
|
|
|
|
.catch((error) => console.error(error))
|
|
|
|
}
|
2020-12-07 01:07:07 -05:00
|
|
|
|
2020-08-09 17:01:25 -04:00
|
|
|
render() {
|
|
|
|
return (
|
2020-12-07 01:07:07 -05:00
|
|
|
<View>
|
|
|
|
<View style = {{height: 90, display: 'flex'}}>
|
|
|
|
<LinearGradient
|
|
|
|
colors={['#f99', 'white']}
|
|
|
|
style = {{height: '100%', borderBottomColor:'black', borderBottomWidth:0.5, display: 'flex', justifyContent: 'flex-end', paddingBottom: '2.5%'}}
|
|
|
|
>
|
|
|
|
<Text style = {{fontSize: 24, fontWeight: 'bold', alignSelf: 'center'}}>Calendar</Text>
|
|
|
|
</LinearGradient>
|
|
|
|
|
|
|
|
</View>
|
2020-11-06 20:39:39 -05:00
|
|
|
<FlatList
|
|
|
|
data={this.state.data}
|
|
|
|
renderItem={item=><Event item={item}/>}
|
|
|
|
keyExtractor={item=>JSON.stringify(item)}
|
|
|
|
/>
|
2020-08-09 17:01:25 -04:00
|
|
|
</View>
|
|
|
|
)
|
2020-12-07 01:07:07 -05:00
|
|
|
}
|
2020-08-09 17:01:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Calendar;
|