mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-26 15:40:51 +01:00
fix moodlight state
This commit is contained in:
parent
2b7c54e989
commit
d6a7200136
@ -1,5 +1,5 @@
|
|||||||
import { RoomEngineTriggerWidgetEvent } from '@nitrots/nitro-renderer';
|
import { RoomEngineTriggerWidgetEvent } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useEffect, useMemo, useState } from 'react';
|
import { FC, useEffect, useState } from 'react';
|
||||||
import ReactSlider from 'react-slider';
|
import ReactSlider from 'react-slider';
|
||||||
import { ColorUtils, FurnitureDimmerUtilities, GetConfiguration, LocalizeText } from '../../../../api';
|
import { ColorUtils, FurnitureDimmerUtilities, GetConfiguration, LocalizeText } from '../../../../api';
|
||||||
import { Base, Button, classNames, Column, Flex, Grid, NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView, Text } from '../../../../common';
|
import { Base, Button, classNames, Column, Flex, Grid, NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView, Text } from '../../../../common';
|
||||||
@ -26,7 +26,7 @@ export const FurnitureDimmerView: FC<{}> = props =>
|
|||||||
setIsVisible(true);
|
setIsVisible(true);
|
||||||
}, [ presets ]);
|
}, [ presets ]);
|
||||||
|
|
||||||
const isFreeColorMode = useMemo(() => GetConfiguration<boolean>('widget.dimmer.colorwheel', false), []);
|
const isFreeColorMode = GetConfiguration<boolean>('widget.dimmer.colorwheel', false);
|
||||||
|
|
||||||
if(!isVisible) return null;
|
if(!isVisible) return null;
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ const useFurnitureDimmerWidgetState = () =>
|
|||||||
const [ presets, setPresets ] = useState<DimmerFurnitureWidgetPresetItem[]>([]);
|
const [ presets, setPresets ] = useState<DimmerFurnitureWidgetPresetItem[]>([]);
|
||||||
const [ selectedPresetId, setSelectedPresetId ] = useState(0);
|
const [ selectedPresetId, setSelectedPresetId ] = useState(0);
|
||||||
const [ dimmerState, setDimmerState ] = useState(0);
|
const [ dimmerState, setDimmerState ] = useState(0);
|
||||||
const [ lastDimmerState, setLastDimmerState ] = useState(0);
|
|
||||||
const [ effectId, setEffectId ] = useState(0);
|
const [ effectId, setEffectId ] = useState(0);
|
||||||
const [ color, setColor ] = useState(0xFFFFFF);
|
const [ color, setColor ] = useState(0xFFFFFF);
|
||||||
const [ brightness, setBrightness ] = useState(0xFF);
|
const [ brightness, setBrightness ] = useState(0xFF);
|
||||||
@ -34,8 +33,6 @@ const useFurnitureDimmerWidgetState = () =>
|
|||||||
|
|
||||||
const applyChanges = () =>
|
const applyChanges = () =>
|
||||||
{
|
{
|
||||||
if(dimmerState === 0) return;
|
|
||||||
|
|
||||||
const selectedPresetIndex = (selectedPresetId - 1);
|
const selectedPresetIndex = (selectedPresetId - 1);
|
||||||
|
|
||||||
if((selectedPresetId < 1) || (selectedPresetId > presets.length)) return;
|
if((selectedPresetId < 1) || (selectedPresetId > presets.length)) return;
|
||||||
@ -53,7 +50,7 @@ const useFurnitureDimmerWidgetState = () =>
|
|||||||
return newValue;
|
return newValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
FurnitureDimmerUtilities.savePreset(preset.id, selectedEffectId, selectedColor, selectedBrightness, true);
|
FurnitureDimmerUtilities.savePreset(preset.id, selectedEffectId, selectedColor, selectedBrightness, dimmerState !== 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
useRoomEngineEvent<RoomEngineTriggerWidgetEvent>(RoomEngineTriggerWidgetEvent.REQUEST_DIMMER, event =>
|
useRoomEngineEvent<RoomEngineTriggerWidgetEvent>(RoomEngineTriggerWidgetEvent.REQUEST_DIMMER, event =>
|
||||||
@ -79,14 +76,21 @@ const useFurnitureDimmerWidgetState = () =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
setPresets(presets);
|
setPresets(presets);
|
||||||
setSelectedPresetId(event.selectedPresetId);
|
|
||||||
|
const preset = presets[(event.selectedPresetId - 1)];
|
||||||
|
|
||||||
|
if(!preset) return;
|
||||||
|
|
||||||
|
setSelectedPresetId(preset.id);
|
||||||
|
setSelectedEffectId(preset.type);
|
||||||
|
setSelectedColor(preset.color);
|
||||||
|
setSelectedBrightness(preset.light);
|
||||||
});
|
});
|
||||||
|
|
||||||
useRoomEngineEvent<RoomEngineDimmerStateEvent>(RoomEngineDimmerStateEvent.ROOM_COLOR, event =>
|
useRoomEngineEvent<RoomEngineDimmerStateEvent>(RoomEngineDimmerStateEvent.ROOM_COLOR, event =>
|
||||||
{
|
{
|
||||||
if(RoomId.isRoomPreviewerId(event.roomId)) return;
|
if(RoomId.isRoomPreviewerId(event.roomId)) return;
|
||||||
|
|
||||||
setLastDimmerState(dimmerState);
|
|
||||||
setDimmerState(event.state);
|
setDimmerState(event.state);
|
||||||
setSelectedPresetId(event.presetId);
|
setSelectedPresetId(event.presetId);
|
||||||
setEffectId(event.effectId);
|
setEffectId(event.effectId);
|
||||||
@ -95,16 +99,18 @@ const useFurnitureDimmerWidgetState = () =>
|
|||||||
setSelectedColor(event.color);
|
setSelectedColor(event.color);
|
||||||
setBrightness(event.brightness);
|
setBrightness(event.brightness);
|
||||||
setSelectedBrightness(event.brightness);
|
setSelectedBrightness(event.brightness);
|
||||||
|
|
||||||
|
console.log(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
if((dimmerState === 0) && (lastDimmerState === 0)) return;
|
if(dimmerState === 0 && selectedColor != 0xFFFFFF && selectedBrightness != 0xFF) return;
|
||||||
|
|
||||||
FurnitureDimmerUtilities.previewDimmer(selectedColor, selectedBrightness, (selectedEffectId === 2));
|
FurnitureDimmerUtilities.previewDimmer(selectedColor, selectedBrightness, (selectedEffectId === 2));
|
||||||
}, [ dimmerState, lastDimmerState, selectedColor, selectedBrightness, selectedEffectId ]);
|
}, [ dimmerState, selectedColor, selectedBrightness, selectedEffectId ]);
|
||||||
|
|
||||||
return { presets, selectedPresetId, dimmerState, lastDimmerState, effectId, color, brightness, selectedEffectId, setSelectedEffectId, selectedColor, setSelectedColor, selectedBrightness, setSelectedBrightness, selectPresetId, applyChanges };
|
return { presets, selectedPresetId, dimmerState, effectId, color, brightness, selectedEffectId, setSelectedEffectId, selectedColor, setSelectedColor, selectedBrightness, setSelectedBrightness, selectPresetId, setDimmerState, applyChanges };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useFurnitureDimmerWidget = useFurnitureDimmerWidgetState;
|
export const useFurnitureDimmerWidget = useFurnitureDimmerWidgetState;
|
||||||
|
Loading…
Reference in New Issue
Block a user