diff --git a/frontend/src/scenes/frame/panels/Control/controlLogic.tsx b/frontend/src/scenes/frame/panels/Control/controlLogic.tsx index ec1851ac..ddb73e62 100644 --- a/frontend/src/scenes/frame/panels/Control/controlLogic.tsx +++ b/frontend/src/scenes/frame/panels/Control/controlLogic.tsx @@ -3,7 +3,7 @@ import { actions, afterMount, connect, kea, key, listeners, path, props, reducer import { frameLogic } from '../../frameLogic' import { forms } from 'kea-forms' -import { FrameScene } from '../../../../types' +import { FrameScene, FrameStateRecord } from '../../../../types' import { loaders } from 'kea-loaders' @@ -14,11 +14,6 @@ export interface ControlLogicProps { frameId: number } -export interface StateRecord { - sceneId: string - state: Record -} - export const controlLogic = kea([ path(['src', 'scenes', 'frame', 'panels', 'Scenes', 'controlLogic']), props({} as ControlLogicProps), @@ -34,7 +29,7 @@ export const controlLogic = kea([ }), loaders(({ props, values }) => ({ stateRecord: [ - {} as StateRecord, + {} as FrameStateRecord, { sync: async (_, breakpoint) => { await breakpoint(100) @@ -54,7 +49,7 @@ export const controlLogic = kea([ })), reducers({ stateRecord: [ - {} as StateRecord, + {} as FrameStateRecord, { currentSceneChanged: (state, { sceneId }) => ({ ...state, sceneId }), }, diff --git a/frontend/src/scenes/frame/panels/Scenes/Scenes.tsx b/frontend/src/scenes/frame/panels/Scenes/Scenes.tsx index 95265a23..b7e68918 100644 --- a/frontend/src/scenes/frame/panels/Scenes/Scenes.tsx +++ b/frontend/src/scenes/frame/panels/Scenes/Scenes.tsx @@ -23,11 +23,14 @@ import { SceneSettings } from './SceneSettings' import React from 'react' import { SceneDropDown } from './SceneDropDown' import { showAsFps } from '../../../../decorators/refreshInterval' +import clsx from 'clsx' export function Scenes() { const { frameId, frameForm } = useValues(frameLogic) const { editScene, openTemplates } = useActions(panelsLogic) - const { scenes, showNewSceneForm, isNewSceneSubmitting, showingSettings } = useValues(scenesLogic({ frameId })) + const { scenes, showNewSceneForm, isNewSceneSubmitting, showingSettings, activeSceneId } = useValues( + scenesLogic({ frameId }) + ) const { toggleSettings, submitNewScene, toggleNewScene, createNewScene, closeNewScene } = useActions( scenesLogic({ frameId }) ) @@ -86,7 +89,16 @@ export function Scenes() { ) : null} {scenes.map((scene) => ( - +
editScene(scene.id)} + >
editScene(scene.id)}> @@ -106,6 +118,11 @@ export function Scenes() { {showAsFps(scene.settings.refreshInterval)} ) : null} + {activeSceneId === scene.id ? ( + + active + + ) : null}
id: {scene.id}
@@ -115,7 +132,7 @@ export function Scenes() {
-
+ {showingSettings[scene.id] ? ( toggleSettings(scene.id)} /> diff --git a/frontend/src/scenes/frame/panels/Scenes/scenesLogic.tsx b/frontend/src/scenes/frame/panels/Scenes/scenesLogic.tsx index a5cfe43f..d83b591c 100644 --- a/frontend/src/scenes/frame/panels/Scenes/scenesLogic.tsx +++ b/frontend/src/scenes/frame/panels/Scenes/scenesLogic.tsx @@ -1,4 +1,4 @@ -import { actions, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea' +import { actions, afterMount, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea' import type { scenesLogicType } from './scenesLogicType' import { FrameScene, Panel } from '../../../../types' import { frameLogic, sanitizeScene } from '../../frameLogic' @@ -6,9 +6,9 @@ import { appsModel } from '../../../../models/appsModel' import { forms } from 'kea-forms' import { v4 as uuidv4 } from 'uuid' import { panelsLogic } from '../panelsLogic' -import { Option } from '../../../../components/Select' import _sceneTemplates from '../../../../../schema/templates.json' +import { controlLogic } from '../Control/controlLogic' const sceneTemplates: Record> = _sceneTemplates export interface ScenesLogicProps { @@ -20,8 +20,22 @@ export const scenesLogic = kea([ props({} as ScenesLogicProps), key((props) => props.frameId), connect(({ frameId }: ScenesLogicProps) => ({ - values: [frameLogic({ frameId }), ['frame', 'frameForm'], appsModel, ['apps']], - actions: [frameLogic({ frameId }), ['applyTemplate'], panelsLogic({ frameId }), ['editScene', 'closePanel']], + values: [ + frameLogic({ frameId }), + ['frame', 'frameForm'], + appsModel, + ['apps'], + controlLogic({ frameId }), + ['sceneId as activeSceneId'], + ], + actions: [ + frameLogic({ frameId }), + ['applyTemplate'], + panelsLogic({ frameId }), + ['editScene', 'closePanel'], + controlLogic({ frameId }), + ['sync as syncActiveScene'], + ], })), actions({ toggleSettings: (sceneId: string) => ({ sceneId }), @@ -33,6 +47,7 @@ export const scenesLogic = kea([ toggleNewScene: true, closeNewScene: true, createNewScene: true, + sync: true, }), forms(({ actions, values, props }) => ({ newScene: { @@ -182,4 +197,7 @@ export const scenesLogic = kea([ }, ], }), + afterMount(({ actions }) => { + actions.syncActiveScene() + }), ]) diff --git a/frontend/src/types.tsx b/frontend/src/types.tsx index 8a489fce..17817479 100644 --- a/frontend/src/types.tsx +++ b/frontend/src/types.tsx @@ -422,3 +422,8 @@ export interface FrameOSSettings { accessKey?: string } } + +export interface FrameStateRecord { + sceneId: string + state: Record +}