From 33b2bfb0d2dbabc13066eb0c4c41e34f7ce9e946 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi <256895@studenti.unimore.it> Date: Mon, 26 Apr 2021 18:36:41 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=92=A5=20Refactor=20the=20login/logou?= =?UTF-8?q?t=20flow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/backend/backend.iml | 2 +- code/frontend/src/App.js | 78 ++++++++--------- code/frontend/src/App.module.css | 9 -- code/frontend/src/components/BoxAlert.js | 22 +++++ .../src/components/BoxAlert.module.css | 25 ++++++ .../src/components/BoxFullScrollable.js | 2 +- code/frontend/src/components/BoxLoggedIn.js | 14 ++- code/frontend/src/components/BoxLogin.js | 85 ++++++++++++++++++ code/frontend/src/components/BoxSetServer.js | 35 ++++++++ code/frontend/src/components/ButtonSidebar.js | 2 +- code/frontend/src/components/CurrentServer.js | 22 +++++ code/frontend/src/components/FormAlert.js | 22 +++++ .../src/components/FormAlert.module.css | 3 + code/frontend/src/components/FormButton.js | 19 ++++ .../src/components/FormButton.module.css | 3 + .../src/components/{Label.js => FormLabel.js} | 7 +- ...{Label.module.css => FormLabel.module.css} | 0 .../{LabelledForm.js => FormLabelled.js} | 9 +- ...orm.module.css => FormLabelled.module.css} | 0 code/frontend/src/components/GlobalServer.js | 64 ++++++++++++++ code/frontend/src/components/GlobalTheme.js | 21 +++++ code/frontend/src/components/GlobalUser.js | 86 +++++++++++++++++++ code/frontend/src/components/Layout.js | 11 ++- .../frontend/src/components/Layout.module.css | 9 +- code/frontend/src/components/LoggedInUser.js | 23 +++-- .../src/components/LoggedInUser.module.css | 3 - code/frontend/src/components/Logo.js | 2 +- .../components/RepositorySummary.module.css | 5 +- code/frontend/src/components/SelectTheme.js | 2 +- code/frontend/src/components/Sidebar.js | 10 +-- code/frontend/src/contexts/ContextLogin.js | 21 ----- code/frontend/src/contexts/ContextServer.js | 22 +++++ code/frontend/src/contexts/ContextTheme.js | 13 ++- code/frontend/src/contexts/ContextUser.js | 26 ++++++ code/frontend/src/hooks/useSavedLogin.js | 82 ------------------ code/frontend/src/hooks/useSavedTheme.js | 12 --- code/frontend/src/index.css | 4 + code/frontend/src/routes/PageDashboard.js | 16 ++-- code/frontend/src/routes/PageLogin.js | 64 ++------------ code/frontend/src/routes/PageRoot.js | 4 +- 40 files changed, 576 insertions(+), 283 deletions(-) delete mode 100644 code/frontend/src/App.module.css create mode 100644 code/frontend/src/components/BoxAlert.js create mode 100644 code/frontend/src/components/BoxAlert.module.css create mode 100644 code/frontend/src/components/BoxLogin.js create mode 100644 code/frontend/src/components/BoxSetServer.js create mode 100644 code/frontend/src/components/CurrentServer.js create mode 100644 code/frontend/src/components/FormAlert.js create mode 100644 code/frontend/src/components/FormAlert.module.css create mode 100644 code/frontend/src/components/FormButton.js create mode 100644 code/frontend/src/components/FormButton.module.css rename code/frontend/src/components/{Label.js => FormLabel.js} (80%) rename code/frontend/src/components/{Label.module.css => FormLabel.module.css} (100%) rename code/frontend/src/components/{LabelledForm.js => FormLabelled.js} (50%) rename code/frontend/src/components/{LabelledForm.module.css => FormLabelled.module.css} (100%) create mode 100644 code/frontend/src/components/GlobalServer.js create mode 100644 code/frontend/src/components/GlobalTheme.js create mode 100644 code/frontend/src/components/GlobalUser.js delete mode 100644 code/frontend/src/components/LoggedInUser.module.css delete mode 100644 code/frontend/src/contexts/ContextLogin.js create mode 100644 code/frontend/src/contexts/ContextServer.js create mode 100644 code/frontend/src/contexts/ContextUser.js delete mode 100644 code/frontend/src/hooks/useSavedLogin.js delete mode 100644 code/frontend/src/hooks/useSavedTheme.js diff --git a/code/backend/backend.iml b/code/backend/backend.iml index e6b7d9d..65017c1 100644 --- a/code/backend/backend.iml +++ b/code/backend/backend.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/code/frontend/src/App.js b/code/frontend/src/App.js index 97c3789..f365622 100644 --- a/code/frontend/src/App.js +++ b/code/frontend/src/App.js @@ -1,7 +1,4 @@ -import classNames from "classnames" -import Style from "./App.module.css" import Layout from "./components/Layout" -import ContextTheme from "./contexts/ContextTheme" import { BrowserRouter } from "react-router-dom" import { Route, Switch } from "react-router" import PageDashboard from "./routes/PageDashboard" @@ -9,11 +6,11 @@ import PageRepositories from "./routes/PageRepositories" import PageAlerts from "./routes/PageAlerts" import PageSettings from "./routes/PageSettings" import PageSandbox from "./routes/PageSandbox" -import useSavedTheme from "./hooks/useSavedTheme" import PageLogin from "./routes/PageLogin" -import useSavedLogin from "./hooks/useSavedLogin" -import ContextLogin from "./contexts/ContextLogin" import PageRoot from "./routes/PageRoot" +import GlobalTheme from "./components/GlobalTheme" +import GlobalServer from "./components/GlobalServer" +import GlobalUser from "./components/GlobalUser" /** @@ -23,44 +20,41 @@ import PageRoot from "./routes/PageRoot" * @constructor */ export default function App() { - const theme = useSavedTheme(); - const login = useSavedLogin(); - return ( - - - + + + + -
- - - - - - - - - - - - - - - - - - - - - - - - - -
+ + + + + + + + + + + + + + + + + + + + + + + + + -
-
-
+ + + + ) } diff --git a/code/frontend/src/App.module.css b/code/frontend/src/App.module.css deleted file mode 100644 index 6f2e85c..0000000 --- a/code/frontend/src/App.module.css +++ /dev/null @@ -1,9 +0,0 @@ -.App { - height: 100vh; - width: 100vw; - - padding: 16px; - - background-color: var(--bg-primary); - color: var(--fg-primary); -} \ No newline at end of file diff --git a/code/frontend/src/components/BoxAlert.js b/code/frontend/src/components/BoxAlert.js new file mode 100644 index 0000000..829b28a --- /dev/null +++ b/code/frontend/src/components/BoxAlert.js @@ -0,0 +1,22 @@ +import React from "react" +import Style from "./BoxAlert.module.css" +import classNames from "classnames" + + +/** + * A colored alert box to draw the user's attention. + * + * @param color - The color of the alert. + * @param children - The contents of the alert. + * @param className - Additional class(es) to add to the div. + * @param props - Additional props to pass to the div. + * @returns {JSX.Element} + * @constructor + */ +export default function BoxAlert({ color, children, className, ...props }) { + return ( +
+ {children} +
+ ) +} diff --git a/code/frontend/src/components/BoxAlert.module.css b/code/frontend/src/components/BoxAlert.module.css new file mode 100644 index 0000000..2f3e220 --- /dev/null +++ b/code/frontend/src/components/BoxAlert.module.css @@ -0,0 +1,25 @@ +.BoxAlert { + padding: 5px 20px; + border-radius: 25px; + box-shadow: 0 4px 4px rgba(0, 0, 0, 0.25); +} + +.BoxAlertRed { + color: var(--fg-red); + background-color: var(--bg-red); +} + +.BoxAlertGreen { + color: var(--fg-green); + background-color: var(--bg-green); +} + +.BoxAlertYellow { + color: var(--fg-yellow); + background-color: var(--bg-yellow); +} + +.BoxAlertGrey { + color: var(--fg-grey); + background-color: var(--bg-grey); +} \ No newline at end of file diff --git a/code/frontend/src/components/BoxFullScrollable.js b/code/frontend/src/components/BoxFullScrollable.js index bfd714f..cd38fbb 100644 --- a/code/frontend/src/components/BoxFullScrollable.js +++ b/code/frontend/src/components/BoxFullScrollable.js @@ -5,7 +5,7 @@ import BoxFull from "./BoxFull" /** - * A {@link BoxFull} whose body does not grow automatically but instead supports scrolling. + * A {@link BoxFull} whose body supports scrolling. * * @param children - The contents of the box body. * @param childrenClassName - Additional class(es) added to the inner `
` acting as the body. diff --git a/code/frontend/src/components/BoxLoggedIn.js b/code/frontend/src/components/BoxLoggedIn.js index 5205bf8..533ead6 100644 --- a/code/frontend/src/components/BoxLoggedIn.js +++ b/code/frontend/src/components/BoxLoggedIn.js @@ -3,20 +3,28 @@ import BoxFull from "./BoxFull" import LoggedInUser from "./LoggedInUser" import Button from "./Button" import { faSignOutAlt } from "@fortawesome/free-solid-svg-icons" -import ContextLogin from "../contexts/ContextLogin" +import ContextUser from "../contexts/ContextUser" import { useHistory } from "react-router" import Style from "./BoxLoggedIn.module.css" +import CurrentServer from "./CurrentServer" +/** + * A {@link BoxFull} displaying the user's current login status, and allowing them to logout. + * + * @param props + * @returns {JSX.Element} + * @constructor + */ export default function BoxLoggedIn({ ...props }) { - const {logout} = useContext(ContextLogin) + const {logout} = useContext(ContextUser) const history = useHistory() return (
- You are currently logged in as . + You are currently logged in at as .
+ ) +} diff --git a/code/frontend/src/components/FormButton.module.css b/code/frontend/src/components/FormButton.module.css new file mode 100644 index 0000000..cb23c71 --- /dev/null +++ b/code/frontend/src/components/FormButton.module.css @@ -0,0 +1,3 @@ +.FormButton { + grid-column: 1 / 3; +} diff --git a/code/frontend/src/components/Label.js b/code/frontend/src/components/FormLabel.js similarity index 80% rename from code/frontend/src/components/Label.js rename to code/frontend/src/components/FormLabel.js index 669baa6..febdcca 100644 --- a/code/frontend/src/components/Label.js +++ b/code/frontend/src/components/FormLabel.js @@ -1,9 +1,10 @@ import React, { Fragment } from "react" -import Style from "./Label.module.css" +import Style from "./FormLabel.module.css" /** - * A row of a {@link LabelledForm}. + * A row of a {@link FormLabelled}. + * * It displays a label on the first column and a container for the labelled element on the second column. * * @param children - The labelled element. @@ -12,7 +13,7 @@ import Style from "./Label.module.css" * @returns {JSX.Element} * @constructor */ -export default function Label({ children, text, htmlFor }) { +export default function FormLabel({ children, text, htmlFor }) { return (