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'
import I18n from './i18n.js'
const Stack = createStackNavigator();
const getCurrentDate=()=>{
var date = new Date().getDate();
var month = new Date().getMonth();
var year = new Date().getFullYear();
return new Date(year, month, date);
}
export const EventInfo = ({route}) => {
const item = route.params;
const itemDate = new Date(parseInt(String(item.event_date).split('-')[0]), parseInt(String(item.event_date).split('-')[1])-1, parseInt(String(item.event_date).split('-')[2]))
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 (
{I18n.t('calendar.info')}
{item.text}
{I18n.t('calendar.location')}
{item.location}
{I18n.t('calendar.date')}
{dayOfWeek}, {month} {date}
{I18n.t('calendar.organizer')}
{item.name}
{item.emails}
)
}
const Event = (props) => {
const item = props.item
const date = item.item.event_date.split('-')
return (
props.navigation.navigate('EventInfo', {data:props.data, title: item.item.title,text:item.item.text,location:item.item.location,event_date:item.item.event_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',
headerBackTitleVisible:false,
headerTintColor: 'black'
})}
/>
({
title:route.params.title,
headerTitleStyle:morestyles.headerTitle,
headerBackground: ()=>background,
//headerLeft: null,
headerTitleAlign: 'center',
headerBackTitleVisible:false,
headerTintColor: 'black'
})}
/>
)
}
function NewCalendarCategory (props) {
return (
{I18n.t('dates.'+props.name)}
}
keyExtractor={item=>JSON.stringify(item)}
/>
)
}
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/`+String(I18n.locale).split('-')[0]+`/events`,{
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)
data.sort((a,b)=>new Date(b.event_date).getTime()-new Date(a.event_date).getTime())
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
if (this.state.data.length >0) {
try {
for (var i =0; i < this.state.data.length; i++) {
const itemDate = new Date(parseInt(String(this.state.data[i].event_date).split('-')[0]), parseInt(String(this.state.data[i].event_date).split('-')[1])-1, parseInt(String(this.state.data[i].event_date).split('-')[2]))
if (itemDate.getTime() == todayDate.getTime()) {
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])
}
}
}
catch {null}
}
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?: <>>}
{futureBoolean?: <>>}
{pastBoolean?: <>>}
{!noAnn?{I18n.t('calendar.noEvents')}:<>>}
)
}
}
export default CalendarEvents;