diff --git a/frontend/src/framework/Module.tsx b/frontend/src/framework/Module.tsx index e47f67c0e..c58fd420e 100644 --- a/frontend/src/framework/Module.tsx +++ b/frontend/src/framework/Module.tsx @@ -99,7 +99,14 @@ export class Module { return this._syncableSettingKeys; } + + hasSyncableSettingKey(key: SyncSettingKey): boolean { + return this._syncableSettingKeys.includes(key); + } + + makeInstance(instanceNumber: number): ModuleInstance { + if (!this._workbench) { throw new Error("Module must be added to a workbench before making an instance"); } diff --git a/frontend/src/framework/internal/components/Settings/private-components/syncSettings.tsx b/frontend/src/framework/internal/components/Settings/private-components/syncSettings.tsx index 88cd38ae3..2f7c7d272 100644 --- a/frontend/src/framework/internal/components/Settings/private-components/syncSettings.tsx +++ b/frontend/src/framework/internal/components/Settings/private-components/syncSettings.tsx @@ -5,7 +5,7 @@ import { SyncSettingKey, SyncSettingsMeta } from "@framework/SyncSettings"; import { DrawerContent, Workbench } from "@framework/Workbench"; import { Drawer } from "@framework/internal/components/Drawer"; import { useActiveModuleId } from "@framework/internal/hooks/workbenchHooks"; -import { LinkIcon } from "@heroicons/react/20/solid"; +import { GlobeAltIcon, LinkIcon, MapPinIcon } from "@heroicons/react/20/solid"; import { Checkbox } from "@lib/components/Checkbox"; type ModulesListProps = { @@ -13,44 +13,109 @@ type ModulesListProps = { }; export const SyncSettings: React.FC = (props) => { + const forceRerender = React.useReducer((x) => x + 1, 0)[1]; const drawerContent = useStoreValue(props.workbench.getGuiStateStore(), "drawerContent"); const activeModuleId = useActiveModuleId(props.workbench); const activeModuleInstance = props.workbench.getModuleInstance(activeModuleId); - const handleSyncSettingChange = (setting: SyncSettingKey, value: boolean) => { + function handleSyncSettingChange(setting: SyncSettingKey, value: boolean) { if (activeModuleInstance === undefined) { return; } if (value) { - activeModuleInstance.addSyncedSetting(setting); + if (!activeModuleInstance.isSyncedSetting(setting)) { + activeModuleInstance.addSyncedSetting(setting); + } } else { activeModuleInstance.removeSyncedSetting(setting); } - }; + + forceRerender(); + } + + function handleGlobalSyncSettingChange(setting: SyncSettingKey, value: boolean) { + const moduleInstances = props.workbench.getModuleInstances(); + + // @rmt: This has to be changed as soon as we support multiple pages + for (const moduleInstance of moduleInstances) { + if (moduleInstance.getModule().hasSyncableSettingKey(setting)) { + if (value) { + if (!moduleInstance.isSyncedSetting(setting)) { + moduleInstance.addSyncedSetting(setting); + } + } else { + moduleInstance.removeSyncedSetting(setting); + } + } + } + + forceRerender(); + } + + function isGlobalSyncSetting(setting: SyncSettingKey): boolean { + const moduleInstances = props.workbench.getModuleInstances(); + + // @rmt: This has to be changed as soon as we support multiple pages + for (const moduleInstance of moduleInstances) { + if (moduleInstance.getModule().hasSyncableSettingKey(setting)) { + if (!moduleInstance.isSyncedSetting(setting)) { + return false; + } + } + } + + return true; + } return ( } visible={drawerContent === DrawerContent.SyncSettings}> {activeModuleId === "" || activeModuleInstance === undefined ? (
No module selected
) : ( - <> - {activeModuleInstance - .getModule() - .getSyncableSettingKeys() - .map((setting) => { - return ( -
- handleSyncSettingChange(setting, e.target.checked)} - label={SyncSettingsMeta[setting].name} - /> -
- ); - })} - + + + + + + + + + + {activeModuleInstance + .getModule() + .getSyncableSettingKeys() + .map((setting) => { + const globallySynced = isGlobalSyncSetting(setting); + return ( + + + + + + ); + })} + +
+ + + +
+ + handleGlobalSyncSettingChange(setting, e.target.checked) + } + /> + + handleSyncSettingChange(setting, e.target.checked)} + /> + {SyncSettingsMeta[setting].name}
)}
);