action over params

main
alex 2023-08-04 11:55:58 +00:00
parent f695054720
commit 69dad08c0a
4 changed files with 28 additions and 34 deletions

View File

@ -6,6 +6,7 @@ import {
AppContext, AppContext,
AppSelectedUserDevice, AppSelectedUserDevice,
Constants, Constants,
GetDevice,
ModalContainer, ModalContainer,
NewAction, NewAction,
} from "../../../../../utils"; } from "../../../../../utils";
@ -84,12 +85,8 @@ export default function LayerSelectionModalContent({ navigation, route }) {
style={{ marginTop: 20, width: 180 }} style={{ marginTop: 20, width: 180 }}
disabled={selectedLayer.length === 0} disabled={selectedLayer.length === 0}
onPress={() => { onPress={() => {
const device = appContext.devices.find(
(d) => d.id === AppSelectedUserDevice.current.id
);
const newAction = NewAction( const newAction = NewAction(
device.selectedScene, GetDevice(appContext.devices).selectedScene,
Constants.actionType.layers Constants.actionType.layers
); );

View File

@ -85,12 +85,12 @@ export function LightsEditActionModalContent({ navigation, route }) {
lightMode.supportedFirmwareVersions.includes(deviceFirmwareVersion) lightMode.supportedFirmwareVersions.includes(deviceFirmwareVersion)
); );
const selectedSceneActionModeId = appContext.deviceSceneActions.find( const selectedSceneAction = appContext.deviceSceneActions.find(
(a) => a.actionId === actionId (a) => a.actionId === actionId
).modeId; );
const selectedLightMode = supportedDeviceLightModes.find( const selectedLightMode = supportedDeviceLightModes.find(
(s) => s.id === selectedSceneActionModeId (s) => s.id === selectedSceneAction.modeId
); );
useEffect(() => { useEffect(() => {
@ -105,7 +105,7 @@ export function LightsEditActionModalContent({ navigation, route }) {
setLightModeDefaultColors(selectedLightMode.defaults); setLightModeDefaultColors(selectedLightMode.defaults);
setSelectedDefaultLightModeColor(0); setSelectedDefaultLightModeColor(0);
} }
}, [selectedSceneActionModeId]); }, [selectedSceneAction.modeId]);
return ( return (
<View <View
@ -146,7 +146,7 @@ export function LightsEditActionModalContent({ navigation, route }) {
"screens.device.scenes.modalLayersEditAction.dropdownColorModeSelection.label" "screens.device.scenes.modalLayersEditAction.dropdownColorModeSelection.label"
)} )}
selectedItemLabel={ selectedItemLabel={
selectedSceneActionModeId === "" selectedSceneAction.modeId === ""
? t( ? t(
"screens.device.scenes.modalLayersEditAction.dropdownColorModeSelection.noColorModeSelected" "screens.device.scenes.modalLayersEditAction.dropdownColorModeSelection.noColorModeSelected"
) )
@ -155,13 +155,12 @@ export function LightsEditActionModalContent({ navigation, route }) {
onPress={() => onPress={() =>
navigation.navigate("modalLayersEditActionColorModeSelection", { navigation.navigate("modalLayersEditActionColorModeSelection", {
supportedDeviceLightModes: supportedDeviceLightModes, supportedDeviceLightModes: supportedDeviceLightModes,
selectedSceneActionModeId: selectedSceneActionModeId, action: selectedSceneAction,
actionId: route.params.actionId,
}) })
} }
/> />
{selectedSceneActionModeId !== "" && ( {selectedSceneAction.modeId !== "" && (
<> <>
{lightModeDefaultColors.length > 0 && ( {lightModeDefaultColors.length > 0 && (
<> <>
@ -270,10 +269,10 @@ export function LightsEditActionModalContent({ navigation, route }) {
</Card> </Card>
<EditActionAnimationsCardContent <EditActionAnimationsCardContent
disabled={selectedSceneActionModeId === ""} disabled={selectedSceneAction.modeId === ""}
navigation={navigation} navigation={navigation}
deviceFirmwareVersion={deviceFirmwareVersion} deviceFirmwareVersion={deviceFirmwareVersion}
actionId={actionId} action={selectedSceneAction}
/> />
</ScrollView> </ScrollView>
</View> </View>
@ -286,6 +285,8 @@ export function LayersEditActionColorModeSelectionModalContent({
}) { }) {
const appContext = useContext(AppContext); const appContext = useContext(AppContext);
const { action } = route.params;
return ( return (
<ModalContainer withoutPadding> <ModalContainer withoutPadding>
<FlatList <FlatList
@ -294,13 +295,13 @@ export function LayersEditActionColorModeSelectionModalContent({
renderItem={({ item }) => ( renderItem={({ item }) => (
<MyPickerModalListItem <MyPickerModalListItem
itemName={item.name[appContext.appLanguage]} itemName={item.name[appContext.appLanguage]}
itemSelected={route.params.selectedSceneActionModeId === item.id} itemSelected={action.modeId === item.id}
onPress={() => { onPress={() => {
appContext.setDeviceSceneActions((arr) => { appContext.setDeviceSceneActions((arr) => {
const newArr = [...arr]; const newArr = [...arr];
const actionIndex = newArr.findIndex( const actionIndex = newArr.findIndex(
(a) => a.actionId === route.params.actionId (a) => a.actionId === action.actionId
); );
if (actionIndex !== -1) { if (actionIndex !== -1) {

View File

@ -18,23 +18,21 @@ export default function EditActionAnimationsCardContent({
disabled, disabled,
navigation, navigation,
deviceFirmwareVersion, deviceFirmwareVersion,
actionId, action,
}) { }) {
const appContext = useContext(AppContext); const appContext = useContext(AppContext);
const { t } = useTranslation(); const { t } = useTranslation();
const deviceSceneAction = appContext.deviceSceneActions.find( console.log("act", action);
(action) => action.actionId === actionId
);
const selectedLightAnimationIn = const selectedLightAnimationIn =
appContext.deviceFirmwareModes.lightAnimationsIn.find( appContext.deviceFirmwareModes.lightAnimationsIn.find(
(animation) => animation.id === deviceSceneAction.animationInId (animation) => animation.id === action.animationInId
); );
const selectedLightAnimationOut = const selectedLightAnimationOut =
appContext.deviceFirmwareModes.lightAnimationsOut.find( appContext.deviceFirmwareModes.lightAnimationsOut.find(
(animation) => animation.id === deviceSceneAction.animationOutId (animation) => animation.id === action.animationOutId
); );
return ( return (
@ -64,7 +62,7 @@ export default function EditActionAnimationsCardContent({
navigation.navigate("modalEditActionAnimationInSelection", { navigation.navigate("modalEditActionAnimationInSelection", {
animationType: "animationIn", animationType: "animationIn",
deviceFirmwareVersion: deviceFirmwareVersion, deviceFirmwareVersion: deviceFirmwareVersion,
actionId: actionId, action: action,
}) })
} }
/> />
@ -107,7 +105,7 @@ export default function EditActionAnimationsCardContent({
navigation.navigate("modalEditActionAnimationOutSelection", { navigation.navigate("modalEditActionAnimationOutSelection", {
animationType: "animationOut", animationType: "animationOut",
deviceFirmwareVersion: deviceFirmwareVersion, deviceFirmwareVersion: deviceFirmwareVersion,
actionId: actionId, action: action,
}) })
} }
/> />
@ -132,7 +130,7 @@ export function EditActionAnimationSelectionModalContent({
}) { }) {
const appContext = useContext(AppContext); const appContext = useContext(AppContext);
let { animationType, deviceFirmwareVersion, actionId } = route.params; let { animationType, deviceFirmwareVersion, action } = route.params;
const supportedLightAnimations = const supportedLightAnimations =
animationType === "animationIn" animationType === "animationIn"
@ -149,10 +147,6 @@ export function EditActionAnimationSelectionModalContent({
) || animation.supportedFirmwareVersions.includes("*") ) || animation.supportedFirmwareVersions.includes("*")
); );
const deviceSceneAction = appContext.deviceSceneActions.find(
(action) => action.actionId === actionId
);
animationType = animationType =
animationType === "animationIn" ? "animationInId" : "animationOutId"; animationType === "animationIn" ? "animationInId" : "animationOutId";
@ -178,7 +172,7 @@ export function EditActionAnimationSelectionModalContent({
renderItem={({ item }) => ( renderItem={({ item }) => (
<MyPickerModalListItem <MyPickerModalListItem
itemName={item.name[appContext.appLanguage]} itemName={item.name[appContext.appLanguage]}
itemSelected={deviceSceneAction[animationType] === item.id} itemSelected={action[animationType] === item.id}
onPress={() => { onPress={() => {
navigation.goBack(); navigation.goBack();
@ -186,7 +180,7 @@ export function EditActionAnimationSelectionModalContent({
const newArr = [...arr]; const newArr = [...arr];
const foundActionIndex = newArr.findIndex( const foundActionIndex = newArr.findIndex(
(action) => action.actionId === actionId (a) => a.actionId === action.actionId
); );
newArr[foundActionIndex][animationType] = item.id; newArr[foundActionIndex][animationType] = item.id;

View File

@ -402,6 +402,7 @@ const devDeviceSceneActions = [
modeId: "", modeId: "",
animationInId: "", animationInId: "",
animationOutId: "", animationOutId: "",
adjustments: [], // affected layers, animation speed...
}, },
]; ];
@ -411,8 +412,9 @@ export function NewAction(sceneId, actionType) {
sceneId: sceneId, sceneId: sceneId,
type: actionType, // layers, ambilight, motor type: actionType, // layers, ambilight, motor
modeId: "", modeId: "",
animationInId: "00000000-0000-0000-0000-000000000000", animationInId: "00000000-0000-0000-0000-000000000000", // default animation id for -> No animation selected
animationOutId: "00000000-0000-0000-0000-000000000000", animationOutId: "00000000-0000-0000-0000-000000000000", // default animation id for -> No animation selected
adjustments: [],
}; };
} }