-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1.js
85 lines (83 loc) · 2.1 KB
/
test1.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
import React from 'react';
import {
StyleSheet,
SafeAreaView,
StatusBar,
Platform,
Text,
Button,
Alert,
View,
Image,
} from 'react-native';
import firestore from '@react-native-firebase/firestore';
import AsyncStorage from '@react-native-async-storage/async-storage';
export default function AddData() {
function Add() {
firestore()
.collection('words2')
.add({
exam: 'GRE',
example: '',
image: '',
meaning: '',
mnemonic: '',
parent_a: '',
parent_b: '',
parent_c: '',
synonyms: null,
word: null,
})
.then(() => {
console.log('User added!');
});
}
function ShowCurrentUser() {
const valuePromise = AsyncStorage.getItem('currentUser');
valuePromise.then(value => {
console.log(JSON.parse(value).uid);
});
} //SHOWS CURRENT USER OBJECT FROM ASYNCSTORAGE
function ShowUserData() {
const valuePromise = AsyncStorage.getItem('userOrigin');
valuePromise.then(value => {
console.log(JSON.parse(value));
let userdata = JSON.parse(value);
let Learned = userdata.learned.split(',');
let Learning = userdata.learning.split(',');
if (Learning.find(element => element == 'a')) {
console.log('ok');
}
let Arr = [Learning, Learned];
return Arr;
});
}
return (
<View style={styles.container}>
<Button title="AddWord" onPress={() => Add()} />
<Button title="Show Current User" onPress={() => ShowCurrentUser()} />
<Button title="Show User Data" onPress={() => ShowUserData()} />
<Button title="Check and Push" onPress={() => CheckData()} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
alignItems: 'stretch',
justifyContent: 'space-around',
paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight : 0,
},
title: {
alignItems: 'center',
justifyContent: 'flex-start',
},
buttons: {
flexDirection: 'column',
justifyContent: 'flex-start',
},
separator: {
marginVertical: 10,
},
});