Skip to content
Snippets Groups Projects
Commit 3acf0e28 authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

chore(ui): avoid useless dispatch

parent 3a46b64f
No related branches found
No related tags found
2 merge requests!1169chore(ui): avoid useless dispatch,!11623.0 Release
...@@ -21,11 +21,11 @@ const Content = ({ children }: { children: React.ReactNode }) => { ...@@ -21,11 +21,11 @@ const Content = ({ children }: { children: React.ReactNode }) => {
useEffect(() => { useEffect(() => {
function handleResize() { function handleResize() {
if (innerWidth <= 768) { if (innerWidth <= 768 && screenType !== ScreenType.MOBILE) {
dispatch(changeScreenType(ScreenType.MOBILE)) dispatch(changeScreenType(ScreenType.MOBILE))
} else if (innerWidth <= 1024) { } else if (innerWidth <= 1024 && screenType !== ScreenType.TABLET) {
dispatch(changeScreenType(ScreenType.TABLET)) dispatch(changeScreenType(ScreenType.TABLET))
} else { } else if (innerWidth > 1024 && screenType !== ScreenType.DESKTOP) {
dispatch(changeScreenType(ScreenType.DESKTOP)) dispatch(changeScreenType(ScreenType.DESKTOP))
} }
} }
...@@ -34,7 +34,7 @@ const Content = ({ children }: { children: React.ReactNode }) => { ...@@ -34,7 +34,7 @@ const Content = ({ children }: { children: React.ReactNode }) => {
return () => { return () => {
window.removeEventListener('resize', handleResize) window.removeEventListener('resize', handleResize)
} }
}, [dispatch]) }, [dispatch, screenType])
return ( return (
<> <>
......
...@@ -68,9 +68,8 @@ const CozyBar = ({ ...@@ -68,9 +68,8 @@ const CozyBar = ({
</BarRight> </BarRight>
</> </>
) )
} else {
return null
} }
return null
} }
export default CozyBar export default CozyBar
...@@ -31,7 +31,9 @@ const Header = ({ ...@@ -31,7 +31,9 @@ const Header = ({
const navigate = useNavigate() const navigate = useNavigate()
const header = useRef<HTMLDivElement>(null) const header = useRef<HTMLDivElement>(null)
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const { screenType } = useAppSelector(state => state.ecolyo.global) const { screenType, headerHeight } = useAppSelector(
state => state.ecolyo.global
)
const cozyBarHeight = 48 const cozyBarHeight = 48
const handleClickBack = useCallback(() => { const handleClickBack = useCallback(() => {
...@@ -47,10 +49,12 @@ const Header = ({ ...@@ -47,10 +49,12 @@ const Header = ({
} }
useEffect(() => { useEffect(() => {
const headerHeight = header.current?.clientHeight || 0 const refHeight = header.current?.clientHeight || 0
const adjustment = screenType === ScreenType.MOBILE ? cozyBarHeight : 0 const adjustment = screenType === ScreenType.MOBILE ? cozyBarHeight : 0
dispatch(setHeaderHeight(headerHeight - adjustment)) const targetHeight = refHeight - adjustment
}, [screenType, children, dispatch]) if (targetHeight === headerHeight) return
dispatch(setHeaderHeight(targetHeight))
}, [screenType, children, dispatch, headerHeight])
return ( return (
<header ref={header}> <header ref={header}>
......
export enum ScreenType { export enum ScreenType {
MOBILE = 0, MOBILE = 'MOBILE',
TABLET = 1, TABLET = 'TABLET',
DESKTOP = 2, DESKTOP = 'DESKTOP',
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment