From da484d8b5f4e555a9a510165ae9b3bd00bf7740c Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 10 Aug 2023 06:23:10 +0000 Subject: [PATCH] save edit on text enter --- App.js | 14 +++++++++ locales/de.json | 4 +++ locales/en.json | 4 +++ src/Components/Modal/index.js | 5 +++ src/Components/TextInput/index.js | 2 ++ .../Device/modals/AddSceneAction/index.js | 12 +++++-- .../Device/modals/EditActions/Wait/index.js | 2 -- .../SettingsChangeDeviceDisplayName/index.js | 27 +++++++++------- .../Device/modals/UpdateSceneName/index.js | 31 +++++++++++-------- src/Screens/Device/scene.js | 5 +++ 10 files changed, 77 insertions(+), 29 deletions(-) diff --git a/App.js b/App.js index 49d72ff..43bdf17 100644 --- a/App.js +++ b/App.js @@ -39,6 +39,7 @@ import MotorEditActionModalContent, { MotorEditActionMotorModeSelectionModalContent, } from "./src/Screens/Device/modals/EditActions/Motor"; import WaitXSecondsEditActionModalContent from "./src/Screens/Device/modals/EditActions/Wait"; +import StopEditActionModalContent from "./src/Screens/Device/modals/EditActions/Stop"; const Drawer = createDrawerNavigator(); const Stack = createStackNavigator(); @@ -248,6 +249,19 @@ export function MyApp() { } /> + + options({ + navigation: navigation, + pageTitle: t( + "screens.device.scenes.editActions.modalStopEditAction.pageTitle" + ), + }) + } + /> + setNewValue(v)} textMaxLength={textMaxLength} + onSubmitEditing={(e) => { + navigation.goBack(); + textOnSubmitEditing(e); + }} /> ); diff --git a/src/Components/TextInput/index.js b/src/Components/TextInput/index.js index ba4ccff..25e20e0 100644 --- a/src/Components/TextInput/index.js +++ b/src/Components/TextInput/index.js @@ -9,6 +9,7 @@ export default function MyTextInput({ value, onChangeText, inputMode, + onSubmitEditing, }) { const appContext = useContext(AppContext); @@ -28,6 +29,7 @@ export default function MyTextInput({ maxLength={textMaxLength} value={value} onChangeText={onChangeText} + onSubmitEditing={onSubmitEditing} /> console.log("pressed action")} deviceFirmwareVersion={deviceFirmwareVersion} - supportedFirmwareVersions={["1.0.1"]} + supportedFirmwareVersions={["1.0.0"]} /> console.log("pressed action")} + onPress={() => + handleCreateAction( + Constants.actionType.stop, + {}, + "modalStopEditAction" + ) + } deviceFirmwareVersion={deviceFirmwareVersion} supportedFirmwareVersions={["1.0.1"]} /> @@ -189,7 +195,7 @@ export default function AddSceneActionModalContent({ navigation, route }) { iconName={ActionTypeIconName(Constants.actionType.timeControl)} onPress={() => console.log("pressed action")} deviceFirmwareVersion={deviceFirmwareVersion} - supportedFirmwareVersions={["1.0.1"]} + supportedFirmwareVersions={["1.0.0"]} /> { + appContext.setDevices((arr) => { + let newArr = [...arr]; + + const foundIndex = newArr.findIndex((d) => d.id === route.params.id); + + if (foundIndex !== -1) { + newArr[foundIndex].displayName = newDeviceDisplayName; + } + + return newArr; + }); + }; + return ( { - appContext.setDevices((arr) => { - let newArr = [...arr]; - - const foundIndex = newArr.findIndex((d) => d.id === route.params.id); - - if (foundIndex !== -1) { - newArr[foundIndex].displayName = newDeviceDisplayName; - } - - return newArr; - }); + updateDeviceDisplayName(newDeviceDisplayName); }} + textOnSubmitEditing={(e) => updateDeviceDisplayName(e.nativeEvent.text)} textInputTitle={t( "screens.device.settings.modalSettingsChangeDeviceDisplayName.textTitle" )} diff --git a/src/Screens/Device/modals/UpdateSceneName/index.js b/src/Screens/Device/modals/UpdateSceneName/index.js index 15aa755..fc693be 100644 --- a/src/Screens/Device/modals/UpdateSceneName/index.js +++ b/src/Screens/Device/modals/UpdateSceneName/index.js @@ -9,6 +9,22 @@ export default function UpdateSceneNameModalContent({ navigation, route }) { const { deviceSelectedScene, sceneName } = route.params; + const updateSceneName = (newName) => { + appContext.setDeviceScenes((arr) => { + let newArr = [...arr]; + + const foundSceneIndex = newArr.findIndex( + (scene) => scene.sceneId === deviceSelectedScene + ); + + if (foundSceneIndex !== -1) { + newArr[foundSceneIndex].name = newName; + } + + return newArr; + }); + }; + return ( { - appContext.setDeviceScenes((arr) => { - let newArr = [...arr]; - - const foundSceneIndex = newArr.findIndex( - (scene) => scene.sceneId === deviceSelectedScene - ); - - if (foundSceneIndex !== -1) { - newArr[foundSceneIndex].name = newValue; - } - - return newArr; - }); + updateSceneName(newValue); }} + textOnSubmitEditing={(e) => updateSceneName(e.nativeEvent.text)} /> ); } diff --git a/src/Screens/Device/scene.js b/src/Screens/Device/scene.js index 73d843a..d6392c2 100644 --- a/src/Screens/Device/scene.js +++ b/src/Screens/Device/scene.js @@ -246,6 +246,8 @@ function ActionListItem({ drag, navigation, device, item }) { if (item.type === Constants.actionType.wait) { title = t("screens.device.scenes.modalAddSceneAction.actions.wait"); + } else if (item.type === Constants.actionType.stop) { + title = t("screens.device.scenes.modalAddSceneAction.actions.stop"); } else if (item.modeId !== "") { title = itemModeList.find((m) => m.id === item.modeId).name[ appContext.appLanguage @@ -428,6 +430,9 @@ function ActionListItem({ drag, navigation, device, item }) { adjustments.push({msg}} />); break; + case Constants.actionType.stop: + navigateTo = "modalStopEditAction"; + break; default: console.log("item type not defined" + item.type); return;