diff --git a/applications/visualizer/frontend/src/components/ViewerContainer/CustomSwitch.tsx b/applications/visualizer/frontend/src/components/ViewerContainer/CustomSwitch.tsx index 84004793..c2825a60 100644 --- a/applications/visualizer/frontend/src/components/ViewerContainer/CustomSwitch.tsx +++ b/applications/visualizer/frontend/src/components/ViewerContainer/CustomSwitch.tsx @@ -1,7 +1,6 @@ import Switch from "@mui/material/Switch"; import Tooltip from "@mui/material/Tooltip"; import type React from "react"; -import { useState } from "react"; import { vars } from "../../theme/variables.ts"; const { white, brand600, gray100 } = vars; @@ -17,19 +16,13 @@ interface CustomSwitchProps { disabled?: boolean; } -const CustomSwitch: React.FC = ({ width, height, thumbDimension, checkedPosition }) => { - const [checked, setChecked] = useState(false); - - const handleChange = (event) => { - setChecked(event.target.checked); - }; - +const CustomSwitch: React.FC = ({ width, height, thumbDimension, checkedPosition, checked, onChange }) => { return ( ({ marginRight: ".5rem", width: width ?? 23, diff --git a/applications/visualizer/frontend/src/components/ViewerSettings.tsx b/applications/visualizer/frontend/src/components/ViewerSettings.tsx index 798dba66..e41eaf71 100644 --- a/applications/visualizer/frontend/src/components/ViewerSettings.tsx +++ b/applications/visualizer/frontend/src/components/ViewerSettings.tsx @@ -1,7 +1,9 @@ import { Box, Divider, Drawer, FormControlLabel, FormGroup, IconButton, Typography } from "@mui/material"; -import { CloseIcon, LinkIcon } from "../icons/index.tsx"; import { vars } from "../theme/variables.ts"; import CustomSwitch from "./ViewerContainer/CustomSwitch.tsx"; +import {useGlobalContext} from "../contexts/GlobalContext.tsx"; +import {produce} from "immer"; +import { CloseIcon, LinkIcon } from "../icons"; const { gray900A, gray600, gray100, white, gray700 } = vars; @@ -32,14 +34,27 @@ const SyncViewersData = [ }, ]; -const ViewersList = ["Connectivity graph", "3D viewer", "EM viewer"]; - const textStyles = { ...secondaryTypographyStyles, fontWeight: 500, flex: 1 }; const buttonStyle = { p: "0.25rem", }; const ViewerSettings = ({ open, toggleDrawer }) => { + const { workspaces, currentWorkspaceId, updateWorkspace } = useGlobalContext(); + const currentWorkspace = workspaces[currentWorkspaceId]; + const handleToggle = (e, viewer) => { + const updatedWorkspace = produce(currentWorkspace, (draft) => { + draft.viewers[viewer] = e.target.checked; + }); + updateWorkspace(updatedWorkspace); + }; + const handleChangeSynchronizations = (_, index) => { + const updatedWorkspace = produce(currentWorkspace, (draft) => { + draft.synchronizations[index] = !draft.synchronizations[index] + }); + updateWorkspace(updatedWorkspace); + }; + return ( { - + Show/hide viewers @@ -107,38 +122,43 @@ const ViewerSettings = ({ open, toggleDrawer }) => { }, }} > - {ViewersList?.map((viewer) => { - return ( - } - key={`viewer-${viewer}`} - label={ - - {viewer} graph - - } - /> - ); - })} + {Object.keys(currentWorkspace?.viewers)?.map((viewer) => ( + handleToggle(e, viewer)} + /> + } + key={`viewer-${viewer}`} + label={ + + {viewer} + + } + /> + ))} - + Sync viewers - + - {SyncViewersData?.map((data, index) => { - return ( - - {data.primaryText} - - - - {data.secondaryText} - - ); - })} + {SyncViewersData?.map((data, index) => ( + + {data.primaryText} + handleChangeSynchronizations(e, index)}> + + + {data.secondaryText} + + ))}