Skip to content

Commit

Permalink
[#91] Save current page when navigating away
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-At-Home committed Jul 17, 2020
1 parent 909061d commit e71e020
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/components/shared/HeaderBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const HeaderBar: React.FunctionComponent<Props> = ({thisPage, common}) => {
// From baseline query
function getBaseGameUrl() {
return UrlRouting.getGameUrl(
getCommonFilterParams(common) as GameFilterParams, {}
getCommonFilterParams(common) as GameFilterParams, {}
);
}
function getBaseLineupUrl() {
Expand Down Expand Up @@ -104,55 +104,63 @@ const HeaderBar: React.FunctionComponent<Props> = ({thisPage, common}) => {
<Tooltip id="lastReportTooltip">View a gallery of interesting basketball analytics charts</Tooltip>
);

/** Adds the current selection to history before navigating away */
const onNav = (e: any) => {
if (!_.isEmpty(common)) { //(do nothing if the page has just been loaded and not modified)
const key = UrlRouting.getUrl({ [UrlRouting.noSuffix]: common });
HistoryManager.addParamsToHistory(key, thisPage);
}
};

//(only render client-side - was running into cache issues of the Link href)
return (typeof window !== `undefined`) ? <Container>
<Row className="border-top">
{(thisPage != ParamPrefixes.game) ?
<Col className="text-center small">
<OverlayTrigger placement="auto" overlay={baseGameTooltip}>
<span><Link href={getBaseGameUrl()}><a>On/Off: Base</a></Link></span>
<span><Link href={getBaseGameUrl()}><div><a href="#" onClick={onNav}>On/Off: Base</a></div></Link></span>
</OverlayTrigger>
</Col> : null
}
{(thisPage != ParamPrefixes.game) ?
<Col className="text-center small">
<OverlayTrigger placement="auto" overlay={lastGameTooltip}>
<span><Link href={getLastGameUrl()}><a>On/Off: Last</a></Link></span>
<span><Link href={getLastGameUrl()}><div><a href="#" onClick={onNav}>On/Off: Last</a></div></Link></span>
</OverlayTrigger>
</Col> : null
}
{(thisPage != ParamPrefixes.lineup) ?
<Col className="text-center small">
<OverlayTrigger placement="auto" overlay={baseLineupTooltip}>
<span><Link href={getBaseLineupUrl()}><a>Lineups: Base</a></Link></span>
<span><Link href={getBaseLineupUrl()}><div><a href="#" onClick={onNav}>Lineups: Base</a></div></Link></span>
</OverlayTrigger>
</Col> : null
}
{(thisPage != ParamPrefixes.lineup) ?
<Col className="text-center small">
<OverlayTrigger placement="auto" overlay={lastLineupTooltip}>
<span><Link href={getLastLineupUrl()}><a>Lineups: Last</a></Link></span>
<span><Link href={getLastLineupUrl()}><div><a href="#" onClick={onNav}>Lineups: Last</a></div></Link></span>
</OverlayTrigger>
</Col> : null
}
{(thisPage != ParamPrefixes.report) ?
<Col className="text-center small">
<OverlayTrigger placement="auto" overlay={baseReportTooltip}>
<span><Link href={getBaseReportUrl()}><a>Report: Base</a></Link></span>
<span><Link href={getBaseReportUrl()}><div><a href="#" onClick={onNav}>Report: Base</a></div></Link></span>
</OverlayTrigger>
</Col> : null
}
{(thisPage != ParamPrefixes.report) ?
<Col className="text-center small">
<OverlayTrigger placement="auto" overlay={lastReportTooltip}>
<span><Link href={getLastReportUrl()}><a>Report: Last</a></Link></span>
<span><Link href={getLastReportUrl()}><div><a href="#" onClick={onNav}>Report: Last</a></div></Link></span>
</OverlayTrigger>
</Col> : null
}
{(thisPage != "charts") ?
<Col className="text-center small">
<OverlayTrigger placement="auto" overlay={chartTooltip}>
<span><Link href={"/Charts"}><a>Charts</a></Link></span>
<span><Link href={"/Charts"}><div><a href="#" onClick={onNav}>Charts</a></div></Link></span>
</OverlayTrigger>
</Col> : null
}
Expand Down

1 comment on commit e71e020

@vercel
Copy link

@vercel vercel bot commented on e71e020 Jul 17, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.