save edit on text enter

main
alex 2023-08-10 06:23:10 +00:00
parent 998f62b0f9
commit da484d8b5f
10 changed files with 77 additions and 29 deletions

14
App.js
View File

@ -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() {
}
/>
<Stack.Screen
name="modalStopEditAction"
component={StopEditActionModalContent}
options={({ navigation }) =>
options({
navigation: navigation,
pageTitle: t(
"screens.device.scenes.editActions.modalStopEditAction.pageTitle"
),
})
}
/>
<Stack.Screen
name="modalUpdateSceneName"
component={UpdateSceneNameModalContent}

View File

@ -145,6 +145,10 @@
"singular": "Sekunde",
"plural": "Sekunden"
}
},
"modalStopEditAction": {
"pageTitle": "Stop",
"description": "Das Gerät stoppt hier und wird keine weiteren Aktionen ausführen."
}
},
"modalUpdateSceneName": {

View File

@ -145,6 +145,10 @@
"singular": "Second",
"plural": "Seconds"
}
},
"modalStopEditAction": {
"pageTitle": "Stop",
"description": "The device will stop here and will not execute further actions."
}
},
"modalUpdateSceneName": {

View File

@ -279,6 +279,7 @@ export function MyTextInputModalContent({
textInputTitle,
textInputDescription,
textMaxLength,
textOnSubmitEditing,
}) {
const [newValue, setNewValue] = useState(defaultValue);
@ -308,6 +309,10 @@ export function MyTextInputModalContent({
value={newValue}
onChangeText={(v) => setNewValue(v)}
textMaxLength={textMaxLength}
onSubmitEditing={(e) => {
navigation.goBack();
textOnSubmitEditing(e);
}}
/>
</ModalContainer>
);

View File

@ -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}
/>
<Text
style={[

View File

@ -171,13 +171,19 @@ export default function AddSceneActionModalContent({ navigation, route }) {
iconName={ActionTypeIconName(Constants.actionType.waitUntilTimeX)}
onPress={() => console.log("pressed action")}
deviceFirmwareVersion={deviceFirmwareVersion}
supportedFirmwareVersions={["1.0.1"]}
supportedFirmwareVersions={["1.0.0"]}
/>
<Action
text={t("screens.device.scenes.modalAddSceneAction.actions.stop")}
iconName={ActionTypeIconName(Constants.actionType.stop)}
onPress={() => 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"]}
/>
<Action

View File

@ -70,8 +70,6 @@ export default function WaitEditActionModalContent({ navigation, route }) {
const { action } = route.params;
console.log("params", route.params);
const [selectedHours, setSelectedHours] = useState(
action.modeAdjustments.hours
);

View File

@ -10,24 +10,29 @@ export default function SettingsChangeDeviceDisplayNameModalContent({
const appContext = useContext(AppContext);
const { t } = useTranslation();
const updateDeviceDisplayName = (newDeviceDisplayName) => {
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 (
<MyTextInputModalContent
navigation={navigation}
textMaxLength={Constants.globals.max_device_name_length}
defaultValue={route.params.displayName}
onCheckIconPress={(newDeviceDisplayName) => {
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"
)}

View File

@ -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 (
<MyTextInputModalContent
navigation={navigation}
@ -19,20 +35,9 @@ export default function UpdateSceneNameModalContent({ navigation, route }) {
"screens.device.scenes.modalUpdateSceneName.textDescription"
)}
onCheckIconPress={(newValue) => {
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)}
/>
);
}

View File

@ -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(<ListItem text={<Text>{msg}</Text>} />);
break;
case Constants.actionType.stop:
navigateTo = "modalStopEditAction";
break;
default:
console.log("item type not defined" + item.type);
return;