1- import React , { useContext , useState } from "react" ;
1+ import React , { useContext } from "react" ;
22
33import Viewer from "./Viewer" ;
44import { SimulariumContext } from "../simulation/context" ;
@@ -9,47 +9,19 @@ import LabIcon from "./icons/Lab";
99import Molecules from "./icons/Molecules" ;
1010import LabView from "./LabView" ;
1111import VisibilityControl from "./shared/VisibilityControl" ;
12- import { Module , Section } from "../types" ;
12+ import { Module , ViewType } from "../types" ;
1313import { FIRST_PAGE } from "../content" ;
14- import useModule from "../hooks/useModule" ;
1514import { VIEW_SWITCH_ID } from "../constants" ;
1615
17- enum View {
18- Lab = "lab" ,
19- Simulation = "simulation" ,
20- }
21-
2216const ViewSwitch : React . FC = ( ) => {
23- const [ currentView , setCurrentView ] = useState < View > ( View . Lab ) ;
24- const [ previousModule , setPreviousModule ] = useState < Module > ( Module . A_B_AB ) ;
17+ const { viewportType, setViewportType } = useContext ( SimulariumContext ) ;
2518
26- const switchView = ( ) => {
27- setCurrentView ( ( prevView ) =>
28- prevView === View . Lab ? View . Simulation : View . Lab
29- ) ;
30- } ;
3119 const { page, isPlaying, setIsPlaying, handleTimeChange, module } =
3220 useContext ( SimulariumContext ) ;
3321
3422 const isFirstPageOfFirstModule =
3523 page === FIRST_PAGE [ module ] + 1 && module === Module . A_B_AB ;
3624
37- if ( isFirstPageOfFirstModule && currentView === View . Simulation ) {
38- setCurrentView ( View . Lab ) ;
39- }
40-
41- const { contentData } = useModule ( module ) ;
42-
43- // Show the sim view at the beginning of the module
44- if ( module !== previousModule ) {
45- setPreviousModule ( module ) ;
46- if ( contentData [ page ] . section === Section . Experiment ) {
47- if ( currentView === View . Lab ) {
48- setCurrentView ( View . Simulation ) ;
49- }
50- }
51- }
52-
5325 let buttonStyle : React . CSSProperties = {
5426 top : 16 ,
5527 right : 16 ,
@@ -73,22 +45,23 @@ const ViewSwitch: React.FC = () => {
7345 < VisibilityControl notInBonusMaterial >
7446 < ProgressionControl elementId = { VIEW_SWITCH_ID } >
7547 < OverlayButton
76- onClick = { switchView }
48+ onClick = { setViewportType }
7749 style = { buttonStyle }
7850 icon = {
79- currentView === View . Lab ? (
51+ viewportType === ViewType . Lab ? (
8052 < Molecules />
8153 ) : (
8254 < LabIcon />
8355 )
8456 }
8557 >
86- { currentView === View . Lab ? "Molecular" : "Lab" } view
58+ { viewportType === ViewType . Lab ? "Molecular" : "Lab" } { " " }
59+ view
8760 </ OverlayButton >
8861 </ ProgressionControl >
8962 </ VisibilityControl >
9063 < PlayButton />
91- { currentView === View . Lab ? < LabView /> : null }
64+ { viewportType === ViewType . Lab ? < LabView /> : null }
9265 < Viewer
9366 isPlaying = { isPlaying }
9467 setIsPlaying = { setIsPlaying }
0 commit comments