From 4206a2183ca0e196e27b05fb2801523e912f7a2f Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Wed, 12 Apr 2023 20:22:57 -0300 Subject: [PATCH] added LIFO history to popUp context --- src/frontend/src/contexts/popUpContext.tsx | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/frontend/src/contexts/popUpContext.tsx b/src/frontend/src/contexts/popUpContext.tsx index 1d4d28bc7..efa263146 100644 --- a/src/frontend/src/contexts/popUpContext.tsx +++ b/src/frontend/src/contexts/popUpContext.tsx @@ -1,33 +1,33 @@ import { createContext } from "react"; import React, { useState } from "react"; -//context to set JSX element on the DOM +// context to set JSX element on the DOM export const PopUpContext = createContext({ openPopUp: (popUpElement: JSX.Element) => {}, - closePopUp: () => {}, + closePopUp: () => {}, }); interface PopUpProviderProps { - children: React.ReactNode; + children: React.ReactNode; } const PopUpProvider = ({ children }: PopUpProviderProps) => { - const [popUpElement, setPopUpElement] = useState(null); + const [popUpElements, setPopUpElements] = useState([]); - const openPopUp = (element: JSX.Element) => { - setPopUpElement(element); - }; + const openPopUp = (element: JSX.Element) => { + setPopUpElements(prevPopUps => [element, ...prevPopUps]); + }; - const closePopUp = () => { - setPopUpElement(null); - }; + const closePopUp = () => { + setPopUpElements(prevPopUps => prevPopUps.slice(1)); + }; - return ( - - {children} - {popUpElement} - - ); + return ( + + {children} + {popUpElements[0]} + + ); }; export default PopUpProvider;