blazerapp/app/Poll.js

134 lines
3.1 KiB
JavaScript
Raw Permalink Normal View History

2021-01-05 23:08:34 -05:00
/*import React from 'react';
2020-08-09 17:01:25 -04:00
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
2020-12-23 00:23:53 -05:00
Image,
TouchableOpacity,
2020-08-09 17:01:25 -04:00
} from 'react-native';
import {
Header,
LearnMoreLinks,
Colors,
DebugInstructions,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
2020-11-20 02:44:02 -05:00
import {WebView} from 'react-native-webview';
2020-12-23 00:23:53 -05:00
import LinearGradient from 'react-native-linear-gradient';
import { Linking } from 'react-native';
import { url } from './resources/fetchInfo.json'
2021-01-05 23:08:34 -05:00
//import I18n from './i18n';
2020-12-23 00:23:53 -05:00
2020-08-09 17:01:25 -04:00
class Poll extends React.Component {
2020-12-23 00:23:53 -05:00
/*constructor(props) {
super(props)
this.state = {
data: []
}
}
componentDidMount() {
fetch(`${url}/api/en/lunchEvents`,{
headers: {
'Cache-Control': 'no-cache'
}
}
)
.then((response) => {
return response.text();
})
.then((json) => {
this.setState({data: JSON.parse(json)});
})
.catch((error) => console.error(error))
}*/
2021-01-05 23:08:34 -05:00
/*
2020-08-09 17:01:25 -04:00
render() {
return (
2020-12-23 00:23:53 -05:00
<View style = {{backgroundColor: 'white'}}>
<View style={{backgroundColor: 'white', height: '100%', display: 'flex', alignItems: 'center'}}>
<TouchableOpacity onPress={()=>Linking.openURL("https://google.com")}>
<Image source={require('./assets/polls.png')} style={{marginTop: 50, height: 300, width: 300, tintColor: 'red'}}/>
</TouchableOpacity>
2021-01-05 23:08:34 -05:00
<Text style ={{fontSize: 20, marginTop: 30}}>Take A Poll!</Text>
2020-12-23 00:23:53 -05:00
</View>
</View>
2020-08-09 17:01:25 -04:00
)
}
}
2021-01-05 23:08:34 -05:00
export default Poll;*/
import React from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
} from 'react-native';
import {
Header,
LearnMoreLinks,
Colors,
DebugInstructions,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
2021-09-12 15:08:49 -04:00
import { url } from './resources/fetchInfo.json'
2021-01-05 23:08:34 -05:00
import {WebView} from 'react-native-webview';
2021-09-12 15:08:49 -04:00
import I18n from 'i18n-js';
2021-01-05 23:08:34 -05:00
class Poll extends React.Component {
2021-09-12 15:08:49 -04:00
constructor(props) {
super(props)
this.state = {
data:[]
}
}
componentDidMount() {
fetch(`${url}/api/`+String(I18n.locale).split('-')[0]+`/polls`,{
headers: {
'Cache-Control': 'no-cache'
}}
).then((response) => {
return response.text();
}).then((json) => {
const data = JSON.parse(json)
data.sort((a,b)=>a.id-b.id)
this.setState({data: data});
}).catch((error) => console.error(error))
}
2021-01-05 23:08:34 -05:00
render() {
2021-09-12 15:08:49 -04:00
if (this.state.isLoading) {
return <View/>
} else {
if (this.state.data.length==0) {
return (
<View style={{alignItems:'center',paddingiorizontal:'10%', height: '100%', backgroundColor: 'white', justifyContent: 'center', padding: '2%'}}>
<Text style={{fontSize: 32, fontWeight: 'bold', marginBottom: '10%', color: 'red', textAlign: 'center'}}>No Poll</Text>
</View>
)
} else {
return (
<WebView
source = {{uri: this.state.data[this.state.data.length-1].url}}
javaScriptEnabled={true}
domStorageEnabled={true}
startInLoadingState={true}
style={{marginTop: 0}}
cacheEnabled={true}
/>
)
}
}
2021-01-05 23:08:34 -05:00
}
}
2020-08-09 17:01:25 -04:00
export default Poll;