Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #686

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/pages/components/Navbar/SubMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,39 @@ const SubMenu = ({ isVisible, transparent }) => {
useEffect(() => {
changeLanguage(language);
}, [language]);
// Check if the viewport matches a mobile screen width
const mediaQuery = window.matchMedia('(max-width: 767px)');
const handleMediaQueryChange = (event) => {
setIsMobile(event.matches);
};

const [isMobile, setIsMobile] = useState(false);

useEffect(() => {
const mediaQuery = window.matchMedia('(max-width: 767px)');
const handleMediaQueryChange = (event) => {
setIsMobile(event.matches);
};

// Initial check
handleMediaQueryChange(mediaQuery);

// Listen for changes in viewport width
mediaQuery.addEventListener('change', handleMediaQueryChange);

// Clean up the event listener
return () => {
mediaQuery.removeEventListener('change', handleMediaQueryChange);
};
}, []); // Empty dependency array to run the effect only once
Comment on lines +33 to +57
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of this is necessary since you can just use responsive TailwindCSS classnames

Suggested change
// Check if the viewport matches a mobile screen width
const mediaQuery = window.matchMedia('(max-width: 767px)');
const handleMediaQueryChange = (event) => {
setIsMobile(event.matches);
};
const [isMobile, setIsMobile] = useState(false);
useEffect(() => {
const mediaQuery = window.matchMedia('(max-width: 767px)');
const handleMediaQueryChange = (event) => {
setIsMobile(event.matches);
};
// Initial check
handleMediaQueryChange(mediaQuery);
// Listen for changes in viewport width
mediaQuery.addEventListener('change', handleMediaQueryChange);
// Clean up the event listener
return () => {
mediaQuery.removeEventListener('change', handleMediaQueryChange);
};
}, []); // Empty dependency array to run the effect only once

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PeaceOloruntoba please make this change - we don't need this extra code


return (
<ul
className={`navbar ${transparent ? 'transparent-navbar' : ''}
${isVisible ? 'visible opacity-1' : 'hidden opacity-0'}
${isVisible ? '' : 'pointer-events-none'}
space-y-5 lg:space-y-0 lg:space-x-5 transition-all duration-100`}
space-y-5 lg:space-y-0 lg:space-x-5 transition-all duration-100
${isMobile ? 'text-red-500' : ''}`}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of creating a new isMobile variable, you can rely on the TailwindCSS responsive classname paradigm to assign the text color based on the device size

Suggested change
${isMobile ? 'text-red-500' : ''}`}
text-red-500 md:text-gray // text-gray should be the default text color

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PeaceOloruntoba bumping this comment

>
<li className="transition-element">
<button
Expand Down