Last active
October 21, 2017 19:50
-
-
Save gHashTag/25bb3c30d0e302db514b847d4c797135 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react' | |
| import { | |
| StyleSheet, | |
| Text, | |
| View, | |
| Image | |
| } from 'react-native' | |
| export default class Party extends Component { | |
| constructor(props) { | |
| super(props) | |
| this.state = { | |
| db: [], | |
| loaded: false, | |
| } | |
| } | |
| componentDidMount() { | |
| this.fetchData().done() | |
| } | |
| fetchData() { | |
| try { | |
| const request = new XMLHttpRequest() | |
| console.log('readyState', request.readyState) | |
| request.open( | |
| 'GET', | |
| 'http://p23-calendarws.icloud.com/ca/subscribe/1/iWQpKJehKyMsV5CtZVXDsvAz6bUmAowDyEEU4FL696x3Db8ODUy51IEzEUM-4ycB', | |
| true | |
| ) | |
| request.send(null) | |
| console.log('readyState', request.readyState) | |
| request.onreadystatechange = function() { | |
| console.log('readyState', request.readyState) | |
| if (request.readyState === 4 && request.status === 200) { | |
| var type = request.getResponseHeader('Content-Type') | |
| if (type.indexOf('text') !== 1) { | |
| var lines = request.responseText.split('\n') | |
| //console.log('lines', lines) | |
| var events = {} | |
| var events_i = 0 | |
| for (i = 0; i < lines.length; i++) { | |
| if (lines[i].includes('DTSTART')) { | |
| var date = lines[i].split(':') | |
| events[events_i] = {date: date[1]} | |
| } | |
| else if (lines[i].includes('SUMMARY')) { | |
| var title = lines[i].split(':') | |
| events[events_i]['title'] = title[1] | |
| } | |
| else if (lines[i].startsWith('LOCATION:')) { | |
| var location = lines[i].split(':') | |
| events[events_i]['location'] = location[1] | |
| } | |
| else if (lines[i].includes('END:VEVENT')) { | |
| events_i++ | |
| } | |
| } | |
| console.log(events) | |
| this.setState({ db: events }) | |
| } | |
| } | |
| } | |
| } catch (e) { | |
| throw e | |
| } | |
| } | |
| render() { | |
| return ( | |
| <View style={styles.container}> | |
| <Text>Text</Text> | |
| </View> | |
| ) | |
| } | |
| } | |
| const styles = StyleSheet.create({ | |
| container: { | |
| flex: 1, | |
| padding: 20, | |
| paddingTop:65, | |
| backgroundColor:'white' | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment