2020-08-10 17:41:10 -04:00
|
|
|
import React, { useState } from 'react';
|
2020-08-09 20:16:52 -04:00
|
|
|
import {
|
|
|
|
SafeAreaView,
|
|
|
|
StyleSheet,
|
|
|
|
ScrollView,
|
|
|
|
View,
|
|
|
|
Text,
|
|
|
|
StatusBar,
|
2020-08-10 17:41:10 -04:00
|
|
|
FlatList,
|
|
|
|
TouchableOpacity,
|
2020-08-09 20:16:52 -04:00
|
|
|
} from 'react-native';
|
|
|
|
|
|
|
|
import {
|
|
|
|
Header,
|
|
|
|
LearnMoreLinks,
|
|
|
|
Colors,
|
|
|
|
DebugInstructions,
|
|
|
|
ReloadInstructions,
|
|
|
|
} from 'react-native/Libraries/NewAppScreen';
|
|
|
|
|
2020-08-10 17:41:10 -04:00
|
|
|
import styles from './styles/liststyles'
|
2020-08-13 18:55:10 -04:00
|
|
|
import { url } from './resources/fetchInfo.json'
|
2020-08-10 17:41:10 -04:00
|
|
|
|
|
|
|
const LunchEvent = ({item}) => {
|
|
|
|
const [visible, setVisible] = useState(0)
|
|
|
|
const extra = visible?(<Text>{'\n'}{item.item.text}{'\n\n'}Location: {item.item.loc}</Text>):(<></>);
|
|
|
|
return(
|
|
|
|
<View>
|
2020-08-10 18:09:49 -04:00
|
|
|
<TouchableOpacity style={styles.item} onPress={()=>setVisible(!visible)} activeOpacity={0.8}>
|
2020-08-10 17:41:10 -04:00
|
|
|
<Text style={styles.title}>{item.item.title}</Text>
|
|
|
|
{extra}
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-09 20:16:52 -04:00
|
|
|
class LunchEvents extends React.Component {
|
2020-08-10 17:41:10 -04:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {
|
|
|
|
data: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-08-13 18:55:10 -04:00
|
|
|
fetch(`${url}/api/en/lunchEvents`,{
|
2020-08-10 17:41:10 -04:00
|
|
|
headers: {
|
|
|
|
'Cache-Control': 'no-cache'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.then((response) => {
|
|
|
|
return response.text();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
this.setState({data: JSON.parse(json)});
|
|
|
|
})
|
|
|
|
.catch((error) => console.error(error))
|
|
|
|
}
|
|
|
|
|
2020-08-09 20:16:52 -04:00
|
|
|
render() {
|
|
|
|
return (
|
2020-08-10 17:41:10 -04:00
|
|
|
<View style={styles.container}>
|
|
|
|
<FlatList
|
|
|
|
data={this.state.data}
|
|
|
|
renderItem={item=><LunchEvent item={item}/>}
|
|
|
|
keyExtractor={item=>JSON.stringify(item)}
|
|
|
|
/>
|
2020-08-09 20:16:52 -04:00
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LunchEvents;
|