Skip to content

Commit 0effe6d

Browse files
committed
Added helpful comments
1 parent 3e2c074 commit 0effe6d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/pages/_app.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Head from 'next/head';
22
import { AppProps } from 'next/app';
33
import Link from 'next/link';
44
import { useRouter } from 'next/router';
5-
import { useRef, useEffect} from 'react';
5+
import { useRef, useEffect } from 'react';
66

77
import './styles.css';
88
import styles from './MainLayout.module.css';
@@ -27,11 +27,16 @@ const MainLayout: React.FunctionComponent<AppProps> = ({
2727

2828
useEffect(() => {
2929
const resizeListener = () => {
30+
// Whenever the window expands to greater than 768 pixels,
31+
// set the panelContents to their maximum height.
3032
if (window.innerWidth > 768) {
3133
prevWindowWidth.current = window.innerWidth;
3234
panelContentsRef.current.style.maxHeight =
3335
panelContentsRef.current.scrollHeight + 'px';
3436
}
37+
// Else when the window resizes to less than 768 pixels
38+
// and we haven't already gone under 768 pixels on the previous resize,
39+
// then set the height of panelContents to 0.
3540
if (window.innerWidth <= 768 && prevWindowWidth.current > 768) {
3641
panelContentsRef.current.style.maxHeight = '0px';
3742
}
@@ -43,6 +48,7 @@ const MainLayout: React.FunctionComponent<AppProps> = ({
4348
};
4449
}, []);
4550

51+
// Style .panelContents when clicking the expand icon.
4652
const stylePanelOnExpand = () => {
4753
if (panelContentsRef.current) {
4854
if (panelContentsRef.current.style.maxHeight === '0px') {
@@ -58,7 +64,10 @@ const MainLayout: React.FunctionComponent<AppProps> = ({
5864
}
5965
};
6066

67+
//Style .panelContents when clicking on a link.
6168
const stylePanelOnLink = () => {
69+
// Only hide the panelContents when our window size is less than 768 pixels.
70+
// Otherwise maintain the current layout of panelContents.
6271
if (window.innerWidth <= 768) {
6372
panelContentsRef.current.style.maxHeight = '0px';
6473
panelContentsRef.current.style.overflow = 'hidden';

0 commit comments

Comments
 (0)