blazerapp/app/Announcements.js

68 lines
1.1 KiB
JavaScript
Raw Normal View History

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'
const Announcement = ({item}) => {
return (
<View style={styles.item}>
<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() {
fetch('https://6dc2642ae9b3.ngrok.io/api/en/announcements',{
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;