blazerapp/app/Calendar.js

241 lines
9.1 KiB
JavaScript
Raw Permalink Normal View History

2021-08-01 22:11:39 -04:00
import React, {useState} from 'react';
2020-08-09 17:01:25 -04:00
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
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';
2021-08-01 22:11:39 -04:00
import Ionicons from 'react-native-vector-icons/Ionicons';
import Icon from 'react-native-vector-icons/AntDesign'
2020-12-07 01:07:07 -05:00
import LinearGradient from 'react-native-linear-gradient';
2021-08-01 22:11:39 -04:00
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import styles from './styles/liststyles'
import { url } from './resources/fetchInfo.json'
2021-08-01 22:11:39 -04:00
import morestyles from './styles/morestyles'
2021-08-17 21:18:32 -04:00
import I18n from './i18n.js'
2021-08-01 22:11:39 -04:00
const Stack = createStackNavigator();
2020-12-07 01:07:07 -05:00
const getCurrentDate=()=>{
var date = new Date().getDate();
2021-09-08 23:50:20 -04:00
var month = new Date().getMonth();
2020-12-07 01:07:07 -05:00
var year = new Date().getFullYear();
2021-08-01 22:11:39 -04:00
return new Date(year, month, date);
2020-12-24 01:35:25 -05:00
}
2021-08-01 22:11:39 -04:00
export const EventInfo = ({route}) => {
const item = route.params;
2021-09-12 21:28:01 -04:00
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]))
2021-08-01 22:11:39 -04:00
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
const months = ['January','February','March','April','May','June','July','August','September','October','November','December',]
2021-09-12 21:28:01 -04:00
const dayOfWeek = days[itemDate.getDay()]
2021-08-01 22:11:39 -04:00
const month = months[itemDate.getMonth()]
2021-09-12 21:28:01 -04:00
const date = itemDate.getDate()
2021-08-01 22:11:39 -04:00
return (
2021-08-17 21:18:32 -04:00
<ScrollView style = {{backgroundColor: 'white', flex:1, padding: '5%', paddingRight: '10%'}}>
<View style={{marginBottom: '7%'}}>
<Text style={[styles.title, {fontWeight: 'bold', marginBottom: '2%'}]}>{I18n.t('calendar.info')}</Text>
<Text style={[styles.title, {fontWeight: '200'}]}>{item.text}</Text>
</View>
<View style={{}}>
2021-08-01 22:11:39 -04:00
<View style={{display: 'flex', flexDirection: 'row', marginBottom: '5%'}}>
<Ionicons name='location-outline' size={28} color={'#323232'}style={{marginRight: 15, alignSelf: 'center'}}/>
2021-08-17 21:18:32 -04:00
<View style={{display: 'flex', marginLeft: -15, paddingHorizontal: '5%'}}>
<Text style={{fontSize: 16}}>{I18n.t('calendar.location')}</Text>
2021-08-01 22:11:39 -04:00
<Text style={[styles.title, {fontSize: 16, fontWeight: '200'}]}>{item.location}</Text>
</View>
2020-12-24 02:34:47 -05:00
</View>
2021-08-01 22:11:39 -04:00
<View style={{display: 'flex', flexDirection: 'row', marginBottom: '5%'}}>
<Ionicons name='time-outline' size={28} color={'#323232'}style={{marginRight: 15, alignSelf: 'center'}}/>
2021-08-17 21:18:32 -04:00
<View style={{display: 'flex', marginLeft: -15, paddingHorizontal: '5%'}}>
<Text style={{fontSize: 16}}>{I18n.t('calendar.date')}</Text>
2021-08-01 22:11:39 -04:00
<Text style={[styles.title, {fontSize: 16, fontWeight: '200'}]}>{dayOfWeek}, {month} {date}</Text>
</View>
2020-12-07 01:07:48 -05:00
</View>
2021-08-01 22:11:39 -04:00
<View style={{display: 'flex', flexDirection: 'row'}}>
<Ionicons name='person-circle-outline' size={28} color={'#323232'}style={{marginRight: 15, alignSelf: 'center'}}/>
2021-08-17 21:18:32 -04:00
<View style={{display: 'flex', marginLeft: -15, paddingHorizontal: '5%'}}>
<Text style={{fontSize: 16}}>{I18n.t('calendar.organizer')}</Text>
2021-08-01 22:11:39 -04:00
<Text style={[styles.title, {fontSize: 16, fontWeight: '200'}]}>{item.name}</Text>
<Text style={[styles.title, {fontSize: 16, fontWeight: '200', textDecorationLine: 'underline'}]}>{item.emails}</Text>
</View>
2020-12-07 01:07:48 -05:00
</View>
2020-12-07 01:07:07 -05:00
</View>
2021-08-17 21:18:32 -04:00
</ScrollView>
2021-08-01 22:11:39 -04:00
)
}
2021-08-01 22:11:39 -04:00
const Event = (props) => {
const item = props.item
2021-09-08 23:50:20 -04:00
const date = item.item.event_date.split('-')
2021-08-01 22:11:39 -04:00
return (
<View>
2021-09-11 17:48:17 -04:00
<TouchableOpacity style={[styles.listItem, {padding: '2%'}]} onPress={()=>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}>
2021-08-01 22:11:39 -04:00
<View style = {[styles.container2, {justifyContent: 'space-between'}]}>
<View style={{display: 'flex', flexDirection: 'row'}}>
<Ionicons name='calendar' size={32} color={'#323232'} style={{marginRight: 15}}/>
<View style = {{display: 'flex', alignContent: 'center', width: '80%'}}>
<Text style={styles.title}>{item.item.title}</Text>
<View style={{paddingBottom: '2%'}}><Text style = {{fontSize: 12, fontWeight: '200'}}>{`${date[1]}/${date[2]}/${date[0]}`}</Text></View>
</View>
</View>
<Image source = {require('./assets/forward.png')} style={{tintColor: '#b2b2b2'}}/>
2021-01-05 23:08:34 -05:00
</View>
2021-08-01 22:11:39 -04:00
</TouchableOpacity>
</View>
)
2021-01-05 23:08:34 -05:00
}
2021-08-01 22:11:39 -04:00
const background = (<LinearGradient
colors={['#f99', 'white']}
style = {{flex:1,borderBottomColor:'black',borderBottomWidth:0.5}}
/>)
function CalendarEvents () {
return (
<NavigationContainer independent={true}>
<Stack.Navigator>
<Stack.Screen
2021-08-17 21:18:32 -04:00
name = {I18n.t('calendar.calendar')}
2021-08-01 22:11:39 -04:00
component = {Calendar}
options={({
headerShown: true,
headerTitleStyle:morestyles.headerTitle,
headerBackground: ()=>background,
2021-08-17 21:18:32 -04:00
//headerLeft: null,
headerTitleAlign: 'center',
headerBackTitleVisible:false,
headerTintColor: 'black'
2021-08-01 22:11:39 -04:00
})}
/>
<Stack.Screen
name = "EventInfo"
component = {EventInfo}
options={({route})=>({
title:route.params.title,
headerTitleStyle:morestyles.headerTitle,
headerBackground: ()=>background,
2021-08-17 21:18:32 -04:00
//headerLeft: null,
headerTitleAlign: 'center',
headerBackTitleVisible:false,
headerTintColor: 'black'
2021-08-01 22:11:39 -04:00
})}
/>
</Stack.Navigator>
</NavigationContainer>
)
2021-01-05 23:08:34 -05:00
}
2021-08-17 21:18:32 -04:00
function NewCalendarCategory (props) {
return (
<View>
<LinearGradient start={{x: 0.25, y: .5}} end={{x: 1, y: 1}} colors={['#FF8484', '#FF1111']} style={{backgroundColor: 'red', width: '20%', padding: '2%', borderTopRightRadius: 20, borderBottomRightRadius: 20, marginVertical: '2%'}}>
<Text style={[styles.title, {color: 'white', fontWeight: 'bold'}]}>{I18n.t('dates.'+props.name)}</Text>
</LinearGradient>
<FlatList
data={props.list}
renderItem={item=><Event item={item} name={props.itemname} navigation={props.navigation}/>}
keyExtractor={item=>JSON.stringify(item)}
/>
</View>
)
}
2021-01-05 23:08:34 -05:00
class Calendar extends React.Component {
constructor(props) {
super(props)
this.state = {
data: []
}
}
componentDidMount() {
this.getData()
this.props.navigation.addListener(
'focus',
() => {
this.getData()
}
);
}
getData() {
2021-09-12 15:08:49 -04:00
fetch(`${url}/api/`+String(I18n.locale).split('-')[0]+`/events`,{
2021-01-05 23:08:34 -05:00
headers: {
'Cache-Control': 'no-cache'
} })
.then((response) => {
return response.text();
2021-09-08 23:50:20 -04:00
2021-01-05 23:08:34 -05:00
})
.then((json) => {
2021-09-08 23:50:20 -04:00
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())
2021-01-05 23:08:34 -05:00
this.setState({data: data});
})
.catch((error) => console.error(error))
}
render() {
2021-08-01 22:11:39 -04:00
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
2021-09-08 23:50:20 -04:00
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])
}
2021-09-12 21:28:01 -04:00
else if (itemDate >= weekPastDate && itemDate < todayDate) {
//else if (itemDate < todayDate) {
2021-09-08 23:50:20 -04:00
past.push(this.state.data[i])
}
}
2021-08-01 22:11:39 -04:00
}
2021-09-08 23:50:20 -04:00
catch {null}
2021-08-01 22:11:39 -04:00
}
2021-09-08 23:50:20 -04:00
2021-08-01 22:11:39 -04:00
if (today.length === 0) todayBoolean = false
if (past.length === 0) pastBoolean = false
if (future.length === 0) futureBoolean = false
var noAnn = (todayBoolean||pastBoolean||futureBoolean)
2021-01-05 23:08:34 -05:00
return (
2021-08-01 22:11:39 -04:00
<ScrollView style={{flex:1, backgroundColor: 'white'}}>
2021-08-17 21:18:32 -04:00
{todayBoolean?<NewCalendarCategory name = 'today' list = {today} navigation={this.props.navigation} />: <></>}
{futureBoolean?<NewCalendarCategory name = 'future' list = {future} navigation={this.props.navigation} />: <></>}
2021-09-08 23:50:20 -04:00
{pastBoolean?<NewCalendarCategory name = 'past' list = {past} navigation={this.props.navigation} />: <></>}
2021-08-17 21:18:32 -04:00
{!noAnn?<Text style={{textAlign: 'center', fontSize: 20, paddingTop: '2%'}}>{I18n.t('calendar.noEvents')}</Text>:<></>}
2021-08-01 22:11:39 -04:00
</ScrollView>
2020-08-09 17:01:25 -04:00
)
2020-12-07 01:07:07 -05:00
}
2020-08-09 17:01:25 -04:00
}
2021-08-01 22:11:39 -04:00
export default CalendarEvents;