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

Development to Main, week 40 #114

Merged
merged 27 commits into from
Oct 16, 2023
Merged

Development to Main, week 40 #114

merged 27 commits into from
Oct 16, 2023

Conversation

remko48
Copy link
Member

@remko48 remko48 commented Oct 4, 2023

No description provided.

@remko48 remko48 requested a review from lencodes October 4, 2023 14:23
Copy link
Contributor

@lencodes lencodes left a comment

Choose a reason for hiding this comment

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

Looks good 👍🏼

I think we should have a quick call and think about how we want to implement these sub-item changes. Left some comments on it as well.

Comment on lines +46 to +52
const screenWidth = window.innerWidth;

React.useEffect(() => {
if (screenWidth > 992) {
setSubNavIsOpen({});
}
}, [screenWidth]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not triggering on the "right" moments. screenWidth seems to update sometimes, I think whenever the React lifecycle is triggered by some other side effect.

To accurately keep track of a screen width, we can register (and un-register when needed) a listener, like so (dummy code):

const [screenWidth, setScreenWidth] = React.useState<number | undefined>(undefined);

  React.useEffect(() => {
    const handleScreenResize = (e: TypeThis) => setScreenWidth(e.path_to_width);

    window.addEventListener("resize", handleScreenResize); // add listener

    return () => window.removeEventListener("resize", handleScreenResize) // remove listener when component is removed
  }, []) // only trigger once

@@ -26,6 +26,7 @@ export interface TopNavProps {

export const PrimaryTopNav = ({ items, mobileLogo, layoutClassName }: TopNavProps): JSX.Element => {
const [isOpen, setIsOpen] = React.useState<boolean>(false);
const [subNavIsOpen, setSubNavIsOpen] = React.useState({});
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should type this state, it's unclear what it's expecting.

Comment on lines +39 to +44
const handleSubItemMenu = (idx: number, value: boolean) => {
setSubNavIsOpen({
...subNavIsOpen,
[idx as keyof typeof subNavIsOpen]: value,
});
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a complex way to keep track of the open sub items. Previously, I think, we just let the css handle everything. Why the change?

Comment on lines +67 to +92
onClick={() =>
!subItems
? handleItemClick(handleClick)
: screenWidth > 992
? handleItemClick(handleClick)
: handleSubItemMenu(idx, !subNavIsOpen[idx as keyof typeof subNavIsOpen] ?? true)
}
className={clsx(styles.li, current && styles.current)}
key={idx}
>
<Link className={clsx(styles.link, styles.label)}>
<Link
className={clsx(
styles.link,
styles.label,
subItems && styles.mobileLink,
current && styles.currentLink,
)}
>
{icon}
{label}
{label}{" "}
{subItems && screenWidth < 992 && (
<FontAwesomeIcon
className={clsx(styles.toggleIcon, subNavIsOpen[idx as keyof typeof subNavIsOpen] && styles.isOpen)}
icon={faChevronRight}
/>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this a bit complex, see my other comment as well.

Is this because a top-level item can have a link and have sub-items?

remko48 and others added 23 commits October 11, 2023 12:02
…gination

Revert "feature/OP-57/pagination"
…gination

Revert "feature/OP-57/pagination"
…lect-WCAG

Revert "feature/XW-87/select-WCAG"
…lect-WCAG

Revert "feature/XW-87/select-WCAG"
…lect-WCAG

Revert "feature/XW-87/select-WCAG"
@remko48 remko48 merged commit 1ab61a7 into main Oct 16, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants