Advertisement
enkf

Untitled

Jan 20th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {StyleSheet, View, Text, TextInput, ActivityIndicator,FlatList, Image, ScrollView } from 'react-native';
  3. import AsyncStorage from '@react-native-community/async-storage';
  4. import { Button, CardItem, Card } from 'native-base'
  5. import Axios from 'axios';
  6.  
  7.  
  8.  
  9. class Promotions extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. id:1,
  14. treatment_id: '',
  15. title: '',
  16. desc: '',
  17. image:'',
  18. status:'',
  19. token: '',
  20. data: []
  21. }
  22. }
  23.  
  24.  
  25. async componentDidMount(){
  26. const token = await AsyncStorage.getItem('token')
  27. headers = {'Authorization': 'Bearer ' + token }
  28. this.makeRemoteRequest();
  29. }
  30. makeRemoteRequest = () => {
  31.  
  32. // api profile
  33. const { id } = this.state;
  34. const url = 'http://192.168.56.1/vzuu/public/api/promotions'
  35. // headers = {'Authorization': 'Bearer ' + token }
  36. fetch(url, headers, {method:'GET'})
  37. .then(data=>data.json())
  38. .then(res=> {
  39. console.log(res.results.promotions);
  40. // dari selesai fetching api profile
  41.  
  42. setTimeout(()=>{this.setState({loading:false})},1000)
  43. this.setState({
  44. data: id === 1 ? res.result.promotions : [...this.state.data, ...res.results.promotions],
  45. title: title,
  46. desc: desc,
  47. image: image,
  48.  
  49. })
  50. })
  51. .catch(err=>console.warn({err}))
  52. }
  53.  
  54.  
  55. // componentDidMount(){
  56. // const url = 'https://gist.githubusercontent.com/mahardika404/a48b4a2da23e2da0ecfe15c5979c91e8/raw/d3ce69eed5aab573c49e44acc20f7278a3fbc63a/test.json'
  57. // fetch(url, {method:'GET'})
  58. // .then(data=>data.json())
  59. // .then(res=> {
  60. // // dari selesai fetching api profile
  61. // const {id, name, profile, role} = res
  62. // setTimeout(()=>{this.setState({loading:false})},2000)
  63. // this.setState({id:id, name:name, profile:profile, role:role})
  64. // })
  65. // .catch(err=>console.warn({err}))
  66. // }
  67.  
  68.  
  69.  
  70. render() {
  71.  
  72. return(
  73. <ScrollView>
  74. <View style={{ padding: 14, }}>
  75. <Card>
  76. <FlatList
  77. data={this.state.data}
  78. renderItem={({ item }) => (
  79. <ListItem
  80. roundAvatar
  81. title={`${item.title} `}
  82. subtitle={`${this.state.desc}`}
  83. avatar={{ uri: item.image.thumbnail }}
  84. />
  85. )}
  86. />
  87. </Card>
  88. {/* <Card>
  89. <Image style={styles.img} source={{uri:this.state.profile}} />
  90. <Text
  91. style={styles.text}>
  92. {`${this.state.name}`}
  93. </Text>
  94. <Text style={styles.text}>
  95. {`${this.state.role}`}
  96. </Text>
  97. </Card> */}
  98. </View>
  99. </ScrollView>
  100. )
  101. }
  102. }
  103.  
  104. export default Promotions;
  105. const styles = StyleSheet.create({
  106. container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
  107. img: {width: 370, height: 200},
  108. text: { fontSize: 18, fontWeight: 'bold', color: '#E91E63', alignItems: 'center', justifyContent: 'center' }
  109. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement