blazerapp/app/SSLOps.js

74 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-08-22 20:01:15 -04:00
import React, { useState } from 'react';
2020-08-09 20:56:12 -04:00
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
2020-08-22 20:01:15 -04:00
FlatList,
TouchableOpacity,
2020-08-09 20:56:12 -04:00
} from 'react-native';
import {
Header,
LearnMoreLinks,
Colors,
DebugInstructions,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
2020-08-22 20:01:15 -04:00
import styles from './styles/liststyles';
import { url } from './resources/fetchInfo.json';
const SSLElement = ({item}) => {
const [visible, setVisible] = useState(0)
2020-08-22 20:05:42 -04:00
const extra = visible?(<Text>{'\n'}Details: {item.item.text}{"\n\n"}Where: {item.item.loc}{"\n\n"}Teacher: {item.item.teacher}</Text>):(<></>);
2020-08-22 20:01:15 -04:00
return(
<View>
<TouchableOpacity style={styles.item} onPress={()=>setVisible(!visible)} activeOpacity={0.8}>
2020-08-22 20:05:42 -04:00
<Text style={styles.title}>{item.item.title}</Text>
2020-08-22 20:01:15 -04:00
{extra}
</TouchableOpacity>
</View>
)
}
2020-08-09 20:56:12 -04:00
class SSLOps extends React.Component {
2020-08-22 20:01:15 -04:00
constructor(props) {
super(props)
this.state = {
data: []
}
}
componentDidMount() {
fetch(`${url}/api/en/sslOps`,{
headers: {
'Cache-Control': 'no-cache'
}
}
)
.then((response) => {
return response.text();
})
.then((json) => {
this.setState({data: JSON.parse(json).ops});
})
.catch((error) => console.error(error))
}
2020-08-09 20:56:12 -04:00
render() {
return (
2020-08-22 20:01:15 -04:00
<View style={styles.container}>
<FlatList
data={this.state.data}
renderItem={item=><SSLElement item={item}/>}
keyExtractor={item=>JSON.stringify(item)}
/>
2020-08-09 20:56:12 -04:00
</View>
)
}
}
export default SSLOps;