-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomeView.js
More file actions
201 lines (188 loc) · 6.44 KB
/
homeView.js
File metadata and controls
201 lines (188 loc) · 6.44 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import React, {useState, useRef, useEffect, useCallback} from 'react';
import { TouchableWithoutFeedback, Modal, TouchableOpacity,
Alert, StyleSheet, Text, View, TextInput, ScrollView,
KeyboardAvoidingView, StatusBar, FlatList, RefreshControl } from 'react-native';
import { WebView } from 'react-native-webview';
import Constants from 'expo-constants';
import { showMessage, hideMessage } from "react-native-flash-message";
import { Auth } from 'aws-amplify';
import { createStackNavigator } from 'react-navigation-stack';
import { createBottomTabNavigator, createMaterialTopTabNavigator } from 'react-navigation-tabs';
import {color, styles, global_debug, itemFontSize, itemHeight, my_i18n} from './styleConst';
import { Button, Icon, Image, SearchBar } from 'react-native-elements';
import ModalDropdown from 'react-native-modal-dropdown';
import { withNavigationFocus } from 'react-navigation';
import { IconText } from './utilsComp';
import { ExploreLambda } from './homeView2'
import {process_upload_json} from './utils'
export const ExploreView = createMaterialTopTabNavigator(
{
[my_i18n.t('youtube')]: ExploreYoutube,
[my_i18n.t('ladder')]: ExploreLambda
},
{
tabBarOptions: {
upperCaseLabel: false,
indicatorStyle: {backgroundColor:color.dark_pup},
labelStyle: {fontWeight: "bold", fontSize: itemFontSize+2, color:'black'},
style: {
flexDirection:'column-reverse',
paddingBottom:2,
backgroundColor: color.light_pup_header,
height: Constants.statusBarHeight + 35,
},
tabStyle: {...styles.statusBar, height:null, paddingBottom:0}
},
}
)
// export const ExploreView = withNavigationFocus(_ExploreView)
function ExploreYoutube(props){
// console.log('updating home')
var ref_out = null;
const [show_modal, setShowModal] = useState(false);
const upload2Cloud = () => {
Alert.alert(
my_i18n.t('homeView_alr1'),
null,
[
{text: my_i18n.t('ok_butt'), onPress: () => ref_out.injectJavaScript("window.ReactNativeWebView.postMessage(window.location.href);")},
{text: my_i18n.t('cancel_butt'), onPress: () => {}, style: 'cancel'}
],
)
}
const goBackHome = () => {
ref_out.injectJavaScript("window.location.href = 'https://www.youtube.com';");
setShowModal(false);
}
const historyGoBack = () => {
ref_out.injectJavaScript("window.history.go(-1);");
}
const historyGoForward = () => {
ref_out.injectJavaScript("window.history.go(1);");
}
const logOut = async () => {
console.log('logging out')
let something = await Auth.signOut();
console.log(something)
// .then(data => console.log(data));
props.navigation.navigate('AuthLoading');
}
const webOnMessage = useCallback(async ({nativeEvent: state}) => {
const parsed = state.data.match(/http.:\/\/(www|m)\.youtube\.com.*\?*v=([^&]*).*/);
if (parsed == '' || parsed == null){
Alert.alert(my_i18n.t('homeView_alr2_1'), my_i18n.t('homeView_alr2_2'))
}else{
const you_id = parsed[2];
const user_info = await Auth.currentUserInfo();
const user_id = user_info.id;
console.log('Downloading ' + you_id + ' for ' + user_id);
response = await fetch('https://vxmaikxa2m.execute-api.us-west-2.amazonaws.com/beta/trans', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
you_id: you_id,
user_id: user_id
})
});
res_json = await response.json();
process_upload_json(res_json);
}
});
const HomeModal = (
<Modal
animationType="fade"
transparent={true}
visible={show_modal}
>
<View style={{...styles.modalBack, justifyContent: 'center'}}>
<TouchableWithoutFeedback onPress = {() => setShowModal(false)}>
<View style = {styles.modalTouchClose}/>
</TouchableWithoutFeedback>
<View style ={{...styles.modalInCenter, height: null}}>
<IconText
title = {my_i18n.t('homeView_yh')}
iconName = 'youtube'
iconType = 'material-community'
iconColor = {'red'}
onItemClick = {goBackHome}
/>
<View style = {styles.graySeparator}/>
<IconText
title = {my_i18n.t('homeView_so')}
iconName = 'sign-out'
iconType = 'font-awesome'
iconColor = {color.dark_pup}
onItemClick = {logOut}
/>
</View>
</View>
</Modal>
)
return (
<View style={styles.allView} behavior={'padding'}>
{HomeModal}
{false && <View style = {styles.statusBar}>
<Text style={{fontWeight: "bold", fontSize: itemFontSize+2}}>EXPLORE</Text>
</View>}
<View style = {styles.afterStatus}>
<View style = {{flexDirection: 'row', justifyContent: 'space-around', alignSelf: 'stretch'}}>
<TouchableOpacity
style = {styles.grayContainer}
onPress={historyGoBack}
>
<Icon
name = 'first-page'
color = {color.primary}
size = {itemFontSize * 2}
/>
</TouchableOpacity>
<TouchableOpacity
style = {styles.grayContainer}
onPress={historyGoForward}
>
<Icon
name = 'last-page'
color = {color.primary}
size = {itemFontSize * 2}
/>
</TouchableOpacity>
<TouchableOpacity
style = {styles.grayContainer}
onPress={upload2Cloud}
>
<Icon
name = 'cloud-upload'
color = {color.primary}
size = {itemFontSize * 2}
/>
</TouchableOpacity>
<TouchableOpacity
style = {styles.grayContainer}
onPress={() => setShowModal(true)}
>
<Icon
name = 'more-vert'
color = {color.primary}
size = {itemFontSize * 2}
/>
</TouchableOpacity>
</View>
<View
style={{ flex: 1, alignSelf: 'stretch' }}
>
<WebView
ref={ref => (ref_out = ref)}
style={{alignSelf: 'stretch'}}
source={{
uri: 'https://www.youtube.com',
}}
onMessage={webOnMessage}
/>
</View>
</View>
</View>
);
}