first commit

This commit is contained in:
Kenneth Jannette
2024-01-11 18:24:41 -06:00
commit 4c1fb67383
103 changed files with 29954 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
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";
const initialState = {
group: undefined,
};
const AppContext = createContext({
state: initialState,
dispatch: () => null,
});
const AppProvider = ({ children }) => {
const { currentUserEmail } = useContext(AuthContext);
const [appState, appDispatch] = useReducer(useGroupReducer, initialState);
useEffect(() => {
if (typeof currentUserEmail === 'undefined') {
return;
}
if (!currentUserEmail) {
appDispatch({ type: "DELETE_GROUP" });
return;
}
return onSnapshot(
query(
collection(db, "users"),
where("email", "==", currentUserEmail)
),
snapshot => {
const doc = snapshot.docs[0];
if (typeof doc === 'undefined') {
appDispatch({ type: "DELETE_GROUP" });
} else {
appDispatch({ type: "CREATE_GROUP", payload: doc.data() });
}
}
);
}, [currentUserEmail]);
return (
<AppContext.Provider value={{ appState, appDispatch }}>
{children}
</AppContext.Provider>
);
};
export { AppContext, AppProvider };

View File

@@ -0,0 +1,22 @@
import React, { createContext, useReducer } from "react";
import { useDataReducer } from "../useReducer/reducers";
const initialState = {
cases: [{}],
};
const DataContext = createContext({
state: initialState,
dispatch: () => null,
});
const DataProvider = ({ children }) => {
const [dataState, dataDispatch] = useReducer(useDataReducer, initialState);
return (
<DataContext.Provider value={{ dataState, dataDispatch }}>
{children}
</DataContext.Provider>
);
};
export { DataContext, DataProvider };

View File

@@ -0,0 +1,15 @@
import { useQuery } from "react-query";
import { db } from "../../firebase";
import { collection } from "firebase/firestore";
const casesRef = collection(db, "cases");
export const useCases = (userId) => {
return useQuery(userId, async () => {
const queryParams = {
userId: userId,
};
const response = await someEndpoint;
//return response
});
};

View File

@@ -0,0 +1,25 @@
export const useGroupReducer = (state, action) => {
switch (action.type) {
case "CREATE_GROUP":
return { ...state, group: action.payload };
case "UPDATE_GROUP_NAME":
console.log("state, action.payload", state, action.payload);
return [...state, { name: action.payload }];
case "DELETE_GROUP":
return { ...state, group: null };
default:
return state;
}
};
export const useDataReducer = (state, action) => {
switch (action.type) {
case "CREATE_CASES":
return { ...state, cases: action.payload };
case "UPDATE_GROUP_NAME":
console.log("state, action.payload", state, action.payload);
return [...state, { cases: action.payload }];
default:
return state;
}
};