Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import React from 'react';
  2. import { StyleSheet, View, TextInput } from 'react-native';
  3.  
  4. import db from '../Database.js';
  5.  
  6. class LoginForm extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. }
  10.  
  11. render() {
  12. return (
  13. <View style={styles.container}>
  14. <TextInput
  15. placeholder="Access Code"
  16. returnKeyType="go"
  17. onSubmitEditing={text => {db.checkCode(text.nativeEvent.text)}}
  18. />
  19. </View>
  20. );
  21. }
  22. }
  23.  
  24. const styles = StyleSheet.create({ // stylesheet
  25. // yay styles :)
  26. });
  27.  
  28. export default LoginForm;
  29.  
  30. //import * as firebase from "firebase";
  31. var firebase = require('firebase');
  32.  
  33. if (!firebase.apps.length) {
  34. firebase.initializeApp({
  35. apiKey: "key",
  36. authDomain: "domain",
  37. databaseURL: "url",
  38. storageBucket: "bucket",
  39. });
  40. }
  41.  
  42. class Database {
  43.  
  44. codesRef = firebase.database().ref('codes');
  45.  
  46. static checkCode(text) {
  47. let codeIsFound = false;
  48. this.codesRef.once('value', (db_snapshot) => { // this won't work
  49. db_snapshot.forEach((code_snapshot) => {
  50. if (text == code_snapshot.val().value) {
  51. codeIsFound = true;
  52. identifier = code_snapshot.key;
  53. }
  54. });
  55. });
  56. if (codeIsFound) {
  57. //this.deleteCode(identifier);
  58. console.log("code found");
  59. this.props.navigation.navigate('Create'); // side-question => how can i get this working in Database.js? Do i need to use withNavigation?
  60. } else {
  61. console.log("code not found");
  62. );
  63. }
  64. };
  65. }
  66.  
  67. module.exports = Database;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement