-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
96 lines (85 loc) · 2.3 KB
/
App.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import React, { Component } from 'react';
import {
StyleSheet,
Text,
ScrollView,
View,
Button,
Linking,
ToastAndroid,
} from 'react-native';
import KeepAwake from 'react-native-keep-awake';
import { WebViewPlayer } from './src/components/WebViewPlayer';
import { api } from './src/api';
const siteUrl = 'https://litealloy.com/';
const defaultWorkoutData = { name: '', instructions: '', youtubeId: '' }; // qHuEd3KVAwk
export default class App extends Component {
static workoutState(data) {
const responseData = data || defaultWorkoutData;
return {
id: responseData.id,
name: responseData.name,
instructions: responseData.instructions,
youtubeId: responseData.youtube_id, // api has keys in snake case
};
}
state = { workout: defaultWorkoutData, btnDisabled: false };
componentDidMount() {
this.loadWorkout();
}
loadWorkout = async() => {
this.setState({ btnDisabled: true });
const data = await api('workouts/random');
this.setState({
workout: this.constructor.workoutState(data),
btnDisabled: false,
});
}
openLink = () => {
if (!this.state.workout.id) { return null; }
const url = [siteUrl, 'workouts', this.state.workout.id].join('/');
return Linking.openURL(url).catch(err => ToastAndroid.show(`An error has occurred - ${err}`, ToastAndroid.SHORT));
}
render() {
return (
<ScrollView>
<KeepAwake />
<View style={styles.content}>
<Text style={styles.header} onPress={this.openLink}>
{this.state.workout.name}
</Text>
<Text style={styles.instructions}>{this.state.workout.instructions}</Text>
<WebViewPlayer youtubeId={this.state.workout.youtubeId} />
<Button
title="another workout"
color="#6698FF"
onPress={this.loadWorkout}
disabled={this.state.btnDisabled}
>
Sign In
</Button>
</View>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
a: {
fontWeight: '300',
color: '#6698FF',
},
content: {
paddingBottom: 10,
},
header: {
fontSize: 22,
marginTop: 10,
paddingHorizontal: 20,
textDecorationLine: 'underline',
color: '#6698FF',
},
instructions: {
padding: 10,
margin: 10,
},
});