- switching from firestore to realtime DB

- implement debouncing tactic to sync data
- display sync indicator
This commit is contained in:
Amruth Pillai
2020-07-06 00:25:31 +05:30
parent 49a867dd37
commit 65fc779d58
15 changed files with 180 additions and 142 deletions

View File

@ -1,8 +1,8 @@
import React, { createContext, useState, useEffect } from "react";
import { useAuthState } from "react-firebase-hooks/auth";
import firebase from "gatsby-plugin-firebase";
import { toast } from "react-toastify";
import { pick } from "lodash";
import React, { createContext, useEffect, useState } from "react";
import { useAuthState } from "react-firebase-hooks/auth";
import { toast } from "react-toastify";
const defaultUser = {
uid: null,
@ -35,9 +35,9 @@ const UserProvider = ({ children }) => {
localStorage.setItem("user", JSON.stringify(user));
const addUserToDatabase = async () => {
const docRef = firebase.firestore().collection("users").doc(user.uid);
const snapshot = await docRef.get();
!snapshot.exists && docRef.set(user);
const userRef = firebase.database().ref(`users/${user.uid}`);
const snapshot = await userRef.once("value");
!snapshot.val() && userRef.set(user);
};
addUserToDatabase();