-
Notifications
You must be signed in to change notification settings - Fork 0
/
Booklist.js
53 lines (49 loc) · 1.46 KB
/
Booklist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Alert, ScrollView} from 'react-native';
import {List, ListItem} from 'react-native-elements';
import { createStackNavigator } from 'react-navigation'
export default class BookList extends Component {
constructor() {
super();
this.state = {
data: [],
text: '',
details: false
};
}
componentDidMount() {
fetch('https://e36548e1.ngrok.io/actions/book')
.then(res => res.json())
.then(data => {
this.setState({ data: data.data })
})
}
codeFixed(id){
fetch(`https://e36548e1.ngrok.io/reading/ebook/${id}`)
.then(res => res.text())
.then(data => {
this.setState({
text: data.split(":")[2].split('"')[1],
details: true
});
})
}
render() {
return (
<ScrollView style ={{flex: 1}}>
{this.state.details ?
<Text>{this.state.text}</Text>
: this.state.data.length > 0 ?
this.state.data.map((l, i) => (
<ListItem
key={i}
title={l.title}
subtitle={l.author}
onPress = {() => this.codeFixed(l._id)}
/>
))
: null}
</ScrollView>
)
}
};