Skip to content

Commit

Permalink
Rework window sizes to resolve squished pages
Browse files Browse the repository at this point in the history
Rework window size detection to prevent desktop pages from loading in
a "squished" state before adjusting, at the expense of mobile pages
briefly showing the table of contents before it is hidden.  Closes #240.

Fix several cases of keys not being present in loops.
Updated browserslist DB.
  • Loading branch information
brianlove committed Jun 21, 2024
1 parent 9da565f commit 1eaba90
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
12 changes: 6 additions & 6 deletions web/gui-v2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions web/gui-v2/src/components/AddRemoveColumnDialog.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { Fragment, useEffect, useState } from 'react';
import { css } from '@emotion/react';
import {
Checkbox,
Expand Down Expand Up @@ -145,33 +145,35 @@ const AddRemoveColumnDialog = ({
<div css={styles.columnDialogContents}>
<div css={styles.columnDialogList}>
{
COLUMN_GROUPINGS.map((colGroup) => (
<>
COLUMN_GROUPINGS.map((colGroup, ix) => (
<Fragment key={ix}>
<h3>{colGroup.heading}</h3>
{colGroup.entries &&
colGroup.entries.map((entry) => (
colGroup.entries.map((entry, ix) => (
<ColumnSelectionListEntry
colDef={entry}
columnsInternal={columnsInternal}
key={ix}
setColumnsInternal={setColumnsInternal}
/>
))
}
{colGroup.subgroups &&
colGroup.subgroups.map((subgroup) => (
<>
colGroup.subgroups.map((subgroup, ix) => (
<Fragment key={ix}>
<h4>{subgroup.heading}</h4>
{subgroup.entries.map((entry) => (
{subgroup.entries.map((entry, ix) => (
<ColumnSelectionListEntry
colDef={entry}
columnsInternal={columnsInternal}
key={ix}
setColumnsInternal={setColumnsInternal}
/>
))}
</>
</Fragment>
))
}
</>
</Fragment>
))
}
</div>
Expand Down
12 changes: 10 additions & 2 deletions web/gui-v2/src/util/useWindowSize.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { useEffect, useState } from 'react';

const DEFAULT_WIDTH = 1100;

/**
* Return the current width of the browser viewport.
*
* @returns {number} The current width of the viewport (in px). This width
* updates as the user resizes the viewport.
*/
export const useWindowSize = () => {
const [windowSize, setWindowSize] = useState(800);
const [windowSize, setWindowSize] = useState(() => {
if ( typeof window !== "undefined" ) {
return window.innerWidth;
} else {
return DEFAULT_WIDTH;
}
});

useEffect(() => {
const handleResize = () => setWindowSize(window?.innerWidth ?? 800);
const handleResize = () => setWindowSize(window?.innerWidth ?? DEFAULT_WIDTH);
if ( typeof window !== "undefined" ) {
window.addEventListener("resize", handleResize);
}
Expand Down

0 comments on commit 1eaba90

Please sign in to comment.