Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
thegitofdaniel committed Apr 28, 2024
1 parent 6db8c63 commit b9230db
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 41 deletions.
76 changes: 38 additions & 38 deletions src/components/MenuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@ import React, { useState, useEffect } from 'react';
import SectionsList from './SectionsList';

function MenuButton() {
const [isOpen, setIsOpen] = useState(false);
const [displayStyle, setDisplayStyle] = useState(determineDisplayStyle(isOpen));

// Function to determine the display style
function determineDisplayStyle(isOpen) {
if (window.innerWidth <= 650) {
return isOpen ? "inline-block" : "none";
} else {
return "flex";
}
}

// Update display style on window resize or when isOpen changes
useEffect(() => {
function handleResize() {
if (window.innerWidth > 650) {
setIsOpen(false);
}
setDisplayStyle(determineDisplayStyle(isOpen));
const [isOpen, setIsOpen] = useState(false);
const [displayStyle, setDisplayStyle] = useState(determineDisplayStyle(isOpen));

// Function to determine the display style
function determineDisplayStyle(isOpen) {
if (window.innerWidth <= 650) {
return isOpen ? 'inline-block' : 'none';
} else {
return 'flex';
}
}

window.addEventListener('resize', handleResize);
// Initial setting of the display style
handleResize();

// Cleanup function to remove event listener
return () => window.removeEventListener('resize', handleResize);
}, [isOpen]); // Effect depends on isOpen

const id = isOpen ? "close-btn" : "menu-btn";
const icon = isOpen ? "close" : "menu";

return (
<>
<SectionsList displayStyle={displayStyle} />
<button onClick={() => setIsOpen(!isOpen)} id={id}>
<span className="material-symbols-sharp">{icon}</span>
</button>
</>
);
// Update display style on window resize or when isOpen changes
useEffect(() => {
function handleResize() {
if (window.innerWidth > 650) {
setIsOpen(false);
}
setDisplayStyle(determineDisplayStyle(isOpen));
}

window.addEventListener('resize', handleResize);
// Initial setting of the display style
handleResize();

// Cleanup function to remove event listener
return () => window.removeEventListener('resize', handleResize);
}, [isOpen]); // Effect depends on isOpen

const id = isOpen ? 'close-btn' : 'menu-btn';
const icon = isOpen ? 'close' : 'menu';

return (
<>
<SectionsList displayStyle={displayStyle} />
<button onClick={() => setIsOpen(!isOpen)} id={id}>
<span className="material-symbols-sharp">{icon}</span>
</button>
</>
);
}

export default MenuButton;
2 changes: 1 addition & 1 deletion src/components/SectionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ function SectionsList({ displayStyle }) {
);
}

export default SectionsList;
export default SectionsList;
2 changes: 1 addition & 1 deletion src/hooks/useScrollShadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ const useScrollShadow = (selector, className) => {
}, [selector, className]);
};

export default useScrollShadow;
export default useScrollShadow;
1 change: 0 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ closeBtn.addEventListener('click', () => {
menuBtn.style.display = 'inline-block';
closeBtn.style.display = 'none';
});

0 comments on commit b9230db

Please sign in to comment.