blazerapp/app/Home.js

602 lines
31 KiB
JavaScript
Raw Permalink Normal View History

2020-10-25 02:57:39 -04:00
import React, { useState } from 'react';
2020-08-09 17:01:25 -04:00
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
2020-10-25 02:57:39 -04:00
Modal,
TouchableHighlight,
Image,
2020-12-23 00:23:53 -05:00
FlatList,
2021-08-17 21:18:32 -04:00
Dimensions,
2020-12-24 01:35:25 -05:00
Linking,
2021-08-17 21:18:32 -04:00
ImageBackground
2020-08-09 17:01:25 -04:00
} from 'react-native';
2021-06-26 17:19:29 -04:00
import { useHeaderHeight } from '@react-navigation/stack';
2020-08-09 17:01:25 -04:00
import {
Header,
LearnMoreLinks,
Colors,
DebugInstructions,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
2020-10-25 02:57:39 -04:00
import styles from './styles/morestyles'
2020-12-23 00:23:53 -05:00
import liststyles from './styles/liststyles'
2020-12-21 22:34:09 -05:00
import { url } from './resources/fetchInfo.json'
import LinearGradient from 'react-native-linear-gradient';
2020-12-23 00:23:53 -05:00
import StudentWeek from './StudentWeek';
2021-08-17 21:18:32 -04:00
import LunchEvents from './LunchEvents'
2020-12-23 00:23:53 -05:00
import { TouchableOpacity } from 'react-native-gesture-handler';
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
2020-12-24 01:35:25 -05:00
import Announcements from './Announcements'
2021-08-17 21:18:32 -04:00
import I18n from './i18n.js'
import AsyncStorage from '@react-native-async-storage/async-storage'
2020-12-23 00:23:53 -05:00
2021-08-17 21:18:32 -04:00
const STORAGE_KEY = "teacherAnnouncements"
const Stack = createStackNavigator()
const windowWidth = Dimensions.get('window').width;
const windowHeight = Dimensions.get('window').height;
2020-12-23 00:23:53 -05:00
2021-09-08 23:50:20 -04:00
console.log(String(I18n.locale).split('-')[0])
2020-12-23 00:23:53 -05:00
const getCurrentDate=()=>{
2021-08-17 21:18:32 -04:00
var date = new Date().getDate();
var month = new Date().getMonth();
var year = new Date().getFullYear();
2020-12-24 01:35:25 -05:00
2021-08-17 21:18:32 -04:00
return new Date(year, month, date);
2020-12-24 01:35:25 -05:00
}
const Announcement = ({item}) => {
2021-08-17 21:18:32 -04:00
const todayDate = getCurrentDate()
const itemDate = new Date(item.item.date)
2021-09-12 15:08:49 -04:00
var time_array = item.item.time.split(':')
if (time_array[0]>12) {
var time = String(parseInt(time_array[0])-12) + ':' + String(time_array[1]) + ' PM'
}
else {
var time = String(time_array[0])+':'+String(time_array[1]) + ' AM'
}
const dateInfo = todayDate.getTime()===itemDate.getTime()&&item.item.time!==undefined?item.item.time:(item.item.date+", " + time)
2020-12-24 01:35:25 -05:00
return (
2021-08-17 21:18:32 -04:00
<View style={{borderWidth: 1, borderColor: '#323232', padding: '2%', marginHorizontal: '2%', marginBottom: '2%', borderRadius: 12}}>
<View style = {{display: 'flex', flexDirection: 'column', justifyContent: 'space-between'}}>
<View style = {{width: '100%'}}>
<Text style={liststyles.title}>{item.item.message}</Text>
2020-12-24 01:35:25 -05:00
</View>
2021-09-12 15:08:49 -04:00
{dateInfo!==undefined?<Text style={{fontSize: 12, fontWeight: '200'}}>Posted {dateInfo}</Text>:<></>}
2020-12-24 01:35:25 -05:00
</View>
</View>
)
}
2021-08-17 21:18:32 -04:00
function NewTeacherList(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={[liststyles.title, {color: 'white', fontWeight: 'bold'}]}>{I18n.t('dates.'+props.name)}</Text>
</LinearGradient>
<FlatList
data={props.list}
renderItem={item=><Announcement item={item}/>}
keyExtractor={item=>JSON.stringify(item)}
/>
</View>
)
}
2020-12-24 01:35:25 -05:00
export const TeacherList = ({route}) => {
2021-08-17 21:18:32 -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
for (var i = 0; i < route.params.data.length; i++) {
2021-09-12 15:08:49 -04:00
const itemDate = new Date(parseInt(String(route.params.data[i].date).split('-')[0]), parseInt(String(route.params.data[i].date).split('-')[1])-1, parseInt(String(route.params.data[i].date).split('-')[2]))
2021-08-17 21:18:32 -04:00
if (itemDate.getTime() == todayDate.getTime()) {
today.push(route.params.data[i])
}
else if (itemDate.getTime() > todayDate.getTime() && itemDate.getTime() <= weekFutureDate.getTime()) {
future.push(route.params.data[i])
}
2021-09-12 21:28:01 -04:00
else if (itemDate >= weekPastDate && itemDate < todayDate) {
//else if (itemDate.getTime() < todayDate.getTime()) {
2021-08-17 21:18:32 -04:00
past.push(route.params.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)
2020-12-24 01:35:25 -05:00
return (
2021-09-12 15:08:49 -04:00
<ScrollView style={{flex:1, backgroundColor: 'white'}}>
2021-08-17 21:18:32 -04:00
{todayBoolean?<NewTeacherList name = 'today' list = {today} />:<></>}
{pastBoolean?<NewTeacherList name = 'past' list = {past} />:<></>}
{futureBoolean?<NewTeacherList name = 'future' list = {future} />:<></>}
2021-09-12 15:08:49 -04:00
{!noAnn?<Text style={{textAlign: 'center', fontSize: 20, paddingTop: '2%'}}>{I18n.t('announcements.noAnnouncements')}</Text>:<></>}
2021-08-17 21:18:32 -04:00
</ScrollView>
2020-12-24 01:35:25 -05:00
)
2020-12-23 00:23:53 -05:00
}
2021-08-17 21:18:32 -04:00
function NewElement(props) {
var name = props.name
2020-12-24 01:35:25 -05:00
return (
2021-08-17 21:18:32 -04:00
<View style={{}}>
<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={[liststyles.title, {color: 'white', fontWeight: 'bold'}]}>{I18n.t('dates.'+props.name)}</Text>
</LinearGradient>
<View style={{display:'flex', flexDirection: 'row', paddingHorizontal: '5%'}}>
<FlatList
data={props.list}
renderItem={item=><New item={item} navigation={props.navigation}/>}
keyExtractor={item=>JSON.stringify(item)}
horizontal
/>
2020-12-24 01:35:25 -05:00
</View>
</View>
)
}
2021-08-17 21:18:32 -04:00
export const whatsNew = ({route}) => {
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 < route.params.data.length; i++) {
2021-09-12 21:28:01 -04:00
const itemDate = new Date(parseInt(String(route.params.data[i].new_date).split('-')[0]), parseInt(String(route.params.data[i].new_date).split('-')[1])-1, parseInt(String(route.params.data[i].new_date).split('-')[2]))
2021-08-17 21:18:32 -04:00
if (itemDate.getTime() == todayDate.getTime()) {
today.push(route.params.data[i])
}
else if (itemDate.getTime() > todayDate.getTime() && itemDate.getTime() <= weekFutureDate.getTime()) {
future.push(route.params.data[i])
}
2021-09-12 21:28:01 -04:00
else if (itemDate >= weekPastDate && itemDate < todayDate) {
//else if (itemDate.getTime() < todayDate.getTime()) {
2021-08-17 21:18:32 -04:00
past.push(route.params.data[i])
}
}
if (today.length === 0) todayBoolean = false
if (past.length === 0) pastBoolean = false
if (future.length === 0) futureBoolean = false
2020-12-24 01:35:25 -05:00
2021-08-17 21:18:32 -04:00
const item = route.params
return (
<ScrollView style={{display:'flex', backgroundColor: 'white', height: '100%'}}>
{todayBoolean?<NewElement name = 'today' navigation = {route.params.navigation} list = {today}/>:<></>}
{pastBoolean?<NewElement name = 'past' navigation = {route.params.navigation} list = {past}/>:<></>}
{futureBoolean?<NewElement name = 'future' navigation = {route.params.navigation} list = {future}/>:<></>}
</ScrollView>
)
2020-12-24 01:35:25 -05:00
}
2021-08-17 21:18:32 -04:00
export const NewItem = ({route}) => {
const item = route.params.data
return (
<ScrollView style={{height: '100%', backgroundColor: 'white'}}>
<View style={{backgroundColor: '#e3e3e3'}}>
2021-09-12 21:28:01 -04:00
<Image source={{uri: item.image}} style={{width: windowWidth, height: windowHeight*.6, alignSelf: 'center'}}/>
2021-08-17 21:18:32 -04:00
</View>
<View style={{backgroundColor: 'white', marginTop: '-5%', padding: '5%', borderTopLeftRadius: 20, borderTopRightRadius: 20}}>
2021-09-12 21:28:01 -04:00
<Text style={{fontSize: 14, fontWeight: '200', textAlign: 'center'}}>{item.new_date}</Text>
2021-08-17 21:18:32 -04:00
<Text style={{fontSize: 20, textAlign: 'center', paddingBottom: '2%', fontWeight: 'bold'}}>{item.name}</Text>
2021-09-12 21:28:01 -04:00
<Text style={{fontSize: 14}}>{item.text}</Text>
2021-08-17 21:18:32 -04:00
</View>
</ScrollView>
)
2020-12-24 01:35:25 -05:00
}
const AnnouncementToday = ({item}) => {
2021-09-12 15:08:49 -04:00
const teacher = item.item.teacher
var time_array = item.item.time.split(':')
if (time_array[0]>12) {
var time = String(parseInt(time_array[0])-12) + ':' + String(time_array[1]) + ' PM'
}
else {
var time = String(time_array[0])+':'+String(time_array[1]) + ' AM'
}
2020-12-24 01:35:25 -05:00
2021-08-17 21:18:32 -04:00
return (
<View style = {{display: 'flex', flexDirection: 'row', alignItems: 'center', padding: '2%', paddingVertical: '2.5%', justifyContent: 'space-between', borderBottomWidth: 1, borderColor: "#b2b2b2"}}>
<View style = {{width: '72%'}}>
<Text style={{fontSize: 18}}>{item.item.message}</Text>
2021-09-12 15:08:49 -04:00
<Text style={{fontSize: 12, fontWeight: '200', paddingTop: '1%'}}>{time}</Text>
2020-12-23 00:23:53 -05:00
</View>
2021-08-17 21:18:32 -04:00
<View style = {{width: '25%', display: 'flex', flexDirection: 'row', justifyContent: 'flex-end'}}>
<Text style={{fontSize: 14, alignSelf: 'center', fontWeight: '200'}}>{teacher}</Text>
</View>
</View>
)
2020-12-24 01:35:25 -05:00
}
2021-08-17 21:18:32 -04:00
const New = (props) => {
const item = props.item
const iconURI = item.item.icon !== undefined?`data:image/png;charset=utf-8;base64,${item.item.icon}`:''
const textLength = item.item.name.length
var text = item.item.name
if (textLength >=17) {
text = text.substring(0, 14)+"..."
2020-12-24 01:35:25 -05:00
}
2021-08-17 21:18:32 -04:00
return (
<View style={{paddingRight: '2%'}}>
<TouchableOpacity onPress={()=>props.navigation.navigate('NewItem', {data:props.item.item})}>
2021-09-12 21:28:01 -04:00
<ImageBackground style = {{width: windowWidth*.4, height: windowWidth*.55, backgroundColor:'#e3e3e3', borderRadius: 16, alignItems: 'baseline'}}source = {{uri: item.item.image}}>
2021-08-17 21:18:32 -04:00
<View style={{padding: '5%', flex: 1, justifyContent: 'flex-end', width: windowWidth*.4, height: windowWidth*.2, shadowColor: '#323232', shadowOffset: {width: 0, height: 0}, shadowOpacity: 0.5}}>
2021-09-12 21:28:01 -04:00
<Text style={{fontSize: 12, color: 'white', fontWeight: '500'}}>{item.item.new_date}</Text>
2021-08-17 21:18:32 -04:00
<Text style={{fontSize: 16, color: 'white', fontWeight: 'bold'}}>{text}</Text>
</View>
</ImageBackground>
</TouchableOpacity>
2020-12-24 01:35:25 -05:00
</View>
2021-08-17 21:18:32 -04:00
)
2020-12-23 00:23:53 -05:00
}
2020-10-25 02:57:39 -04:00
function Home1() {
const [modalVisible, setModalVisible] = useState(false);
2020-10-25 02:57:39 -04:00
return (
2021-08-17 21:18:32 -04:00
<Modal animationType="slide" transparent={true} visible={modalVisible}>
<View style={styles.modal}>
<View style={{display: 'flex', flexDirection:'row', justifyContent: 'flex-end'}}>
<TouchableHighlight onPress={() => {setModalVisible(false);}}>
<Image source = {require('./assets/exit.png')} style = {{height: 40, width: 40}}/>
</TouchableHighlight>
</View>
<Image source = {require('./assets/blair_logo.png')} style = {{alignSelf: 'center', marginTop: '5%', height: 325, width: 325}}/>
<Text style={styles.modalText}>{url}</Text>
2020-10-25 02:57:39 -04:00
</View>
2021-08-17 21:18:32 -04:00
</Modal>
2020-12-24 01:35:25 -05:00
)
}
2021-08-17 21:18:32 -04:00
2020-12-24 01:35:25 -05:00
const background = (<LinearGradient
colors={['#f99', 'white']}
2021-08-17 21:18:32 -04:00
style = {{flex:1,borderBottomColor:'black',borderBottomWidth:0}}
2020-12-24 01:35:25 -05:00
/>)
function HomeStack() {
return (
<NavigationContainer independent={true}>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={Home}
options={{
title:'Blair',
headerTitleStyle:styles.headerTitle,
headerBackground: ()=>background
}}
/>
<Stack.Screen
name="new"
component={whatsNew}
options={({route})=> ({
2021-08-17 21:18:32 -04:00
title:I18n.t('home.whatsNew'),
2020-12-24 01:35:25 -05:00
headerTitleStyle:styles.headerTitle,
2021-08-17 21:18:32 -04:00
headerBackground: ()=>background,
//headerLeft:null,
headerBackTitleVisible:false,
headerTintColor: 'black',
headerTitleAlign: 'center'
2020-12-24 01:35:25 -05:00
})}
/>
<Stack.Screen
name="Announcements"
component={Announcements}
options={({route})=> ({
2021-08-17 21:18:32 -04:00
title:I18n.t('home.Announcements'),
2020-12-24 01:35:25 -05:00
headerTitleStyle:styles.headerTitle,
2021-08-17 21:18:32 -04:00
headerBackground: ()=>background,
//headerLeft:null,
headerBackTitleVisible:false,
headerTintColor: 'black',
headerTitleAlign: 'center'
2020-12-24 01:35:25 -05:00
})}
/>
<Stack.Screen
name="TeacherList"
component={TeacherList}
options={({route})=>({
2021-08-17 21:18:32 -04:00
headerTitleStyle:[styles.headerTitle],
2020-12-24 01:35:25 -05:00
title:route.params.name,
headerRight:()=>(<></>),
2021-08-17 21:18:32 -04:00
headerBackground: ()=>background,
//headerLeft:null,
headerBackTitleVisible:false,
headerTintColor: 'black',
headerTitleAlign: 'center'
2020-12-24 01:35:25 -05:00
})}
/>
2021-06-26 17:19:29 -04:00
<Stack.Screen
2021-08-17 21:18:32 -04:00
name="LunchEvents"
component={LunchEvents}
options={{
title:I18n.t('home.lunch'),
headerTitleStyle:styles.headerTitle,
//headerLeft:null,
headerBackground: ()=>background,
headerTitleAlign: 'center',
headerBackTitleVisible:false,
headerTintColor: 'black'
}}
/>
<Stack.Screen
name="StudentWeek"
component={StudentWeek}
2021-06-26 17:19:29 -04:00
options={{
2021-08-17 21:18:32 -04:00
title:I18n.t('home.SOTW'),
2021-06-26 17:19:29 -04:00
headerTitleStyle:styles.headerTitle,
2021-08-17 21:18:32 -04:00
headerBackground: ()=>background,
//headerLeft:null,
headerBackTitleVisible:false,
headerTintColor: 'black',
headerTitleAlign: 'center'
2021-06-26 17:19:29 -04:00
}}
/>
2021-08-17 21:18:32 -04:00
<Stack.Screen
name = "NewItem"
component = {NewItem}
options={({route})=> ({
headerTitleStyle:[styles.headerTitle],
title:I18n.t('home.news'),
headerRight:()=>(<></>),
headerBackground: ()=>background,
//headerLeft: null,
headerBackTitleVisible:false,
headerTintColor: 'black',
headerTitleAlign: 'center'
})}
/>
2020-12-24 01:35:25 -05:00
</Stack.Navigator>
</NavigationContainer>
)
}
2020-10-25 02:57:39 -04:00
2020-12-24 01:35:25 -05:00
function HomeScreen (props) {
2021-09-12 17:29:07 -04:00
var showStudent = true
if (props.studentData.length==0) {showStudent = false}
2021-09-12 15:08:49 -04:00
const iconURI = null
//const iconURI = props.studentData.image !== undefined?`data:image/png;charset=utf-8;base64,${props.studentData.image}`:`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAMZWlDQ1BJQ0MgUHJvZmlsZQAASImVlwdck0cbwO8dmSSsQARkhL1EkRlARggrgoBMQVRCEkgYMSYEETe1VMG6RRRHRasiFq1WQOpAxDqL4raOxoFKpRaruFD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Ksqq56v1Sw9OzXY7+u+XpwWe6yzuV+yzevIK6Qrri2MnTlrlVGq8pWPVg9YXXTGtaayjUv105be6bap3rLOuo65TpVTVxNy3qH9SvWv98g3nC1Nrx270bLjUs2vt4k3HRpc9jmxi1WW6q2vPtG8s2NrdFbm+qc6qq3EbeVbHu0PW37qW/Z39bvsNhRtePDTulO1a6kXR31/vX1uy13L29AG5QNPXuy9lz8LuK7lkaPxq17mXur9oF9yn2/fZ/9/bX9sfvbD7APNP7g+MPGg4yDlU1I06ymvmZxs6olo6Xr0PhD7a1BrQd/HP3jzsO2h2uPmB5ZfpR6dNHRwWNlx/rbZG29x/OOP2if1n7rxKQTVzomdnSejD15+qeon06c4pw6djr49OEzgWcOnWWfbT7nd67pvO/5gz/7/nyw06+z6YL/hZaLARdbu8Z1Hb0Ueun45YjLP13hXTl3Nf5q17XUazeuZ11X3RDeeHKz8ObzX0p+Gbi14DbhduUdwzvVdy3v1v3q+utelZ/qyL2Ie+fvJ9+/9UDw4OlDx
2021-06-26 17:19:29 -04:00
global.headerHeight = useHeaderHeight();
2021-08-17 21:18:32 -04:00
const todayDate = getCurrentDate()
var todayAnn = []
var todayNew = []
var todayAnnBoolean = true
var todayNewBoolean = true
var showLunch = false
for (var i = 0; i < props.annData.length; i++) {
2021-09-12 21:28:01 -04:00
const itemDate = new Date(parseInt(String(props.annData[i].date).split('-')[0]), parseInt(String(props.annData[i].date).split('-')[1])-1, parseInt(String(props.annData[i].date).split('-')[2]))
if (itemDate.getTime() == todayDate.getTime()) todayAnn.push(props.annData[i])
2021-08-17 21:18:32 -04:00
}
2020-12-24 01:35:25 -05:00
2021-08-17 21:18:32 -04:00
for (var i = 0; i < props.data.length; i++) {
2021-09-12 21:28:01 -04:00
const itemDate = new Date(parseInt(String(props.data[i].new_date).split('-')[0]), parseInt(String(props.data[i].new_date).split('-')[1])-1, parseInt(String(props.data[i].new_date).split('-')[2]))
if (itemDate.getTime() == todayDate.getTime()) todayNew.push(props.data[i])
2021-08-17 21:18:32 -04:00
}
2021-09-12 21:28:01 -04:00
2021-08-17 21:18:32 -04:00
if (todayAnn.length === 0) todayAnnBoolean = false
if (todayNew.length ===0) todayNewBoolean = false
todayAnn = todayAnn.slice(0, 4)
2020-12-24 01:35:25 -05:00
2021-08-17 21:18:32 -04:00
var currentTime = new Date();
var time = currentTime.toLocaleTimeString().replace(/([\d]+:[\d]{2})(:[\d]{2})(.*)/, "$1$3").split(' ')
var dayOfWeek = currentTime.getDay()
var hourTime = parseInt(time[0].split(':')[0])
if (dayOfWeek!=0 && dayOfWeek!=6 && ((hourTime>=10 && time[1]=='AM') || (hourTime ==12 && parseInt(time[0].split(':')[1])<=30 && time[1]=='PM'))) {
showLunch = true
}
2021-08-23 21:46:29 -04:00
if (time[1]!='PM' && time[1]!='AM' && dayOfWeek!=0 && dayOfWeek!=6 && hourTime>=10 && (hourTime <=12 && parseInt(time[0].split(':')[1])<=30)) {
2021-08-17 21:18:32 -04:00
showLunch = true
}
return (
<ScrollView style={{paddingHorizontal:'5%', backgroundColor: 'white', height: '100%'}}>
{showLunch?
<View style={{display: 'flex', flexDirection: 'row', paddingTop: '2%'}}>
<Text style={{textAlign: 'center', alignSelf: 'center', fontSize: 16, fontWeight: '200'}}>{I18n.t('home.shortcut')} {'\t'}</Text>
<TouchableOpacity onPress={()=>props.navigation.navigate(LunchEvents)}>
<View style={{padding: '5%', borderRadius: 16, borderWidth: 1, borderColor: 'red'}}>
<Text style={{fontWeight: '200', color: 'red', textAlign: 'center'}}>{I18n.t('home.seeLunch')}</Text>
</View>
2020-12-24 01:35:25 -05:00
</TouchableOpacity>
</View>
2021-08-17 21:18:32 -04:00
:<></>}
<View style={{paddingTop: '2%'}}>
<View style={{display: 'flex', flexDirection:'row', justifyContent: 'space-between', alignItems: 'center', paddingBottom: '5%'}}>
<Text style={liststyles.homeTitle}>{I18n.t('home.whatsNew')}</Text>
<TouchableOpacity style={{display: 'flex', flexDirection: 'row'}}onPress={()=>props.navigation.navigate('new', {data:props.data, navigation: props.navigation})}>
<LinearGradient start={{x: 0, y: 0.25}} end={{x: .5, y: 1}} colors={['red', '#FF7373']} style={{borderRadius: 24, alignSelf: 'center'}}><Image source = {require('./assets/forward.png')} style={{tintColor: 'white'}}/></LinearGradient>
2021-06-26 17:19:29 -04:00
</TouchableOpacity>
</View>
2021-08-17 21:18:32 -04:00
<View style={{backgroundColor: 'white', display: 'flex', flexDirection: 'row'}}>
{!todayNewBoolean?<Text style={{fontWeight: '200', fontSize: 16, paddingTop: '2%'}}>{I18n.t('home.noNews')}</Text>:<FlatList
data={todayNew}
renderItem={item=><New item={item} navigation={props.navigation}/>}
2021-06-26 17:19:29 -04:00
keyExtractor={item=>JSON.stringify(item)}
horizontal
2021-08-17 21:18:32 -04:00
/>}
2021-06-26 17:19:29 -04:00
</View>
</View>
2021-08-17 21:18:32 -04:00
<View style={{marginTop: '5%'}}>
<View style={{display: 'flex', flexDirection:'row', justifyContent: 'space-between', alignItems: 'center', paddingBottom: '5%'}}>
<Text style={liststyles.homeTitle}>{I18n.t('home.Announcements')}</Text>
<TouchableOpacity style={{}}onPress={()=>props.navigation.navigate(Announcements)}>
<LinearGradient start={{x: 0, y: 0.25}} end={{x: .5, y: 1}} colors={['red', '#FF7373']} style={{borderRadius: 24, alignSelf: 'center'}}><Image source = {require('./assets/forward.png')} style={{tintColor: 'white'}}/></LinearGradient>
2021-06-26 17:19:29 -04:00
</TouchableOpacity>
</View>
2021-08-17 21:18:32 -04:00
{!todayAnnBoolean?<Text style={{fontWeight: '200', fontSize: 16, paddingTop: '2%'}}>{I18n.t('home.noAnnouncements')}</Text>:<FlatList
data={todayAnn}
2021-06-26 17:19:29 -04:00
renderItem={item=><AnnouncementToday item={item}/>}
keyExtractor={item=>JSON.stringify(item)}
2021-08-17 21:18:32 -04:00
/>}
2021-06-26 17:19:29 -04:00
</View>
2021-08-17 21:18:32 -04:00
2021-09-12 17:29:07 -04:00
{showStudent?<View style={{marginTop: '5%', marginBottom: '10%'}}>
2021-08-17 21:18:32 -04:00
<Text style={[liststyles.homeTitle, {paddingBottom: '5%'}]}>{I18n.t('home.SOTW')}</Text>
<View style={{display: 'flex', flexDirection: 'row'}}>
<View style={{backgroundColor: 'white', width: windowWidth*.30, height: windowWidth*.30, shadowColor: 'red', shadowOffset: {width: 0, height: 2}, shadowOpacity: 0.5, shadowRadius: 7, borderRadius: (windowWidth*.30)/2}}>
2021-09-12 21:28:01 -04:00
<Image source = {{uri: props.studentData[props.studentData.length-1].image}} style = {{height:'100%', width: '100%', borderTopRightRadius: 8, borderTopLeftRadius:8}}/>
2021-08-17 21:18:32 -04:00
</View>
<View style ={{width: windowWidth*.60, display: 'flex', paddingLeft: '5%', paddingHorizontal: '2%', alignItems: 'center', justifyContent: 'space-around'}}>
2021-09-12 15:08:49 -04:00
<Text style={{fontSize: 18, textAlign: 'center'}}>{props.studentData[props.studentData.length-1].name}, <Text style={{fontWeight: '200', textAlign: 'center'}}>Grade {props.studentData[props.studentData.length-1].grade}</Text></Text>
2021-08-17 21:18:32 -04:00
<TouchableOpacity onPress={()=>props.navigation.navigate(StudentWeek)}>
<View style={{padding: '5%', borderRadius: 16, borderWidth: 1, borderColor: 'red'}}>
2021-09-12 15:08:49 -04:00
<Text style={{fontWeight: '200', color: 'red', textAlign: 'center'}}>{I18n.t('home.moreOn')} {props.studentData[props.studentData.length-1].name}</Text>
2021-08-17 21:18:32 -04:00
</View>
</TouchableOpacity>
</View>
2020-12-24 01:35:25 -05:00
</View>
2021-09-12 17:29:07 -04:00
</View>: <View></View>}
2020-12-24 01:35:25 -05:00
</ScrollView>
2020-10-25 02:57:39 -04:00
)
2021-08-17 21:18:32 -04:00
}
2020-12-23 00:23:53 -05:00
2020-08-09 17:01:25 -04:00
class Home extends React.Component {
2020-10-25 02:57:39 -04:00
constructor(props) {
super(props)
this.state = {
2021-09-12 15:08:49 -04:00
studentData:[],
2020-12-24 01:35:25 -05:00
annData:[],
2020-12-23 00:23:53 -05:00
data:[],
2021-08-17 21:18:32 -04:00
lunchData:[],
2020-12-24 01:35:25 -05:00
teacherNames: [],
favoriteNames: [],
2020-12-21 22:34:09 -05:00
isLoading:true
2020-10-25 02:57:39 -04:00
}
}
2020-12-23 00:23:53 -05:00
addFavorite = (name) => {
const favoriteNames = this.state.favoriteNames.slice().map(({name})=>name)
const index = favoriteNames.indexOf(name)
if (index < 0) {
favoriteNames.push(name)
}
else {
favoriteNames.splice(index,1)
}
favoriteNames.sort()
this.setState({favoriteNames:favoriteNames.map(name=>({name:name}))})
AsyncStorage.setItem(STORAGE_KEY,JSON.stringify(favoriteNames)).catch(console.log).done()
}
2021-09-12 15:08:49 -04:00
2020-12-23 00:23:53 -05:00
componentDidMount() {
2021-09-08 23:50:20 -04:00
fetch(`${url}/api/`+String(I18n.locale).split('-')[0]+`/student`,{
2020-12-23 00:23:53 -05:00
headers: {
'Cache-Control': 'no-cache'
}}
).then((response) => {
2021-09-12 15:08:49 -04:00
return response.text();
2020-12-23 00:23:53 -05:00
}).then((json) => {
2021-09-12 15:08:49 -04:00
const data = JSON.parse(json)
data.sort((a,b)=>a.id-b.id)
this.setState({studentData: data,isLoading:false});
}).catch((error) => console.error(error))
2021-08-17 21:18:32 -04:00
2021-09-12 15:08:49 -04:00
fetch(`${url}/api/`+String(I18n.locale).split('-')[0]+`/lunch_events`,{
2021-08-17 21:18:32 -04:00
headers: {
'Cache-Control': 'no-cache'
}}
).then((response) => {
return response.text();
}).then((json) => {
2021-09-12 15:08:49 -04:00
const data = JSON.parse(json)
data.sort((a,b)=>a.id-b.id)
this.setState({lunchData: data});
2021-08-17 21:18:32 -04:00
}).catch((error) => console.error(error))
2020-12-23 00:23:53 -05:00
this.getData()
this.props.navigation.addListener(
'focus',
() => {
this.getData()
}
);
this.getData1()
AsyncStorage.getItem(STORAGE_KEY)
.then(value=>value==null?[]:JSON.parse(value).map(x=>({name:x})))
.then(names=>this.setState({favoriteNames:names}))
.catch(console.log)
.done()
}
2020-12-24 01:35:25 -05:00
getData() {
2021-09-08 23:50:20 -04:00
fetch(`${url}/api/`+String(I18n.locale).split('-')[0]+`/new`,{
2020-12-24 01:35:25 -05:00
headers: {
'Cache-Control': 'no-cache'
} })
.then((response) => {
return response.text();
})
.then((json) => {
2021-09-12 21:28:01 -04:00
const data = JSON.parse(json)
2021-09-12 15:08:49 -04:00
data.sort((a,b)=>a.id-b.id)
2020-12-24 01:35:25 -05:00
data.sort((a,b)=>new Date(b.date).getTime()-new Date(a.date).getTime())
this.setState({data: data});
2021-09-12 21:28:01 -04:00
console.log(this.state.data)
2020-12-24 01:35:25 -05:00
})
.catch((error) => console.error(error))
}
2020-12-23 00:23:53 -05:00
getData1() {
2021-09-08 23:50:20 -04:00
fetch(`${url}/api/`+String(I18n.locale).split('-')[0]+`/announcements`,{
2020-12-23 00:23:53 -05:00
headers: {
'Cache-Control': 'no-cache'
2021-08-17 21:18:32 -04:00
}})
2020-12-23 00:23:53 -05:00
.then((response) => {
return response.text()
})
.then((txt) => {
2021-09-12 15:08:49 -04:00
const data = JSON.parse(txt);
data.sort((a,b)=>a.id-b.id)
2020-12-23 00:23:53 -05:00
const teacherNames = [...new Set(data.filter(x=>x.teacher!=null&&x.teacher.trim()!=='').map(x=>x.teacher))];
teacherNames.sort()
2020-12-24 01:35:25 -05:00
this.setState({annData: data, teacherNames: teacherNames.map(x=>({name:x})),isLoading:false});
2021-09-12 15:08:49 -04:00
console.log(annData)
2021-08-17 21:18:32 -04:00
}).catch((error) => console.error(error))
2020-12-23 00:23:53 -05:00
}
2021-09-12 15:08:49 -04:00
2020-10-25 02:57:39 -04:00
2020-08-09 17:01:25 -04:00
render() {
2021-09-12 15:08:49 -04:00
if (this.state.isLoading) {
return<View/>
} else {
2020-12-23 00:23:53 -05:00
return (
2020-10-25 02:57:39 -04:00
<View>
<Home1></Home1>
2021-09-12 15:08:49 -04:00
<HomeScreen navigation={this.props.navigation} annData={this.state.annData} studentData={this.state.studentData} data={this.state.data}></HomeScreen>
2020-10-25 02:57:39 -04:00
</View>
2021-09-12 15:08:49 -04:00
)}
2020-08-09 17:01:25 -04:00
}
}
2020-12-24 01:35:25 -05:00
export default HomeStack;