-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
195 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
assets/src/components/v2/pre_fare/simulation_screen_container.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import React, { ComponentType, useContext } from "react"; | ||
import { | ||
LastFetchContext, | ||
ResponseMapperContext, | ||
} from "Components/v2/screen_container"; | ||
import Widget, { WidgetData } from "Components/v2/widget"; | ||
import { | ||
ApiResponse, | ||
useSimulationApiResponse, | ||
} from "Hooks/v2/use_api_response"; | ||
import WidgetTreeErrorBoundary from "Components/v2/widget_tree_error_boundary"; | ||
|
||
interface SimulationScreenLayoutProps { | ||
apiResponse: ApiResponse; | ||
} | ||
|
||
const SimulationScreenLayout: ComponentType<SimulationScreenLayoutProps> = ({ | ||
apiResponse, | ||
}) => { | ||
const responseMapper = useContext(ResponseMapperContext); | ||
const data = responseMapper(apiResponse); | ||
const { fullPage, flexZone } = data; | ||
let leftScreenPages: WidgetData[] = []; | ||
let rightScreenPages: WidgetData[] = []; | ||
if (flexZone) { | ||
leftScreenPages = flexZone.filter( | ||
(widget: WidgetData) => widget.type === "body_left_flex" | ||
); | ||
rightScreenPages = flexZone.filter( | ||
(widget: WidgetData) => !leftScreenPages.includes(widget) | ||
); | ||
} | ||
|
||
return ( | ||
<div className="simulation-screen-centering-container"> | ||
<div className="simulation-screen-scrolling-container"> | ||
{apiResponse && ( | ||
<div className="simulation__full-page"> | ||
<div className="simulation__title">Live view</div> | ||
<WidgetTreeErrorBoundary> | ||
<Widget data={fullPage} /> | ||
</WidgetTreeErrorBoundary> | ||
</div> | ||
)} | ||
{flexZone && <div className="divider"></div>} | ||
{leftScreenPages && leftScreenPages.length > 0 && ( | ||
<div className="simulation__left-screen"> | ||
<div className="simulation__title"> | ||
Left panel ({leftScreenPages.length}) | ||
</div> | ||
<div className="simulation__left-screen-widget-container"> | ||
{leftScreenPages.map( | ||
(flexZonePage: WidgetData, index: number) => { | ||
return ( | ||
<div | ||
key={`page${index}`} | ||
className="simulation__left-screen-widget" | ||
> | ||
<Widget data={flexZonePage} /> | ||
</div> | ||
); | ||
} | ||
)} | ||
</div> | ||
</div> | ||
)} | ||
{rightScreenPages && rightScreenPages.length > 0 && ( | ||
<div className="simulation__right-screen"> | ||
<div className="simulation__title"> | ||
Flex zone ({rightScreenPages.length}) | ||
</div> | ||
<div className="simulation__right-screen-widget-container"> | ||
{rightScreenPages.map( | ||
(flexZonePage: WidgetData, index: number) => { | ||
return ( | ||
<div | ||
key={`page${index}`} | ||
className="simulation__right-screen-widget" | ||
> | ||
<Widget data={flexZonePage} /> | ||
</div> | ||
); | ||
} | ||
)} | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const SimulationScreenContainer = ({ | ||
id, | ||
}: { | ||
id: string; | ||
opts?: { [key: string]: any }; | ||
}) => { | ||
const { apiResponse, lastSuccess } = useSimulationApiResponse({ id }); | ||
|
||
return ( | ||
<LastFetchContext.Provider value={lastSuccess}> | ||
<SimulationScreenLayout apiResponse={apiResponse} /> | ||
</LastFetchContext.Provider> | ||
); | ||
}; | ||
|
||
export default SimulationScreenContainer; |
10 changes: 10 additions & 0 deletions
10
assets/src/components/v2/pre_fare/simulation_screen_page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from "react"; | ||
import { useParams } from "react-router-dom"; | ||
import SimulationScreenContainer from "Components/v2/pre_fare/simulation_screen_container"; | ||
|
||
const SimulationScreenPage = ({ opts = {} }) => { | ||
const { id } = useParams() as { id: string }; | ||
return <SimulationScreenContainer id={id} opts={opts} />; | ||
}; | ||
|
||
export default SimulationScreenPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters