Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import {StyleSheet, View, ListView} from 'react-native';
  3. import {
  4. Container,
  5. Content,
  6. Header,
  7. Left,
  8. Right,
  9. Body,
  10. Title,
  11. Button,
  12. Text,
  13. Icon,
  14. Spinner
  15. } from 'native-base';
  16.  
  17. import CONSTANT from '../../Constant';
  18. import Items from './item';
  19. import GridView from 'react-native-grid-view';
  20. var REWARD_PER_ROW = 3;
  21.  
  22. import Pusher from 'pusher-js/react-native';
  23.  
  24. var pusher = new Pusher('xxxxxxxxxxxx');
  25. var channel = pusher.subscribe('xxxxxx');
  26. var dataSourceObj = [];
  27.  
  28.  
  29.  
  30. export default class Reward extends Component {
  31.  
  32. let something = this;
  33. constructor(props) {
  34. super(props);
  35. this.state = {
  36. dataSource: null,
  37. loaded: false,
  38. };
  39. }
  40.  
  41. componentDidMount() {
  42. this.fetchData();
  43. }
  44.  
  45. fetchData() {
  46. fetch(CONSTANT.API_URL, {
  47. method: 'POST',
  48. headers: {
  49. 'Accept': 'application/json',
  50. 'Content-Type': 'application/json',
  51. },
  52. body: JSON.stringify({
  53. status_active: 0,
  54. user_token: '1',
  55. device_id: 1,
  56. })
  57. })
  58. .then((response) => response.json())
  59. .then((responseJson) => {
  60. this.setState({
  61. dataSource: responseJson.data.stage_bid,
  62. loaded: true,
  63. });
  64. dataSourceObj = responseJson.data.stage_bid;
  65. console.log(responseJson.data.stage_bid);
  66. })
  67. .catch((error) => {
  68. console.error(error);
  69. });
  70. }
  71.  
  72. render() {
  73.  
  74. channel.bind('Production_bid_91',function(response){
  75. console.log(response);
  76.  
  77.  
  78. dataSourceObj[0]['winner_user_name'] = response.winner_user_name;
  79. // console.log(dataSourceObj[0]['winner_user_name']);
  80.  
  81.  
  82. // something.state.dataSource = dataSourceObj;
  83. something.setState({
  84. dataSource: dataSourceObj,
  85. loaded: true,
  86. });
  87. })
  88.  
  89. if (!this.state.loaded) {
  90. return this.renderLoadingView();
  91. }
  92.  
  93. return (
  94. <GridView
  95. items={this.state.dataSource}
  96. itemsPerRow={REWARD_PER_ROW}
  97. renderItem={this.renderReward}
  98. />
  99. )
  100. }
  101.  
  102. renderLoadingView() {
  103. return (
  104. <View style={styles.container}>
  105. <Spinner />
  106. </View>
  107. );
  108. }
  109.  
  110. renderReward(reward) {
  111. return (
  112. <Items
  113. item={reward}
  114. key={reward.item_id}
  115. />
  116. );
  117. }
  118. }
  119.  
  120. const styles = StyleSheet.create({
  121. container: {
  122. flex: 1,
  123. justifyContent: 'center',
  124. alignItems: 'center',
  125. }
  126. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement