Skip to content

Commit

Permalink
tweak(triptych): Do not render slots outside the viewport when using …
Browse files Browse the repository at this point in the history
…the 3-slot split layout
  • Loading branch information
jzimbel-mbta committed Sep 7, 2023
1 parent 2862d86 commit e854b39
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 32 deletions.
4 changes: 2 additions & 2 deletions assets/src/apps/v2/triptych.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import NoData from "Components/v2/triptych/no_data";

import Placeholder from "Components/v2/placeholder";
import TrainCrowding from "Components/v2/train_crowding";
import OutfrontEvergreenContent from "Components/v2/outfront_evergreen_content";
import TriptychEvergreenContent from "Components/v2/triptych/evergreen_content";

const TYPE_TO_COMPONENT = {
// Layouts
Expand All @@ -38,7 +38,7 @@ const TYPE_TO_COMPONENT = {
page_load_no_data: PageLoadNoData,
no_data: NoData,
train_crowding: TrainCrowding,
evergreen_content: OutfrontEvergreenContent,
evergreen_content: TriptychEvergreenContent,
placeholder: Placeholder,
};

Expand Down
27 changes: 0 additions & 27 deletions assets/src/components/v2/outfront_evergreen_content.tsx

This file was deleted.

51 changes: 51 additions & 0 deletions assets/src/components/v2/triptych/evergreen_content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { ComponentType } from "react";

import EvergreenContent from "../evergreen_content";
import useIsOnScreen from "Hooks/v2/use_is_on_screen";
import { imagePath } from "Util/util";
import { TRIPTYCH_VERSION } from "./version";
import { usePlayerName } from "Hooks/outfront";
import { TriptychPane, getTriptychPane } from "Util/outfront";

const isInViewport = (thisComponentsPane: TriptychPane) => {
const triptychPane = getTriptychPane();
if (triptychPane == null) {
// Viewport is not limited/shifted, we're showing all 3 in a browser tab.
return true;
} else {
return thisComponentsPane == triptychPane;
}
};

/**
* Differences from standard evergreen content component:
* - allows showing identifiers (version, player name) over content
* - does not render content outside the viewport at all, besides identifiers, to save on work
*/
const TriptychEvergreenContent: ComponentType<{
asset_url: string;
show_identifiers: boolean;
triptychPane: TriptychPane;
}> = ({
asset_url: assetUrl,
show_identifiers: showIdentifiers,
triptychPane,
}) => {
const dupReadyUrl = imagePath(assetUrl);
const isPlaying = useIsOnScreen();
const playerName = usePlayerName();
let identifiers = `${TRIPTYCH_VERSION} ${playerName ? playerName : ""}`;

return (
<>
{isInViewport(triptychPane) && (
<EvergreenContent asset_url={dupReadyUrl} isPlaying={isPlaying} />
)}
{showIdentifiers && (
<div className="evergreen-content__identifiers">{identifiers}</div>
)}
</>
);
};

export default TriptychEvergreenContent;
6 changes: 3 additions & 3 deletions assets/src/components/v2/triptych/triptych_three_pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ const TriptychThreePane: React.ComponentType<Props> = ({
return (
<>
<div className="left-pane">
<Widget data={leftPane} />
<Widget data={{ ...leftPane, triptychPane: "left" }} />
</div>
<div className="middle-pane">
<Widget data={middlePane} />
<Widget data={{ ...middlePane, triptychPane: "middle" }} />
</div>
<div className="right-pane">
<Widget data={rightPane} />
<Widget data={{ ...rightPane, triptychPane: "right" }} />
</div>
</>
);
Expand Down

0 comments on commit e854b39

Please sign in to comment.