provider.js 2.9 KB

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