From df5af83c404268e31ee2f245b543ae310122dc16 Mon Sep 17 00:00:00 2001
From: Bastien Dumont <bdumont@grandlyon.com>
Date: Thu, 2 May 2024 16:43:05 +0200
Subject: [PATCH] Revert "chore(ui): avoid useless dispatch"

This reverts commit 3acf0e28622aee28a7105af3f7f206772c02db9b.
---
 src/components/Content/Content.tsx |  8 ++++----
 src/components/Header/CozyBar.tsx  |  3 ++-
 src/components/Header/Header.tsx   | 12 ++++--------
 src/enums/screen.enum.ts           |  6 +++---
 4 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/src/components/Content/Content.tsx b/src/components/Content/Content.tsx
index 32fa1dbc0..f30e26160 100644
--- a/src/components/Content/Content.tsx
+++ b/src/components/Content/Content.tsx
@@ -21,11 +21,11 @@ const Content = ({ children }: { children: React.ReactNode }) => {
 
   useEffect(() => {
     function handleResize() {
-      if (innerWidth <= 768 && screenType !== ScreenType.MOBILE) {
+      if (innerWidth <= 768) {
         dispatch(changeScreenType(ScreenType.MOBILE))
-      } else if (innerWidth <= 1024 && screenType !== ScreenType.TABLET) {
+      } else if (innerWidth <= 1024) {
         dispatch(changeScreenType(ScreenType.TABLET))
-      } else if (innerWidth > 1024 && screenType !== ScreenType.DESKTOP) {
+      } else {
         dispatch(changeScreenType(ScreenType.DESKTOP))
       }
     }
@@ -34,7 +34,7 @@ const Content = ({ children }: { children: React.ReactNode }) => {
     return () => {
       window.removeEventListener('resize', handleResize)
     }
-  }, [dispatch, screenType])
+  }, [dispatch])
 
   return (
     <>
diff --git a/src/components/Header/CozyBar.tsx b/src/components/Header/CozyBar.tsx
index 99bd3d50b..d0cccb600 100644
--- a/src/components/Header/CozyBar.tsx
+++ b/src/components/Header/CozyBar.tsx
@@ -68,8 +68,9 @@ const CozyBar = ({
         </BarRight>
       </>
     )
+  } else {
+    return null
   }
-  return null
 }
 
 export default CozyBar
diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx
index 7b838bdb4..b200f36a7 100644
--- a/src/components/Header/Header.tsx
+++ b/src/components/Header/Header.tsx
@@ -31,9 +31,7 @@ const Header = ({
   const navigate = useNavigate()
   const header = useRef<HTMLDivElement>(null)
   const dispatch = useAppDispatch()
-  const { screenType, headerHeight } = useAppSelector(
-    state => state.ecolyo.global
-  )
+  const { screenType } = useAppSelector(state => state.ecolyo.global)
   const cozyBarHeight = 48
 
   const handleClickBack = useCallback(() => {
@@ -49,12 +47,10 @@ const Header = ({
   }
 
   useEffect(() => {
-    const refHeight = header.current?.clientHeight || 0
+    const headerHeight = header.current?.clientHeight || 0
     const adjustment = screenType === ScreenType.MOBILE ? cozyBarHeight : 0
-    const targetHeight = refHeight - adjustment
-    if (targetHeight === headerHeight) return
-    dispatch(setHeaderHeight(targetHeight))
-  }, [screenType, children, dispatch, headerHeight])
+    dispatch(setHeaderHeight(headerHeight - adjustment))
+  }, [screenType, children, dispatch])
 
   return (
     <header ref={header}>
diff --git a/src/enums/screen.enum.ts b/src/enums/screen.enum.ts
index c48678c42..cf2faa302 100644
--- a/src/enums/screen.enum.ts
+++ b/src/enums/screen.enum.ts
@@ -1,5 +1,5 @@
 export enum ScreenType {
-  MOBILE = 'MOBILE',
-  TABLET = 'TABLET',
-  DESKTOP = 'DESKTOP',
+  MOBILE = 0,
+  TABLET = 1,
+  DESKTOP = 2,
 }
-- 
GitLab