diff --git a/src/components/navigation/menu.tsx b/src/components/navigation/menu.tsx index a5d838d7..a4fc879b 100644 --- a/src/components/navigation/menu.tsx +++ b/src/components/navigation/menu.tsx @@ -7,9 +7,62 @@ import Link from 'next/link'; import Submenu from '@/components/navigation/submenu'; import TranslationList from '../translation/TranslationList'; import dynamicWidth from '@/lib/dynamic-width'; -import { useState, Component } from 'react'; +import React, { useState } from 'react'; import { Chiislate } from '../translation/Chiislate'; +interface MenuBarProps { + useMobileBar: boolean; + useFeaturesBeta: boolean; + isDarkHeader: boolean; + currentPath: string; + onNavigate: (route: string) => void; +} + +const MenuBar: React.FC = ({ + useMobileBar, + useFeaturesBeta, + isDarkHeader, + currentPath, + onNavigate +}) => { + return useMobileBar ? ( + + ) : ( + + ); +}; + const Menu = () => { const theme = useTheme(); const prefers = usePrefers(); @@ -30,51 +83,19 @@ const Menu = () => { document.documentElement.classList.toggle('scroll-light', theme.type === 'dark'); }; - const themeDark = () => { - if (theme.type === 'dark' && router.pathname == '/') return true; - else return false; - }; + const isDarkHeader = theme.type === 'dark' && router.pathname === '/'; + + const menuBarElement = ( + router.push(route)} + /> + ); - class MenuBar extends Component { - render() { - return useMobileBar ? ( - - ) : ( - - ); - } - } return ( <> @@ -128,6 +149,7 @@ const Menu = () => { background: rgba(0, 0, 0, 0.2) !important; -webkit-backdrop-filter: blur(2rem); padding-right: 6px !important; + } `} ); diff --git a/src/lib/dynamic-width.ts b/src/lib/dynamic-width.ts index 9ad6259a..49f2508f 100644 --- a/src/lib/dynamic-width.ts +++ b/src/lib/dynamic-width.ts @@ -4,18 +4,29 @@ * @license GPL-3.0 */ -import { useEffect } from 'react'; +import { useEffect, useRef } from 'react'; /** * An easy to use hook for dynamically changing DOM based on window size, fires on page load and resize * @param {hookCallback} callback - Callback function for hook */ const hook = (callback: (width: number) => void) => { + const savedCallback = useRef(callback); + + useEffect(() => { + savedCallback.current = callback; + }, [callback]); + useEffect(() => { - window.addEventListener('resize', () => { - callback(window.innerWidth); - }); - callback(window.innerWidth); + const handleResize = () => { + savedCallback.current(window.innerWidth); + }; + + handleResize(); + window.addEventListener('resize', handleResize); + return () => { + window.removeEventListener('resize', handleResize); + }; }, []); }; diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index e4116051..3a65c9ae 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -66,7 +66,6 @@ const App = ({ Component, pageProps }: AppProps) => { crossOrigin="anonymous" referrerPolicy="no-referrer" > - ); };