Skip to content

Instantly share code, notes, and snippets.

View thedevdavid's full-sized avatar
🎯
Focusing

Dávid Lévai thedevdavid

🎯
Focusing
View GitHub Profile
@thedevdavid
thedevdavid / App.js
Created December 7, 2017 14:46
App.js real-time Firestore implementation
View App.js
constructor() {
super();
this.ref = firebase.firestore().collection('posts');
this.unsubscribe = null;
this.state = {
posts: [],
loading: true,
};
}
@thedevdavid
thedevdavid / App.js
Created December 7, 2017 15:05
Add random post method
View App.js
addRandomPost = () => {
this.ref.add({
title: 'Added post by random button',
likes: Math.floor((Math.random() * 10) + 1),
uri: `https://picsum.photos/200/300?image=${Math.floor((Math.random() * 100) + 1)}`,
});
}
@thedevdavid
thedevdavid / App.js
Last active December 8, 2017 11:23
Auth mods
View App.js
constructor() {
super();
this.ref = firebase.firestore().collection('posts');
this.firestoreUnsubscriber = null;
this.authUnsubscriber = null;
this.state = {
posts: [],
loading: true,
loggingIn: false,
user: null,
@thedevdavid
thedevdavid / App.js
Last active December 8, 2017 12:25
Helper functions
View App.js
onLogin = async () => {
try {
const response = await firebase.auth().signInWithEmailAndPassword(this.state.emailValue, this.state.passwordValue);
console.log(response);
this.setState({
loggingIn: false,
emailValue: '',
passwordValue: '',
hasError: false,
error: '',
@thedevdavid
thedevdavid / store.js
Created February 26, 2018 10:25
store.js
View store.js
import { createStore, applyMiddleware } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import ReduxThunk from 'redux-thunk';
import logger from 'redux-logger';
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';
import rootReducer from '../reducers';
const middlewares = [ReduxThunk];
@thedevdavid
thedevdavid / index.js
Created February 26, 2018 10:40
index.js
View index.js
import React from 'react';
import { AppRegistry, Text } from 'react-native';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/lib/integration/react';
import configureStore from './src/config/store';
import App from './App';
const { store, persistor } = configureStore();
@thedevdavid
thedevdavid / auth.js
Created February 26, 2018 10:48
Auth reducer
View auth.js
import types from '../actions/types';
const initialState = {
loggedIn: false,
isFetching: false,
hasError: false,
errorMessage: '',
user: null
};
@thedevdavid
thedevdavid / App.js
Created February 26, 2018 12:59
Final App.js
View App.js
import React, { Component } from 'react';
import {
Text,
View,
ActivityIndicator,
FlatList,
Button,
TouchableOpacity,
} from 'react-native';
import firebase from 'react-native-firebase';
View Keybase Proof
### Keybase proof
I hereby claim:
* I am dlevai94 on github.
* I am davidlevai (https://keybase.io/davidlevai) on keybase.
* I have a public key ASAOdV3xUbOJPm2SsdSixNjloFsfFPQMbATUD0orpJh-Fgo
To claim this, I am signing this object: