Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { StyleSheet, View, Linking } from 'react-native';
  3. import { connect } from 'react-redux';
  4. import axios from 'axios';
  5.  
  6. import { API } from '../../API';
  7. import { errorMessage } from '../../actions/Func'
  8.  
  9. import { Header, Fetch, Section } from '../../components';
  10. import Item from './Item';
  11.  
  12. class Shop extends Component {
  13. constructor(props){
  14. super(props)
  15. this.state = {
  16. data: [],
  17. fetching: true,
  18. }
  19. }
  20. componentDidMount(){
  21. this.getData()
  22. }
  23. getData(){
  24. const { auth_token } = this.props.main;
  25. axios({
  26. url: `${API}${'/api/shop'}`,
  27. headers: { 'Authorization': 'Basic ' + auth_token }
  28. })
  29. .then((res) => this.setState({fetching: false, data: res.data}))
  30. .catch((err) => {this.props.errorMessage(err); this.setState({fetching: false})})
  31. }
  32. render(){
  33. const { SHOP } = this.props.language.lang;
  34. const { data, fetching } = this.state;
  35. return(
  36. <View style={styles.container}>
  37. <Header title={SHOP} onPressLeft={() => this.props.onPressHamburger()} />
  38.  
  39. {fetching ? <Fetch type={'flex'} /> :
  40. <View style={styles.content}>
  41. <Section extraData={data} sections={[{title: '', data: data}]}
  42. refreshFunc={() => this.getData()}
  43. itemFunc={(item, index) => {
  44. const ind = item.image.split('').indexOf('1');
  45. const slice_img = item.image.split('').slice(ind).join('');
  46. return(
  47. <Item
  48. key={index}
  49. title={item.header}
  50. image={API + '/download?name=' + slice_img}
  51. price={item.currency + item.price}
  52. onPress={() => Linking.openURL(item.link)}
  53. />
  54. )
  55. }}
  56. />
  57. </View>
  58. }
  59.  
  60. </View>
  61. );
  62. }
  63. }
  64.  
  65.  
  66. const styles = StyleSheet.create({
  67. container: {
  68. flex: 1,
  69. backgroundColor: '#eee'
  70. },
  71. content: {
  72. flex: 1,
  73. }
  74. });
  75.  
  76. const mapStateToProps = (state) => {
  77. return {
  78. main: state.main,
  79. language: state.language,
  80. home: state.home
  81. }
  82. }
  83.  
  84. export default connect(mapStateToProps, { errorMessage })(Shop);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement