From 3c3576e0ade185a8d0dbbced5c68c1e5c2f50377 Mon Sep 17 00:00:00 2001 From: Gabriel Almeida Date: Mon, 22 May 2023 08:39:03 -0300 Subject: [PATCH] Format --- src/frontend/src/App.tsx | 289 +++++++++++++++++++-------------------- 1 file changed, 144 insertions(+), 145 deletions(-) diff --git a/src/frontend/src/App.tsx b/src/frontend/src/App.tsx index e0d19fd40..69b41fdf4 100644 --- a/src/frontend/src/App.tsx +++ b/src/frontend/src/App.tsx @@ -16,153 +16,152 @@ import CrashErrorComponent from "./components/CrashErrorComponent"; import { TabsContext } from "./contexts/tabsContext"; export default function App() { + let { setCurrent, setShowSideBar, setIsStackedOpen } = + useContext(locationContext); + let location = useLocation(); + useEffect(() => { + setCurrent(location.pathname.replace(/\/$/g, "").split("/")); + setShowSideBar(true); + setIsStackedOpen(true); + }, [location.pathname, setCurrent, setIsStackedOpen, setShowSideBar]); + const { hardReset } = useContext(TabsContext); + const { + errorData, + errorOpen, + setErrorOpen, + noticeData, + noticeOpen, + setNoticeOpen, + successData, + successOpen, + setSuccessOpen, + } = useContext(alertContext); - let { setCurrent, setShowSideBar, setIsStackedOpen } = - useContext(locationContext); - let location = useLocation(); - useEffect(() => { - setCurrent(location.pathname.replace(/\/$/g, "").split("/")); - setShowSideBar(true); - setIsStackedOpen(true); - }, [location.pathname, setCurrent, setIsStackedOpen, setShowSideBar]); - const { hardReset } = useContext(TabsContext); - const { - errorData, - errorOpen, - setErrorOpen, - noticeData, - noticeOpen, - setNoticeOpen, - successData, - successOpen, - setSuccessOpen, - } = useContext(alertContext); + // Initialize state variable for the list of alerts + const [alertsList, setAlertsList] = useState< + Array<{ + type: string; + data: { title: string; list?: Array; link?: string }; + id: string; + }> + >([]); - // Initialize state variable for the list of alerts - const [alertsList, setAlertsList] = useState< - Array<{ - type: string; - data: { title: string; list?: Array; link?: string }; - id: string; - }> - >([]); + // Use effect hook to update alertsList when a new alert is added + useEffect(() => { + // If there is an error alert open with data, add it to the alertsList + if (errorOpen && errorData) { + setErrorOpen(false); + setAlertsList((old) => { + let newAlertsList = [ + ...old, + { type: "error", data: _.cloneDeep(errorData), id: _.uniqueId() }, + ]; + return newAlertsList; + }); + } + // If there is a notice alert open with data, add it to the alertsList + else if (noticeOpen && noticeData) { + setNoticeOpen(false); + setAlertsList((old) => { + let newAlertsList = [ + ...old, + { type: "notice", data: _.cloneDeep(noticeData), id: _.uniqueId() }, + ]; + return newAlertsList; + }); + } + // If there is a success alert open with data, add it to the alertsList + else if (successOpen && successData) { + setSuccessOpen(false); + setAlertsList((old) => { + let newAlertsList = [ + ...old, + { type: "success", data: _.cloneDeep(successData), id: _.uniqueId() }, + ]; + return newAlertsList; + }); + } + }, [ + _, + errorData, + errorOpen, + noticeData, + noticeOpen, + setErrorOpen, + setNoticeOpen, + setSuccessOpen, + successData, + successOpen, + ]); - // Use effect hook to update alertsList when a new alert is added - useEffect(() => { - // If there is an error alert open with data, add it to the alertsList - if (errorOpen && errorData) { - setErrorOpen(false); - setAlertsList((old) => { - let newAlertsList = [ - ...old, - { type: "error", data: _.cloneDeep(errorData), id: _.uniqueId() }, - ]; - return newAlertsList; - }); - } - // If there is a notice alert open with data, add it to the alertsList - else if (noticeOpen && noticeData) { - setNoticeOpen(false); - setAlertsList((old) => { - let newAlertsList = [ - ...old, - { type: "notice", data: _.cloneDeep(noticeData), id: _.uniqueId() }, - ]; - return newAlertsList; - }); - } - // If there is a success alert open with data, add it to the alertsList - else if (successOpen && successData) { - setSuccessOpen(false); - setAlertsList((old) => { - let newAlertsList = [ - ...old, - { type: "success", data: _.cloneDeep(successData), id: _.uniqueId() }, - ]; - return newAlertsList; - }); - } - }, [ - _, - errorData, - errorOpen, - noticeData, - noticeOpen, - setErrorOpen, - setNoticeOpen, - setSuccessOpen, - successData, - successOpen, - ]); + const removeAlert = (id: string) => { + setAlertsList((prevAlertsList) => + prevAlertsList.filter((alert) => alert.id !== id) + ); + }; - const removeAlert = (id: string) => { - setAlertsList((prevAlertsList) => - prevAlertsList.filter((alert) => alert.id !== id) - ); - }; - - return ( - //need parent component with width and height -
-
- { - window.localStorage.removeItem("tabsData"); - window.localStorage.clear(); - hardReset(); - window.location.href = window.location.href; - }} - FallbackComponent={CrashErrorComponent} - > -
- - {/* Main area */} -
- {/* Primary column */} -
- -
-
-
-
-
-
- {alertsList.map((alert) => ( -
- {alert.type === "error" ? ( - - ) : alert.type === "notice" ? ( - - ) : ( - - )} -
- ))} -
- - Created by Logspace - -
- ); + return ( + //need parent component with width and height +
+
+ { + window.localStorage.removeItem("tabsData"); + window.localStorage.clear(); + hardReset(); + window.location.href = window.location.href; + }} + FallbackComponent={CrashErrorComponent} + > +
+ + {/* Main area */} +
+ {/* Primary column */} +
+ +
+
+
+
+
+
+ {alertsList.map((alert) => ( +
+ {alert.type === "error" ? ( + + ) : alert.type === "notice" ? ( + + ) : ( + + )} +
+ ))} +
+ + Created by Logspace + +
+ ); }