mirror of
https://github.com/mudabbir-ahmad/Project-MAD-crudler.git
synced 2026-10-07 20:40:20 +00:00
Refactored Code
This commit is contained in:
1 parent
6f062bb150
commit
a08c48b8b1
6 files changed
+179
-97
No files matched your search
+1
-1
@@ -8,7 +8,7 @@ const Component = () => {
|
|||||||
// View -----------------------
|
// View -----------------------
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Text></Text>
|
<View></View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Generated
+8
-1
@@ -55,6 +55,7 @@
|
|||||||
"version": "7.28.4",
|
"version": "7.28.4",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.28.4.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.28.4.tgz",
|
||||||
"integrity": "sha512-2BCOP7TN8M+gVDj7/ht3hsaO/B/n5oDbiAyyvnRlNOs+u1o+JWNYTQrmpuNp1/Wq2gcFrI01JAW+paEKDMx/CA==",
|
"integrity": "sha512-2BCOP7TN8M+gVDj7/ht3hsaO/B/n5oDbiAyyvnRlNOs+u1o+JWNYTQrmpuNp1/Wq2gcFrI01JAW+paEKDMx/CA==",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/code-frame": "^7.27.1",
|
"@babel/code-frame": "^7.27.1",
|
||||||
"@babel/generator": "^7.28.3",
|
"@babel/generator": "^7.28.3",
|
||||||
@@ -4050,6 +4051,7 @@
|
|||||||
"url": "https://github.com/sponsors/ai"
|
"url": "https://github.com/sponsors/ai"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"baseline-browser-mapping": "^2.8.9",
|
"baseline-browser-mapping": "^2.8.9",
|
||||||
"caniuse-lite": "^1.0.30001746",
|
"caniuse-lite": "^1.0.30001746",
|
||||||
@@ -4746,6 +4748,7 @@
|
|||||||
"resolved": "https://registry.npmjs.org/expo/-/expo-54.0.20.tgz",
|
"resolved": "https://registry.npmjs.org/expo/-/expo-54.0.20.tgz",
|
||||||
"integrity": "sha512-mWHky+H63W60P5Oo+VbtqzF2sLvdaoSSwG57H9rlq1DrgIla++QJZuwJkXXo55lYPymVmkVhwG6FjWYKKylwpw==",
|
"integrity": "sha512-mWHky+H63W60P5Oo+VbtqzF2sLvdaoSSwG57H9rlq1DrgIla++QJZuwJkXXo55lYPymVmkVhwG6FjWYKKylwpw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.20.0",
|
"@babel/runtime": "^7.20.0",
|
||||||
"@expo/cli": "54.0.13",
|
"@expo/cli": "54.0.13",
|
||||||
@@ -4797,6 +4800,7 @@
|
|||||||
"version": "14.0.9",
|
"version": "14.0.9",
|
||||||
"resolved": "https://registry.npmjs.org/expo-font/-/expo-font-14.0.9.tgz",
|
"resolved": "https://registry.npmjs.org/expo-font/-/expo-font-14.0.9.tgz",
|
||||||
"integrity": "sha512-xCoQbR/36qqB6tew/LQ6GWICpaBmHLhg/Loix5Rku/0ZtNaXMJv08M9o1AcrdiGTn/Xf/BnLu6DgS45cWQEHZg==",
|
"integrity": "sha512-xCoQbR/36qqB6tew/LQ6GWICpaBmHLhg/Loix5Rku/0ZtNaXMJv08M9o1AcrdiGTn/Xf/BnLu6DgS45cWQEHZg==",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fontfaceobserver": "^2.1.0"
|
"fontfaceobserver": "^2.1.0"
|
||||||
},
|
},
|
||||||
@@ -7672,6 +7676,7 @@
|
|||||||
"version": "19.1.0",
|
"version": "19.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/react/-/react-19.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/react/-/react-19.1.0.tgz",
|
||||||
"integrity": "sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg==",
|
"integrity": "sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg==",
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
@@ -7689,7 +7694,6 @@
|
|||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/react-freeze/-/react-freeze-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/react-freeze/-/react-freeze-1.0.4.tgz",
|
||||||
"integrity": "sha512-r4F0Sec0BLxWicc7HEyo2x3/2icUTrRmDjaaRyzzn+7aDyFZliszMDOgLVwSnQnYENOlL1o569Ze2HZefk8clA==",
|
"integrity": "sha512-r4F0Sec0BLxWicc7HEyo2x3/2icUTrRmDjaaRyzzn+7aDyFZliszMDOgLVwSnQnYENOlL1o569Ze2HZefk8clA==",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
},
|
},
|
||||||
@@ -7707,6 +7711,7 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react-native/-/react-native-0.81.5.tgz",
|
"resolved": "https://registry.npmjs.org/react-native/-/react-native-0.81.5.tgz",
|
||||||
"integrity": "sha512-1w+/oSjEXZjMqsIvmkCRsOc8UBYv163bTWKTI8+1mxztvQPhCRYGTvZ/PL1w16xXHneIj/SLGfxWg2GWN2uexw==",
|
"integrity": "sha512-1w+/oSjEXZjMqsIvmkCRsOc8UBYv163bTWKTI8+1mxztvQPhCRYGTvZ/PL1w16xXHneIj/SLGfxWg2GWN2uexw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@jest/create-cache-key-function": "^29.7.0",
|
"@jest/create-cache-key-function": "^29.7.0",
|
||||||
"@react-native/assets-registry": "0.81.5",
|
"@react-native/assets-registry": "0.81.5",
|
||||||
@@ -7882,6 +7887,7 @@
|
|||||||
"version": "0.14.2",
|
"version": "0.14.2",
|
||||||
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.2.tgz",
|
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.2.tgz",
|
||||||
"integrity": "sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==",
|
"integrity": "sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==",
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
@@ -9330,6 +9336,7 @@
|
|||||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
|
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
|
||||||
"integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
|
"integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/colinhacks"
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import {StyleSheet, Text, TextInput, View} from "react-native";
|
||||||
|
import {Button, ButtonTray} from "./Button";
|
||||||
|
import Icons from "./Icons";
|
||||||
|
|
||||||
|
const Form = ({children, onSubmit, onCancel, submitLabel, submitIcon}) => {
|
||||||
|
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.formContainer}>
|
||||||
|
|
||||||
|
<View style={styles.formItems}>
|
||||||
|
{children}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<ButtonTray>
|
||||||
|
<Button label='Cancel' icon={<Icons.Close/>} onClick={onCancel}/>
|
||||||
|
<Button label={submitLabel} icon={submitIcon} onClick={onSubmit}/>
|
||||||
|
</ButtonTray>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const InputText = ({label, value, onChange}) => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
return (
|
||||||
|
<View style={styles.item}>
|
||||||
|
<Text style={styles.itemLabel}>{label}</Text>
|
||||||
|
<TextInput
|
||||||
|
value={value}
|
||||||
|
onChangeText={onChange}
|
||||||
|
style={styles.itemTextInput}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Compose components
|
||||||
|
Form.InputText = InputText;
|
||||||
|
|
||||||
|
// Styles
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
itemLabel: {
|
||||||
|
color: 'gray',
|
||||||
|
fontSize: 16,
|
||||||
|
margin: 5,
|
||||||
|
},
|
||||||
|
itemTextInput: {
|
||||||
|
height: 50,
|
||||||
|
paddingLeft: 10,
|
||||||
|
fontSize: 16,
|
||||||
|
backgroundColor: 'white',
|
||||||
|
borderRadius: 7,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: 'lightgray',
|
||||||
|
},
|
||||||
|
formItems: {
|
||||||
|
gap: 5,
|
||||||
|
},
|
||||||
|
formContainer: {
|
||||||
|
gap: 10
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Form;
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import {StyleSheet, Text, TextInput, View} from "react-native";
|
||||||
|
import {useState} from "react";
|
||||||
|
import Icons from "../../UI/Icons";
|
||||||
|
import Form from "../../UI/Form";
|
||||||
|
|
||||||
|
const defaultModule = {
|
||||||
|
ModuleID: null,
|
||||||
|
ModuleCode: null,
|
||||||
|
ModuleName: null,
|
||||||
|
ModuleLevel: null,
|
||||||
|
ModuleLeaderID: null,
|
||||||
|
ModuleLeaderName: null,
|
||||||
|
ModuleImage: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const ModuleForm = ({onSubmit, onCancel}) => {
|
||||||
|
|
||||||
|
// Initialisation -------------
|
||||||
|
|
||||||
|
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 handleChange = (field, value) => {
|
||||||
|
setModule({...module, [field]: value})
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = () => onSubmit(module);
|
||||||
|
|
||||||
|
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
|
const submitLabel = 'Add';
|
||||||
|
const submitIcon = <Icons.Add/>;
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
onCancel={onCancel}
|
||||||
|
submitLabel={submitLabel}
|
||||||
|
submitIcon={submitIcon}
|
||||||
|
>
|
||||||
|
|
||||||
|
<Form.InputText
|
||||||
|
label='Module Code'
|
||||||
|
value={module.ModuleCode}
|
||||||
|
onChange={(value) => handleChange('ModuleCode', value)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Form.InputText
|
||||||
|
label='Module Name'
|
||||||
|
value={module.ModuleName}
|
||||||
|
onChange={(value) => handleChange('ModuleName', value)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Form.InputText
|
||||||
|
label='Module Level'
|
||||||
|
value={module.ModuleLevel}
|
||||||
|
onChange={(value) => handleChange('ModuleLevel', value)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Form.InputText
|
||||||
|
label='Module Leader Name'
|
||||||
|
value={module.ModuleLeaderName}
|
||||||
|
onChange={(value) => handleChange('ModuleLeaderName', value)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Form.InputText
|
||||||
|
label='Module Image URL'
|
||||||
|
value={module.ModuleImage}
|
||||||
|
onChange={(value) => handleChange('ModuleImage', value)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* This is to test whether the correct Data was being stored in Local State */}
|
||||||
|
{/*<Text> {module.ModuleCode} {module.ModuleName} </Text>*/}
|
||||||
|
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
formContainer: {},
|
||||||
|
item: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default ModuleForm;
|
||||||
@@ -1,115 +1,24 @@
|
|||||||
import {StyleSheet, Text, TextInput, View} from "react-native";
|
import {StyleSheet, Text, TextInput, View} from "react-native";
|
||||||
import Screen from "../layout/Screen";
|
import Screen from "../layout/Screen";
|
||||||
import {Button, ButtonTray} from "../UI/Button";
|
import ModuleForm from "../entity/modules/moduleForm";
|
||||||
import Icons from "../UI/Icons";
|
|
||||||
import {useState} from "react";
|
|
||||||
|
|
||||||
const defaultModule = {
|
|
||||||
ModuleID: null,
|
|
||||||
ModuleCode: null,
|
|
||||||
ModuleName: null,
|
|
||||||
ModuleLevel: null,
|
|
||||||
ModuleLeaderID: null,
|
|
||||||
ModuleLeaderName: null,
|
|
||||||
ModuleImage: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ModuleAddScreen = ({navigation, route}) => {
|
export const ModuleAddScreen = ({navigation, route}) => {
|
||||||
// Initialisation -------------
|
// 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 ----------------------
|
// State ----------------------
|
||||||
const [module, setModule] = useState(defaultModule);
|
|
||||||
|
|
||||||
// Handlers -------------------
|
// Handlers -------------------
|
||||||
|
|
||||||
const handleAdd = () => onAdd(module);
|
|
||||||
const handleCancel = navigation.goBack;
|
const handleCancel = navigation.goBack;
|
||||||
|
|
||||||
const handleChange = (field, value) => {setModule( {...module, [field]: value} )};
|
|
||||||
|
|
||||||
// View -----------------------
|
// View -----------------------
|
||||||
return (
|
return (
|
||||||
<Screen style={styles.container}>
|
<Screen style={styles.container}>
|
||||||
|
<ModuleForm onSubmit={onAdd} onCancel={handleCancel}/>
|
||||||
<View style={styles.item}>
|
|
||||||
<Text style={styles.itemLabel}>Module Code</Text>
|
|
||||||
<TextInput
|
|
||||||
value={module.ModuleCode}
|
|
||||||
onChangeText={ (value) => handleChange('ModuleCode',value) }
|
|
||||||
style={styles.itemTextInput}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View style={styles.item}>
|
|
||||||
<Text style={styles.itemLabel}>Module Name</Text>
|
|
||||||
<TextInput
|
|
||||||
value={module.ModuleName}
|
|
||||||
onChangeText={ (value) => handleChange('ModuleName',value) }
|
|
||||||
style={styles.itemTextInput}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View style={styles.item}>
|
|
||||||
<Text style={styles.itemLabel}>Module Level</Text>
|
|
||||||
<TextInput
|
|
||||||
value={module.ModuleLevel}
|
|
||||||
onChangeText={ (value) => handleChange('ModuleLevel',value) }
|
|
||||||
style={styles.itemTextInput}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View style={styles.item}>
|
|
||||||
<Text style={styles.itemLabel}>Module Leader Name</Text>
|
|
||||||
<TextInput
|
|
||||||
value={module.ModuleLeaderName}
|
|
||||||
onChangeText={ (value) => handleChange('ModuleLeaderName',value) }
|
|
||||||
style={styles.itemTextInput}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View style={styles.item}>
|
|
||||||
<Text style={styles.itemLabel}>Module Image URL</Text>
|
|
||||||
<TextInput
|
|
||||||
value={module.ModuleImage}
|
|
||||||
onChangeText={ (value) => handleChange('ModuleImage',value) }
|
|
||||||
style={styles.itemTextInput}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{/* This is to test whether the correct Data was being stored in Local State */}
|
|
||||||
{/*<Text> {module.ModuleCode} {module.ModuleName} </Text>*/}
|
|
||||||
|
|
||||||
<ButtonTray>
|
|
||||||
<Button label='Cancel' onClick={handleCancel}/>
|
|
||||||
<Button label='Add' icon={<Icons.Add/>} onClick={handleAdd}/>
|
|
||||||
</ButtonTray>
|
|
||||||
</Screen>
|
</Screen>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({});
|
||||||
item: {},
|
|
||||||
itemLabel: {
|
|
||||||
color: 'gray',
|
|
||||||
fontSize: 16,
|
|
||||||
margin: 5,
|
|
||||||
},
|
|
||||||
itemTextInput: {
|
|
||||||
height: 50,
|
|
||||||
paddingLeft: 10,
|
|
||||||
fontSize: 16,
|
|
||||||
backgroundColor: 'white',
|
|
||||||
borderRadius: 7,
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: 'lightgray',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default ModuleAddScreen;
|
export default ModuleAddScreen;
|
||||||
@@ -12,7 +12,7 @@ export const ModuleViewScreen = ({route}) => {
|
|||||||
// Handlers -------------------
|
// Handlers -------------------
|
||||||
// View -----------------------
|
// View -----------------------
|
||||||
return (<Screen>
|
return (<Screen>
|
||||||
<ModuleView module={module} onDelete={onDelete}></ModuleView>
|
<ModuleView module={module} onDelete={onDelete} />
|
||||||
</Screen>);
|
</Screen>);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user