mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-18 10:41:56 +10:00
- switching from firestore to realtime DB
- implement debouncing tactic to sync data - display sync indicator
This commit is contained in:
@ -1,30 +1,26 @@
|
||||
import { set } from "lodash";
|
||||
import React, { createContext, useReducer } from "react";
|
||||
import React, { createContext, useContext, useReducer } from "react";
|
||||
import DatabaseContext from "./DatabaseContext";
|
||||
|
||||
const initialState = {
|
||||
id: "dafa3242-f39a-4755-bab3-be3c3ca3d190",
|
||||
profile: {
|
||||
photograph: "",
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
},
|
||||
createdAt: "",
|
||||
updatedAt: "",
|
||||
};
|
||||
|
||||
const ResumeContext = createContext(initialState);
|
||||
const ResumeContext = createContext({});
|
||||
|
||||
const ResumeProvider = ({ children }) => {
|
||||
const { updateResume } = useContext(DatabaseContext);
|
||||
|
||||
const [state, dispatch] = useReducer((state, { type, payload }) => {
|
||||
let newState;
|
||||
|
||||
switch (type) {
|
||||
case "on_input":
|
||||
return set({ ...state }, payload.path, payload.value);
|
||||
newState = set({ ...state }, payload.path, payload.value);
|
||||
updateResume(newState);
|
||||
return newState;
|
||||
case "set_data":
|
||||
return payload;
|
||||
default:
|
||||
throw new Error();
|
||||
}
|
||||
}, initialState);
|
||||
}, {});
|
||||
|
||||
return (
|
||||
<ResumeContext.Provider value={{ state, dispatch }}>
|
||||
|
||||
Reference in New Issue
Block a user