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 Ionicons from 'react-native-vector-icons/Ionicons';
import Icon from 'react-native-vector-icons/AntDesign'
import LinearGradient from 'react-native-linear-gradient';
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import styles from './styles/liststyles'
import { url } from './resources/fetchInfo.json'
import morestyles from './styles/morestyles'
const Stack = createStackNavigator();
const getCurrentDate=()=>{
var date = new Date().getDate();
var month = new Date().getMonth() + 1;
var year = new Date().getFullYear();
return new Date(year, month, date);
}
export const EventInfo = ({route}) => {
const item = route.params;
const itemDate = new Date(item.date)
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
const months = ['January','February','March','April','May','June','July','August','September','October','November','December',]
const dayOfWeek = days[itemDate.getDay()]
const month = months[itemDate.getMonth()]
const date = itemDate.getDate()
return (
Info
{item.text}
Location
{item.location}
Date
{dayOfWeek}, {month} {date}
Organizer
{item.name}
{item.emails}
)
}
const Event = (props) => {
const item = props.item
const date = item.item.date.split('-')
return (
props.navigation.navigate('EventInfo', {data:props.data,name:props.name, title: item.item.title,text:item.item.text,location:item.item.location,date:item.item.date, name:item.item.name, emails: item.item.emails})} activeOpacity={0.8}>
{item.item.title}
{`${date[1]}/${date[2]}/${date[0]}`}
)
}
const background = ()
function CalendarEvents () {
return (
background,
headerleft: null,
headerTitleAlign: 'center'
})}
/>
({
title:route.params.title,
headerTitleStyle:morestyles.headerTitle,
headerBackground: ()=>background,
headerleft: null,
headerTitleAlign: 'center'
})}
/>
)
}
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())
console.log(data);
this.setState({data: data});
})
.catch((error) => console.error(error))
}
render() {
const todayDate = getCurrentDate()
const weekPastDate = new Date();
var pastDate = weekPastDate.getDate() - 7;
weekPastDate.setDate(pastDate);
const weekFutureDate = new Date();
var futureDate = weekFutureDate.getDate() + 7;
weekFutureDate.setDate(futureDate);
const today = []
const past = []
const future = []
var todayBoolean = true
var pastBoolean = true
var futureBoolean = true
for (var i =0; i < this.state.data.length; i++) {
const itemDate = new Date(this.state.data[i].date)
if (itemDate == todayDate) {
today.push(this.state.data[i])
}
else if (itemDate > todayDate && itemDate <= weekFutureDate) {
future.push(this.state.data[i])
}
//else if (itemDate >= weekPastDate && itemDate < todayDate) {
else if (itemDate < todayDate) {
past.push(this.state.data[i])
}
}
if (today.length === 0) todayBoolean = false
if (past.length === 0) pastBoolean = false
if (future.length === 0) futureBoolean = false
var noAnn = (todayBoolean||pastBoolean||futureBoolean)
return (
{todayBoolean?
Today
}
keyExtractor={item=>JSON.stringify(item)}
/>
: <>>}
{pastBoolean?
Past
}
keyExtractor={item=>JSON.stringify(item)}
/>
:<>>}
{futureBoolean?
Future
}
keyExtractor={item=>JSON.stringify(item)}
/>
:<>>}
{!noAnn?No Events:<>>}
)
}
}
export default CalendarEvents;