Skip to content

Commit

Permalink
Added helpful comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhhelgeson committed Jan 4, 2024
1 parent 3e2c074 commit 0effe6d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Head from 'next/head';
import { AppProps } from 'next/app';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { useRef, useEffect} from 'react';
import { useRef, useEffect } from 'react';

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

useEffect(() => {
const resizeListener = () => {
// Whenever the window expands to greater than 768 pixels,
// set the panelContents to their maximum height.
if (window.innerWidth > 768) {
prevWindowWidth.current = window.innerWidth;
panelContentsRef.current.style.maxHeight =
panelContentsRef.current.scrollHeight + 'px';
}
// Else when the window resizes to less than 768 pixels
// and we haven't already gone under 768 pixels on the previous resize,
// then set the height of panelContents to 0.
if (window.innerWidth <= 768 && prevWindowWidth.current > 768) {
panelContentsRef.current.style.maxHeight = '0px';
}
Expand All @@ -43,6 +48,7 @@ const MainLayout: React.FunctionComponent<AppProps> = ({
};
}, []);

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

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

0 comments on commit 0effe6d

Please sign in to comment.