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, MotorEditActionMotorModeSelectionModalContent,
} from "./src/Screens/Device/modals/EditActions/Motor"; } from "./src/Screens/Device/modals/EditActions/Motor";
import WaitXSecondsEditActionModalContent from "./src/Screens/Device/modals/EditActions/Wait"; import WaitXSecondsEditActionModalContent from "./src/Screens/Device/modals/EditActions/Wait";
import StopEditActionModalContent from "./src/Screens/Device/modals/EditActions/Stop";
const Drawer = createDrawerNavigator(); const Drawer = createDrawerNavigator();
const Stack = createStackNavigator(); 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 <Stack.Screen
name="modalUpdateSceneName" name="modalUpdateSceneName"
component={UpdateSceneNameModalContent} component={UpdateSceneNameModalContent}

View File

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

View File

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

View File

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

View File

@ -9,6 +9,7 @@ export default function MyTextInput({
value, value,
onChangeText, onChangeText,
inputMode, inputMode,
onSubmitEditing,
}) { }) {
const appContext = useContext(AppContext); const appContext = useContext(AppContext);
@ -28,6 +29,7 @@ export default function MyTextInput({
maxLength={textMaxLength} maxLength={textMaxLength}
value={value} value={value}
onChangeText={onChangeText} onChangeText={onChangeText}
onSubmitEditing={onSubmitEditing}
/> />
<Text <Text
style={[ style={[

View File

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

View File

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

View File

@ -10,24 +10,29 @@ export default function SettingsChangeDeviceDisplayNameModalContent({
const appContext = useContext(AppContext); const appContext = useContext(AppContext);
const { t } = useTranslation(); 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 ( return (
<MyTextInputModalContent <MyTextInputModalContent
navigation={navigation} navigation={navigation}
textMaxLength={Constants.globals.max_device_name_length} textMaxLength={Constants.globals.max_device_name_length}
defaultValue={route.params.displayName} defaultValue={route.params.displayName}
onCheckIconPress={(newDeviceDisplayName) => { onCheckIconPress={(newDeviceDisplayName) => {
appContext.setDevices((arr) => { updateDeviceDisplayName(newDeviceDisplayName);
let newArr = [...arr];
const foundIndex = newArr.findIndex((d) => d.id === route.params.id);
if (foundIndex !== -1) {
newArr[foundIndex].displayName = newDeviceDisplayName;
}
return newArr;
});
}} }}
textOnSubmitEditing={(e) => updateDeviceDisplayName(e.nativeEvent.text)}
textInputTitle={t( textInputTitle={t(
"screens.device.settings.modalSettingsChangeDeviceDisplayName.textTitle" "screens.device.settings.modalSettingsChangeDeviceDisplayName.textTitle"
)} )}

View File

@ -9,6 +9,22 @@ export default function UpdateSceneNameModalContent({ navigation, route }) {
const { deviceSelectedScene, sceneName } = route.params; 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 ( return (
<MyTextInputModalContent <MyTextInputModalContent
navigation={navigation} navigation={navigation}
@ -19,20 +35,9 @@ export default function UpdateSceneNameModalContent({ navigation, route }) {
"screens.device.scenes.modalUpdateSceneName.textDescription" "screens.device.scenes.modalUpdateSceneName.textDescription"
)} )}
onCheckIconPress={(newValue) => { onCheckIconPress={(newValue) => {
appContext.setDeviceScenes((arr) => { updateSceneName(newValue);
let newArr = [...arr];
const foundSceneIndex = newArr.findIndex(
(scene) => scene.sceneId === deviceSelectedScene
);
if (foundSceneIndex !== -1) {
newArr[foundSceneIndex].name = newValue;
}
return newArr;
});
}} }}
textOnSubmitEditing={(e) => updateSceneName(e.nativeEvent.text)}
/> />
); );
} }

View File

@ -246,6 +246,8 @@ function ActionListItem({ drag, navigation, device, item }) {
if (item.type === Constants.actionType.wait) { if (item.type === Constants.actionType.wait) {
title = t("screens.device.scenes.modalAddSceneAction.actions.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 !== "") { } else if (item.modeId !== "") {
title = itemModeList.find((m) => m.id === item.modeId).name[ title = itemModeList.find((m) => m.id === item.modeId).name[
appContext.appLanguage appContext.appLanguage
@ -428,6 +430,9 @@ function ActionListItem({ drag, navigation, device, item }) {
adjustments.push(<ListItem text={<Text>{msg}</Text>} />); adjustments.push(<ListItem text={<Text>{msg}</Text>} />);
break; break;
case Constants.actionType.stop:
navigateTo = "modalStopEditAction";
break;
default: default:
console.log("item type not defined" + item.type); console.log("item type not defined" + item.type);
return; return;