more
This commit is contained in:
@@ -2,7 +2,13 @@ import React, { createContext, useContext, useEffect, useReducer } from "react";
|
||||
import { useGroupReducer } from "../useReducer/reducers";
|
||||
import { AuthContext } from "../../Context/AuthProvider";
|
||||
import { db } from "../../firebase.js";
|
||||
import { collection, getDocs, query, where, onSnapshot } from "firebase/firestore";
|
||||
import {
|
||||
collection,
|
||||
getDocs,
|
||||
query,
|
||||
where,
|
||||
onSnapshot,
|
||||
} from "firebase/firestore";
|
||||
|
||||
const initialState = {
|
||||
group: undefined,
|
||||
@@ -16,9 +22,9 @@ const AppContext = createContext({
|
||||
const AppProvider = ({ children }) => {
|
||||
const { currentUserEmail } = useContext(AuthContext);
|
||||
const [appState, appDispatch] = useReducer(useGroupReducer, initialState);
|
||||
|
||||
console.log("currentUserEmail in AppProvider", currentUserEmail);
|
||||
useEffect(() => {
|
||||
if (typeof currentUserEmail === 'undefined') {
|
||||
if (typeof currentUserEmail === "undefined") {
|
||||
return;
|
||||
}
|
||||
if (!currentUserEmail) {
|
||||
@@ -26,13 +32,10 @@ const AppProvider = ({ children }) => {
|
||||
return;
|
||||
}
|
||||
return onSnapshot(
|
||||
query(
|
||||
collection(db, "users"),
|
||||
where("email", "==", currentUserEmail)
|
||||
),
|
||||
snapshot => {
|
||||
query(collection(db, "users"), where("email", "==", currentUserEmail)),
|
||||
(snapshot) => {
|
||||
const doc = snapshot.docs[0];
|
||||
if (typeof doc === 'undefined') {
|
||||
if (typeof doc === "undefined") {
|
||||
appDispatch({ type: "DELETE_GROUP" });
|
||||
} else {
|
||||
appDispatch({ type: "CREATE_GROUP", payload: doc.data() });
|
||||
|
||||
Reference in New Issue
Block a user