2020-08-09 20:56:12 -04:00
|
|
|
import React from 'react';
|
|
|
|
import {
|
|
|
|
SafeAreaView,
|
|
|
|
StyleSheet,
|
|
|
|
ScrollView,
|
|
|
|
View,
|
|
|
|
Text,
|
|
|
|
StatusBar,
|
2020-08-11 12:35:10 -04:00
|
|
|
FlatList,
|
2020-08-09 20:56:12 -04:00
|
|
|
} from 'react-native';
|
|
|
|
|
|
|
|
import {
|
|
|
|
Header,
|
|
|
|
LearnMoreLinks,
|
|
|
|
Colors,
|
|
|
|
DebugInstructions,
|
|
|
|
ReloadInstructions,
|
|
|
|
} from 'react-native/Libraries/NewAppScreen';
|
|
|
|
|
2020-08-11 12:35:10 -04:00
|
|
|
import styles from './styles/liststyles'
|
2020-08-13 18:55:10 -04:00
|
|
|
import { url } from './resources/fetchInfo.json'
|
2020-08-11 12:35:10 -04:00
|
|
|
|
|
|
|
const Announcement = ({item}) => {
|
2020-08-13 18:55:10 -04:00
|
|
|
const date = new Date
|
|
|
|
const dateStr = `${date.getMonth()+1}/${date.getUTCDate()}/${date.getFullYear()}`
|
|
|
|
const dateInfo = dateStr===item.item.date&&item.item.time!==undefined?item.item.time:item.item.date;
|
2020-08-11 12:35:10 -04:00
|
|
|
return (
|
|
|
|
<View style={styles.item}>
|
2020-08-13 18:55:10 -04:00
|
|
|
{dateInfo!==undefined?<Text style={styles.date}>{dateInfo}</Text>:<></>}
|
2020-08-11 12:35:10 -04:00
|
|
|
<Text style={styles.title}>{item.item.message}</Text>
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-09 20:56:12 -04:00
|
|
|
class Announcements extends React.Component {
|
2020-08-11 12:35:10 -04:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {
|
|
|
|
data: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-08-13 18:55:10 -04:00
|
|
|
fetch(`${url}/api/en/announcements`,{
|
2020-08-11 12:35:10 -04:00
|
|
|
headers: {
|
|
|
|
'Cache-Control': 'no-cache'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.then((response) => {
|
|
|
|
return response.text();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
this.setState({data: JSON.parse(json).data});
|
|
|
|
})
|
|
|
|
.catch((error) => console.error(error))
|
|
|
|
}
|
|
|
|
|
2020-08-09 20:56:12 -04:00
|
|
|
render() {
|
|
|
|
return (
|
2020-08-11 12:35:10 -04:00
|
|
|
<View style={styles.container}>
|
|
|
|
<FlatList
|
|
|
|
data={this.state.data}
|
|
|
|
renderItem={item=><Announcement item={item}/>}
|
|
|
|
keyExtractor={item=>JSON.stringify(item)}
|
|
|
|
/>
|
2020-08-09 20:56:12 -04:00
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Announcements;
|