import React, {useState} from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
FlatList,
TouchableOpacity,
Image,
} from 'react-native';
import {
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
import LinearGradient from 'react-native-linear-gradient';
import styles from './styles/liststyles'
import { url } from './resources/fetchInfo.json'
const getCurrentDate=()=>{
var date = new Date().getDate();
var month = new Date().getMonth() + 1;
var year = new Date().getFullYear();
return year + '-' + month + '-' + date;
}
const Event = ({item}) => {
const [visible, setVisible] = useState(false)
const date = item.item.date.split('-')
const today = new Date(getCurrentDate())
const itemDate = new Date(item.item.date)
const extra = (
<>
{item.item.text}
Location: {item.item.location}
>
)
if (itemDate >= today) {
return (
setVisible(!visible)} activeOpacity={0.8}>
{item.item.title}
{`${date[1]}/${date[2]}/${date[0]}`}
{visible?extra:<>>}
)
}
else {
return (
setVisible(!visible)} activeOpacity={0.8}>
{item.item.title}
{`${date[1]}/${date[2]}/${date[0]}`}
{visible?extra:<>>}
)
}
}
class Calendar extends React.Component {
constructor(props) {
super(props)
this.state = {
data: []
}
}
componentDidMount() {
this.getData()
this.props.navigation.addListener(
'focus',
() => {
this.getData()
}
);
}
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))
}
render() {
return (
Calendar Events
}
keyExtractor={item=>JSON.stringify(item)}
/>
)
}
}
export default Calendar;