From 6f062bb150850c886b64a9755d4e0a3fe181e005 Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Thu, 4 Dec 2025 15:16:43 +0000 Subject: [PATCH 1/7] Added Forms and Local state to Add screen page --- src/components/screens/ModuleAddScreen.js | 103 +++++++++++++++++++--- 1 file changed, 89 insertions(+), 14 deletions(-) diff --git a/src/components/screens/ModuleAddScreen.js b/src/components/screens/ModuleAddScreen.js index ef5a929..669556c 100644 --- a/src/components/screens/ModuleAddScreen.js +++ b/src/components/screens/ModuleAddScreen.js @@ -1,40 +1,115 @@ -import {StyleSheet, Text} from "react-native"; +import {StyleSheet, Text, TextInput, View} from "react-native"; import Screen from "../layout/Screen"; import {Button, ButtonTray} from "../UI/Button"; import Icons from "../UI/Icons"; +import {useState} from "react"; const defaultModule = { - ModuleID: Math.floor(100000 + Math.random()*900000), - ModuleCode: "CI6330", - ModuleName: "Mobile Application Development", - ModuleLevel: 6, - ModuleLeaderID: 1, - ModuleLeaderName: "Graeme Jones", - ModuleImage: 'https://images.freeimages.com/images/small-preview/cf5/cellphone-1313194.jpg', + ModuleID: null, + ModuleCode: null, + ModuleName: null, + ModuleLevel: null, + ModuleLeaderID: null, + ModuleLeaderName: null, + ModuleImage: null, }; export const ModuleAddScreen = ({navigation, route}) => { // Initialisation ------------- - const { onAdd } = route.params; + const {onAdd} = route.params; + + defaultModule.ModuleID = Math.floor(100000 + Math.random() * 900000); + defaultModule.ModuleImage = 'https://images.freeimages.com/images/small-preview/cf5/cellphone-1313194.jpg'; // State ---------------------- + const [module, setModule] = useState(defaultModule); + // Handlers ------------------- - const handleAdd = () => onAdd(defaultModule); + const handleAdd = () => onAdd(module); const handleCancel = navigation.goBack; + const handleChange = (field, value) => {setModule( {...module, [field]: value} )}; + // View ----------------------- return ( - Add + + + Module Code + handleChange('ModuleCode',value) } + style={styles.itemTextInput} + /> + + + + Module Name + handleChange('ModuleName',value) } + style={styles.itemTextInput} + /> + + + + Module Level + handleChange('ModuleLevel',value) } + style={styles.itemTextInput} + /> + + + + Module Leader Name + handleChange('ModuleLeaderName',value) } + style={styles.itemTextInput} + /> + + + + Module Image URL + handleChange('ModuleImage',value) } + style={styles.itemTextInput} + /> + + + + + + {/* This is to test whether the correct Data was being stored in Local State */} + {/* {module.ModuleCode} {module.ModuleName} */} + -