From fe2e58850c27f705819116c58f1e54307e31d9bd Mon Sep 17 00:00:00 2001 From: GRZ4NA Date: Fri, 8 Oct 2021 18:21:13 +0200 Subject: [PATCH] MAJOR data flow change (events) Made API_CLIENT stateless, used context to distribute data over the application --- client/src/App.js | 101 ++----- .../src/components/EventPreviewEdit/index.js | 8 +- client/src/context/Events.js | 49 ++++ client/src/index.js | 7 +- client/src/pages/CreateEvent/index.js | 4 +- client/src/pages/Dashboard/index.js | 61 +++-- client/src/pages/Home/index.js | 251 +++++++----------- client/src/utils/APIClient.js | 16 +- 8 files changed, 223 insertions(+), 274 deletions(-) create mode 100644 client/src/context/Events.js diff --git a/client/src/App.js b/client/src/App.js index 39e18ac..d768bd1 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -8,82 +8,35 @@ import { Navbar } from "./components/Navbar"; import { Footer } from "./components/Footer"; import { CreateEvent } from "./pages/CreateEvent"; import { Event } from "./pages/Event"; -import { API_CLIENT } from "./constants"; +import { useEvents } from "./context/Events"; export const App = () => { - const [routes, setRoutes] = useState( - API_CLIENT.events.map((e) => { - return ( - - - - ); - }) - ); - + const events = useEvents(); + const [routes, setRoutes] = useState([]); useEffect(() => { - API_CLIENT.on("EVENT_RELOAD", (list) => { - setRoutes( - list.map((e) => { - return ( - - - - ); - }) - ); - }); - API_CLIENT.on("EVENT_CREATE", (list) => { - setRoutes( - list.map((e) => { - return ( - - - - ); - }) - ); - }); - }, []); + setRoutes( + events.map((e) => { + return ( + + + + ); + }) + ); + }, [events]); return ( @@ -98,7 +51,7 @@ export const App = () => { {routes} -