provider.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React from 'react'
  2. // import Expo from 'expo'
  3. import {
  4. // StyleSheet,
  5. // FlatList,
  6. // Image,
  7. // TouchableOpacity,
  8. // Text,
  9. // TextInput,
  10. // View,
  11. AsyncStorage,
  12. WebView } from 'react-native'
  13. import Instagram from '@uppy/instagram'
  14. import Url from './url'
  15. function getQueryParamValueFromUrl (name, url) {
  16. name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]')
  17. var regexS = '[\\?&]' + name + '=([^&#]*)'
  18. var regex = new RegExp(regexS)
  19. var results = regex.exec(url)
  20. return results == null ? null : results[1]
  21. }
  22. export default class UppyRNProvider extends React.Component {
  23. constructor () {
  24. super()
  25. this.state = {
  26. instagram: {
  27. user: 'bla@gmail.com',
  28. items: [
  29. { caption: Date.now(), url: 'http://lorempixel.com/200/200/cats/1' },
  30. { caption: Date.now(), url: 'http://lorempixel.com/200/200/cats/2' },
  31. { caption: Date.now(), url: 'http://lorempixel.com/200/200/cats/3' },
  32. { caption: Date.now(), url: 'http://lorempixel.com/200/200/cats/4' },
  33. { caption: Date.now(), url: 'http://lorempixel.com/200/200/cats/5' },
  34. { caption: Date.now(), url: 'http://lorempixel.com/200/200/' },
  35. { caption: Date.now(), url: 'http://lorempixel.com/200/200/' },
  36. { caption: Date.now(), url: 'http://lorempixel.com/200/200/' },
  37. { caption: Date.now(), url: 'http://lorempixel.com/200/200/' }
  38. ]
  39. }
  40. }
  41. }
  42. componentDidMount () {
  43. this.uppy = this.props.uppy
  44. this.uppy.use(Instagram, {
  45. serverUrl: 'http://localhost:3020',
  46. storage: AsyncStorage
  47. })
  48. this.plugin = this.uppy.getPlugin('Instagram')
  49. this.setState({
  50. authUrl: this.plugin.provider.authUrl()
  51. })
  52. }
  53. // renderGrid (items) {
  54. // return (
  55. // <View style={styles.container}>
  56. // <FlatList
  57. // data={items}
  58. // renderItem={({item}) => (
  59. // <View style={{ flex: 1, flexDirection: 'column', margin: 1 }}>
  60. // <Image style={styles.item} source={{uri: item.url}} />
  61. // </View>
  62. // )}
  63. // keyExtractor={(item, index) => index.toString()}
  64. // numColumns={3}
  65. // />
  66. // </View>
  67. // )
  68. // }
  69. renderInstagram () {
  70. console.log(this.state.authUrl)
  71. return <WebView
  72. source={{ uri: this.state.authUrl }}
  73. style={{ marginTop: 20 }}
  74. onNavigationStateChange={(ev) => {
  75. const url = ev.url
  76. const token = getQueryParamValueFromUrl('uppyAuthToken', url)
  77. console.log(token)
  78. this.plugin.provider.setAuthToken(token)
  79. console.log(this.plugin.provider.list('recent'))
  80. // return this.renderGrid(this.state.instagram.items)
  81. }}
  82. />
  83. }
  84. render () {
  85. if (this.props.id === 'Url') {
  86. return <Url uppy={this.props.uppy} />
  87. }
  88. return this.renderInstagram()
  89. }
  90. }
  91. // const styles = StyleSheet.create({
  92. // container: {
  93. // justifyContent: 'center',
  94. // flex: 1,
  95. // paddingTop: 30
  96. // },
  97. // item: {
  98. // justifyContent: 'center',
  99. // alignItems: 'center',
  100. // height: 100
  101. // }
  102. // })