Skip to content

Commit

Permalink
Merge pull request #586 from MTES-MCT/fix/scroll
Browse files Browse the repository at this point in the history
Fix/scroll
  • Loading branch information
tristan-gueguen authored Nov 5, 2024
2 parents 486e760 + 443756e commit 6f71047
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 50 deletions.
4 changes: 4 additions & 0 deletions common/assets/styles/root.scss
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,8 @@ video:not([href])[controls] {

.MuiChip-filled.MuiChip-colorDefault {
background-color: var(--background-action-low-blue-france)
}

main {
scroll-margin-top: 75px;
}
24 changes: 0 additions & 24 deletions common/utils/scroll.js

This file was deleted.

25 changes: 25 additions & 0 deletions web/common/hooks/useScroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useEffect } from "react";
import { useLocation } from "react-router-dom";

function useScroll() {
const { hash, pathname, search } = useLocation();

useEffect(() => {
if (hash) {
const element = document.querySelector(hash);
if (element) {
element.scrollIntoView({ behavior: "smooth" });
}
return;
}
if (pathname === "/resources/regulations" && search !== "") {
return;
}
const mainElements = document.getElementsByTagName("main");
if (mainElements && mainElements[0]) {
mainElements[0].scrollIntoView({ behavior: "smooth", block: "start" });
}
}, [hash, pathname, search]);
}

export default useScroll;
17 changes: 0 additions & 17 deletions web/common/hooks/useScrollHash.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { LinkButton } from "../../../common/LinkButton";
import { CONTROLLER_ROUTE_PREFIX } from "../../../common/routes";

export const BackButton = ({ label, route }) => (
export const ControllerBackButton = ({ label, route }) => (
<LinkButton
to={`${CONTROLLER_ROUTE_PREFIX}${route}`}
priority="tertiary no outline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Typography from "@mui/material/Typography";
import { Header } from "../../../common/Header";
import { usePageTitle } from "../../../common/UsePageTitle";
import Notice from "../../../common/Notice";
import { BackButton } from "./BackButton";
import { Main } from "../../../common/semantics/Main";
import { ControllerBackButton } from "./ControllerBackButton";

const useStyles = makeStyles(theme => ({
container: {
Expand Down Expand Up @@ -38,7 +38,7 @@ export function ControllerQRCodeNotRecognized() {
className={`${classes.container} ${classes.whiteSection}`}
maxWidth="xl"
>
<BackButton label="Scannez un QR Code" route="/scan" />
<ControllerBackButton label="Scannez un QR Code" route="/scan" />
<h3 className={classes.title}>QR Code non reconnu</h3>
<Typography>
Nous n'avons pas pu vérifier la validité de ce QR Code. Il se peut que
Expand Down
4 changes: 2 additions & 2 deletions web/controller/components/scanQRCode/ControllerScanQRCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CONTROL_TYPES } from "../../utils/useReadControlData";
import { usePageTitle } from "../../../common/UsePageTitle";
import Notice from "../../../common/Notice";
import { Main } from "../../../common/semantics/Main";
import { BackButton } from "./BackButton";
import { ControllerBackButton } from "./ControllerBackButton";

const useStyles = makeStyles(theme => ({
container: {
Expand Down Expand Up @@ -132,7 +132,7 @@ export function ControllerScanQRCode() {
className={`${classes.container} ${classes.whiteSection}`}
maxWidth="xl"
>
<BackButton label="Accueil" route="/home" />
<ControllerBackButton label="Accueil" route="/home" />
<h3 className={classes.titleScan}>Scannez un QR Code Mobilic</h3>
<Typography>
Afin d'accéder à l'historique de 28 jours du salarié, positionnez son
Expand Down
6 changes: 2 additions & 4 deletions web/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
getFallbackRoute,
isAccessible
} from "./common/routes";
import { ScrollToTop } from "common/utils/scroll";
import { SnackbarProvider, useSnackbarAlerts } from "./common/Snackbar";
import { EnvironmentHeader } from "./common/EnvironmentHeader";
import { LiveChat } from "./common/LiveChat";
Expand Down Expand Up @@ -58,7 +57,7 @@ import UpdatePasswordModal from "./pwa/components/UpdatePassword";
import AcceptCguModal from "./pwa/modals/AcceptCguModal";
import RejectedCguModal from "./pwa/modals/RejectedCguModals";
import merge from "lodash/merge";
import useScrollToHash from "./common/hooks/useScrollHash";
import useScroll from "./common/hooks/useScroll";

const matomo = createInstance({
urlBase: "https://stats.beta.gouv.fr",
Expand Down Expand Up @@ -103,7 +102,6 @@ export default function Root() {
<LoadingScreenContextProvider>
<ModalProvider modalDict={MODAL_DICT}>
<RegulationDrawerContextProvider>
<ScrollToTop />
<_Root />
</RegulationDrawerContextProvider>
</ModalProvider>
Expand All @@ -125,7 +123,7 @@ function _Root() {
const store = useStoreSyncedWithLocalStorage();
const withLoadingScreen = useLoadingScreen();
const alerts = useSnackbarAlerts();
useScrollToHash();
useScroll();

const userId = store.userId();
const controllerId = store.controllerId();
Expand Down

0 comments on commit 6f71047

Please sign in to comment.