Skip to content

Commit

Permalink
Lazily load the burger component
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrf committed Jan 24, 2024
1 parent f700a71 commit 61b672d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 30 deletions.
4 changes: 2 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { insert, render, style } from 'solid-js/web';
import { initializeMap } from './map/Map';
import { fetchForecastRuns } from './data/ForecastMetadata';
import {Domain, gfsModel, wrfModel} from './State';
import { Burger } from './Burger';
import { BurgerButton } from './BurgerButton';
import { css } from "./css-hooks";
import {LayerKeys} from "./LayerKeys";
import { HelpButton } from './help/HelpButton';
Expand Down Expand Up @@ -74,7 +74,7 @@ export const start = (containerElement: HTMLElement): void => {
return <>
<style>{ css }</style>
<span style={{ position: 'absolute', top: 0, left: 0, 'z-index': 200 /* must be above the “period selector” */ }}>
<Burger domain={props.domain} />
<BurgerButton domain={props.domain} />
</span>
<PeriodSelectors domain={props.domain} locationClicks={mapHooks.locationClicks} />
<LayerKeys domain={props.domain} />
Expand Down
34 changes: 6 additions & 28 deletions frontend/src/Burger.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {createSignal, JSX, Show} from "solid-js";
import {createSignal, JSX} from "solid-js";
import { Domain } from "./State";
import {
burgerBorderTopStyle,
burgerOptionStyle,
closeButton,
closeButtonSize,
periodSelectorHeight
} from "./styles/Styles";
import { surfaceOverMap } from "./styles/Styles";
import { Settings } from "./Settings";
Expand All @@ -21,32 +20,11 @@ import hooks from "./css-hooks";
*/
export const Burger = (props: {
domain: Domain
close: () => void
}): JSX.Element => {

const [expanded, setExpanded] = createSignal(false);
const [areSettingsVisible, makeSettingsVisible] = createSignal(false);

const menuBtn =
<div
style={{
...surfaceOverMap,
width: `${periodSelectorHeight}px`,
height: `${periodSelectorHeight}px`,
cursor: 'pointer',
'user-select': 'none',
padding: '3px',
border: 'thin solid darkGray',
'box-sizing': 'border-box',
'background-color': '#009688',
color: '#fff',
'text-align': 'center',
'font-weight': 'bold',
'font-size': `${periodSelectorHeight / 2}px`,
'line-height': `1.5`
}}
onClick={() => { setExpanded(!expanded()); }}
></div> as HTMLElement;

const staticEntries = [
['About', '/'],
['Support Soaringmeteo', '/don.html'],
Expand Down Expand Up @@ -89,7 +67,7 @@ export const Burger = (props: {
Soaringmeteo
</div>
<div
onClick={ () => setExpanded(false) }
onClick={ () => props.close() }
style={hooks({
...closeButton,
position: 'absolute',
Expand Down Expand Up @@ -117,14 +95,14 @@ export const Burger = (props: {
}
</div>;

return <Show when={ expanded() } fallback={ menuBtn }>
<OverlayContainer handleClick={ () => setExpanded(false) }>
return <>
<OverlayContainer handleClick={ () => props.close() }>
{options}
</OverlayContainer>
<Settings
isVisible={ areSettingsVisible() }
close={ () => makeSettingsVisible(false) }
domain={ props.domain }
/>
</Show>
</>
};
44 changes: 44 additions & 0 deletions frontend/src/BurgerButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {createSignal, JSX, Show, lazy} from "solid-js";
import { Domain } from "./State";
import { periodSelectorHeight } from "./styles/Styles";
import { surfaceOverMap } from "./styles/Styles";

const Burger = lazy(() => import('./Burger').then(module => ({ default: module.Burger })));

/**
* Burger menu with links to the other parts of the website.
*
* The menu is hidden when a detailed view (meteogram or sounding)
* is displayed.
*/
export const BurgerButton = (props: {
domain: Domain
}): JSX.Element => {

const [expanded, setExpanded] = createSignal(false);

const menuBtn =
<div
style={{
...surfaceOverMap,
width: `${periodSelectorHeight}px`,
height: `${periodSelectorHeight}px`,
cursor: 'pointer',
'user-select': 'none',
padding: '3px',
border: 'thin solid darkGray',
'box-sizing': 'border-box',
'background-color': '#009688',
color: '#fff',
'text-align': 'center',
'font-weight': 'bold',
'font-size': `${periodSelectorHeight / 2}px`,
'line-height': `1.5`
}}
onClick={() => { setExpanded(!expanded()); }}
></div> as HTMLElement;

return <Show when={ expanded() } fallback={ menuBtn }>
<Burger domain={ props.domain } close={ () => setExpanded(false) } />
</Show>
};

0 comments on commit 61b672d

Please sign in to comment.