From 4ca2901724476d30e898e0a7798140b00e9d3aa5 Mon Sep 17 00:00:00 2001 From: Imane Date: Sun, 31 May 2020 11:57:31 +0200 Subject: [PATCH 1/4] feat(PageUniversity) : create lastVisitedUniversity when you click on a new university Relates to #149 --- frontend/src/components/pages/PageUniversity.jsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/pages/PageUniversity.jsx b/frontend/src/components/pages/PageUniversity.jsx index 2a4a0a67..d345c74d 100644 --- a/frontend/src/components/pages/PageUniversity.jsx +++ b/frontend/src/components/pages/PageUniversity.jsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect } from "react"; import PropTypes from "prop-types"; import Dialog from "@material-ui/core/Dialog"; import DialogActions from "@material-ui/core/DialogActions"; @@ -11,6 +11,7 @@ import { withErrorBoundary } from "../common/ErrorBoundary"; import APP_ROUTES from "../../config/appRoutes"; import CustomNavLink from "../common/CustomNavLink"; import UniversityService from "../../services/data/UniversityService"; +import { useApiCreate } from "../../hooks/wrappers/api"; function UniversityNotFound() { return ( @@ -34,13 +35,25 @@ function UniversityNotFound() { ); } +let lastVisitedUniv = -1; + /** * Component holding the page with the university details */ function PageUniversity({ match }) { const { univId, tabName } = match.params; + const createLastVisited = useApiCreate("lastVisitedUniversities"); + + useEffect(() => { + if (lastVisitedUniv !== univId) + createLastVisited({ university: univId }, () => { + lastVisitedUniv = univId; + }); + }, [univId]); + const parsedUnivId = parseInt(univId, 10); + if (UniversityService.hasUniversity(parsedUnivId)) { return ( -- GitLab From 9ff13c604bcd5851e9ec8281acb35eb3b70d14cc Mon Sep 17 00:00:00 2001 From: Imane Date: Sun, 31 May 2020 12:00:18 +0200 Subject: [PATCH 2/4] feat(LastVisitedUniversity) : add select component for lastVisitedUniversities Relates to #149 --- frontend/src/components/app/App.jsx | 2 + .../components/app/LastVisitedUniversity.jsx | 100 ++++++++++++++++++ .../src/components/common/LicenseNotice.jsx | 12 ++- 3 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 frontend/src/components/app/LastVisitedUniversity.jsx diff --git a/frontend/src/components/app/App.jsx b/frontend/src/components/app/App.jsx index 92006b53..c9f00a62 100644 --- a/frontend/src/components/app/App.jsx +++ b/frontend/src/components/app/App.jsx @@ -6,6 +6,7 @@ import { compose } from "recompose"; import { Route, Switch } from "react-router-dom"; import { withErrorBoundary } from "../common/ErrorBoundary"; +import LastVisitedUniversity from "./LastVisitedUniversity"; import PageMap from "../pages/PageMap"; import PageHome from "../pages/PageHome"; import PageUniversity from "../pages/PageUniversity"; @@ -90,6 +91,7 @@ function App() { + ); diff --git a/frontend/src/components/app/LastVisitedUniversity.jsx b/frontend/src/components/app/LastVisitedUniversity.jsx new file mode 100644 index 00000000..38e16741 --- /dev/null +++ b/frontend/src/components/app/LastVisitedUniversity.jsx @@ -0,0 +1,100 @@ +import React from "react"; +import { compose } from "recompose"; +import { makeStyles } from "@material-ui/styles"; +import InputLabel from "@material-ui/core/InputLabel"; +import FormControl from "@material-ui/core/FormControl"; +import Select from "@material-ui/core/Select"; +import MenuItem from "@material-ui/core/MenuItem"; +import PropTypes from "prop-types"; +import { withRouter } from "react-router-dom"; +import APP_ROUTES from "../../config/appRoutes"; +import withNetworkWrapper, { NetWrapParam } from "../../hoc/withNetworkWrapper"; +import UniversityService from "../../services/data/UniversityService"; +import NavigationService from "../../services/NavigationService"; +import LicenseNotice from "../common/LicenseNotice"; + +const useStyles = makeStyles((theme) => ({ + formControl: { + marginLeft: "auto", + marginRight: theme.spacing(2), + padding: theme.spacing(1), + maxWidth: "80%", + position: "sticky", + bottom: theme.spacing(2), + border: "solid", + borderWidth: 2, + borderRadius: theme.shape.borderRadius, + borderColor: theme.palette.primary.main, + borderStyle: "dashed", + backgroundColor: theme.palette.background.paper, + zIndex: 1000, + }, +})); + +function LastVisitedUniversity({ location, lastVisitedUniversities }) { + const classes = useStyles(); + + if ( + location.pathname === APP_ROUTES.base || + location.pathname === APP_ROUTES.themeSettings || + location.pathname === APP_ROUTES.myExchanges || + location.pathname === APP_ROUTES.editPreviousExchangeWithParams || + location.pathname === APP_ROUTES.userWithParams || + location.pathname === APP_ROUTES.aboutProject || + location.pathname === APP_ROUTES.aboutRgpd || + location.pathname === APP_ROUTES.aboutCgu || + location.pathname === APP_ROUTES.aboutUnlinkedPartners || + location.pathname === APP_ROUTES.logout + ) { + return <>; + } + + const handleChange = (event) => { + const univId = event.target.value; + if (univId !== "") NavigationService.goToUniversity(univId); + }; + + return ( +
+ + + Dernières universités visitées + + + + +
+ ); +} + +LastVisitedUniversity.propTypes = { + location: PropTypes.shape({ + pathname: PropTypes.string.isRequired, + }).isRequired, + lastVisitedUniversities: PropTypes.arrayOf( + PropTypes.shape({ + university: PropTypes.number.isRequired, + ts: PropTypes.string.isRequired, + }).isRequired + ).isRequired, +}; + +export default compose( + withNetworkWrapper([ + new NetWrapParam("lastVisitedUniversities", "all", { + addDataToProp: "lastVisitedUniversities", + }), + ]), + withRouter +)(LastVisitedUniversity); diff --git a/frontend/src/components/common/LicenseNotice.jsx b/frontend/src/components/common/LicenseNotice.jsx index 8d1b0696..b0fc8d94 100644 --- a/frontend/src/components/common/LicenseNotice.jsx +++ b/frontend/src/components/common/LicenseNotice.jsx @@ -21,17 +21,23 @@ function LicenseNotice(props) { return ( <> - Ce contenu est sous license   - {props.variant}. Plus d'informations à ce propos sont disponibles  + Ce contenu est sous license  + {props.variant}.
+ Plus d'informations à ce propos sont disponibles  ici.
-
+ {props.spacer &&
} ); } LicenseNotice.propTypes = { variant: PropTypes.oneOf(["REX-DRI—PRIVATE", "REX-DRI—BY"]).isRequired, + spacer: PropTypes.bool, +}; + +LicenseNotice.defaultProps = { + spacer: true, }; export default LicenseNotice; -- GitLab From 7c003df366f0cd28f372128b9f07b02b5deceefe Mon Sep 17 00:00:00 2001 From: Imane Date: Sat, 6 Jun 2020 16:37:31 +0200 Subject: [PATCH 3/4] refacto(LastVisitedUniversity): improve style with sticky position Closes #149 --- frontend/src/components/app/LastVisitedUniversity.jsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/app/LastVisitedUniversity.jsx b/frontend/src/components/app/LastVisitedUniversity.jsx index 38e16741..998db69a 100644 --- a/frontend/src/components/app/LastVisitedUniversity.jsx +++ b/frontend/src/components/app/LastVisitedUniversity.jsx @@ -5,6 +5,7 @@ import InputLabel from "@material-ui/core/InputLabel"; import FormControl from "@material-ui/core/FormControl"; import Select from "@material-ui/core/Select"; import MenuItem from "@material-ui/core/MenuItem"; +import Box from "@material-ui/core/Box"; import PropTypes from "prop-types"; import { withRouter } from "react-router-dom"; import APP_ROUTES from "../../config/appRoutes"; @@ -35,7 +36,6 @@ function LastVisitedUniversity({ location, lastVisitedUniversities }) { const classes = useStyles(); if ( - location.pathname === APP_ROUTES.base || location.pathname === APP_ROUTES.themeSettings || location.pathname === APP_ROUTES.myExchanges || location.pathname === APP_ROUTES.editPreviousExchangeWithParams || @@ -55,9 +55,9 @@ function LastVisitedUniversity({ location, lastVisitedUniversities }) { }; return ( -
- - + + + Dernières universités visitées