Refactoring a lot of the user items to use the USER data from the API, as it keeps a very similar structure to module.

This commit is contained in:
bobbert committed 2025-12-07 17:38:37 +00:00
1 parent 755d568090
commit 07e04884af
8 files changed
+177 -137

No files matched your search

+12 -6
View File
@@ -23,7 +23,8 @@ const ModuleView = ({module, onDelete, onModify}) => {
// View ----------------------- // View -----------------------
return (<View style={styles.container}> return (
<View style={styles.container}>
<FullWidthImage source={{uri: module.ModuleImageURL}} style={styles.image}/> <FullWidthImage source={{uri: module.ModuleImageURL}} style={styles.image}/>
<View style={styles.infoTray}> <View style={styles.infoTray}>
@@ -57,15 +58,20 @@ const ModuleView = ({module, onDelete, onModify}) => {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
gap: 15, gap: 15,
}, infoTray: { },
infoTray: {
gap: 5, gap: 5,
}, image: { },
image: {
borderRadius: 3, borderRadius: 3,
}, text: { },
text: {
fontSize: 16, fontSize: 16,
}, boldText: { },
boldText: {
fontSize: 16, fontWeight: 'bold', fontSize: 16, fontWeight: 'bold',
}, dimText: { },
dimText: {
color: "grey", color: "grey",
} }
+12 -18
View File
@@ -22,13 +22,12 @@ const UserForm = ({ originalUser, onSubmit, onCancel }) => {
// Initialisation ------------- // Initialisation -------------
const yearsEndpoint = 'https://softwarehub.uk/unibase/api/years'; const yearsEndpoint = 'https://softwarehub.uk/unibase/api/years';
const usertypesEndpoint = 'https://softwarehub.uk/unibase/api/usertypes'; const userEndpoint = 'https://softwarehub.uk/unibase/api/user';
const [years, , isYearsLoading] = useLoad(yearsEndpoint); const [years, , isYearsLoading] = useLoad(yearsEndpoint);
const [usertypes, , isUsertypesLoading] = useLoad(usertypesEndpoint); const [users, , isUsersLoading] = useLoad(userEndpoint);
// State ---------------------- // State ----------------------
const [user, setUser] = useState(originalUser || { const [user, setUser] = useState(originalUser || {
...defaultUser, ...defaultUser,
UserID: Math.floor(100000 + Math.random() * 900000), UserID: Math.floor(100000 + Math.random() * 900000),
@@ -37,7 +36,6 @@ const UserForm = ({ originalUser, onSubmit, onCancel }) => {
}); });
// Handlers ------------------- // Handlers -------------------
const handleChange = (field, value) => { const handleChange = (field, value) => {
setUser({ ...user, [field]: value }); setUser({ ...user, [field]: value });
}; };
@@ -45,15 +43,14 @@ const UserForm = ({ originalUser, onSubmit, onCancel }) => {
const handleSubmit = () => onSubmit(user); const handleSubmit = () => onSubmit(user);
// View ----------------------- // View -----------------------
const submitLabel = originalUser ? 'Modify' : 'Add'; const submitLabel = originalUser ? 'Modify' : 'Add';
const submitIcon = originalUser ? <Icons.Edit /> : <Icons.Add />; const submitIcon = originalUser ? <Icons.Edit /> : <Icons.Add />;
const levels = [ const levels = [
{ value: '4', label: 'Level 4' }, { value: 4, label: 'Level 4' },
{ value: '5', label: 'Level 5' }, { value: 5, label: 'Level 5' },
{ value: '6', label: 'Level 6' }, { value: 6, label: 'Level 6' },
{ value: '7', label: 'Level 7' } { value: 7, label: 'Level 7' }
]; ];
return ( return (
@@ -81,29 +78,27 @@ const UserForm = ({ originalUser, onSubmit, onCancel }) => {
onChange={(value) => handleChange('UserEmail', value)} onChange={(value) => handleChange('UserEmail', value)}
/> />
{isYearsLoading ? (
<Text>Loading Levels...</Text>
) : (
<Form.InputSelect <Form.InputSelect
label='User Level' label='User Level'
prompt='Select user level...' prompt='Select user level...'
options={levels} options={levels}
value={user.UserLevel} value={user.UserLevel}
onChange={(value) => handleChange('UserLevel', value)} onChange={(value) => handleChange('UserLevel', value)}
isLoading={isYearsLoading}
/> />
)}
{isYearsLoading ? (
<Text>Loading Years...</Text>
) : (
<Form.InputSelect <Form.InputSelect
label='Year/Cohort' label='Year/Cohort'
value={user.UserYearID} value={user.UserYearID}
onChange={(value) => handleChange('UserYearID', value)} onChange={(value) => handleChange('UserYearID', value)}
prompt='Select year/cohort...' prompt='Select year/cohort...'
options={years} options={years}
isLoading={isYearsLoading}
/> />
)}
{isUsertypesLoading ? ( {isUsersLoading ? (
<Text>Loading User Types...</Text> <Text>Loading User Types...</Text>
) : ( ) : (
<Form.InputSelect <Form.InputSelect
@@ -111,8 +106,7 @@ const UserForm = ({ originalUser, onSubmit, onCancel }) => {
value={user.UserUsertypeID} value={user.UserUsertypeID}
onChange={(value) => handleChange('UserUsertypeID', value)} onChange={(value) => handleChange('UserUsertypeID', value)}
prompt='Select user type...' prompt='Select user type...'
options={usertypes} options={users}
isLoading={isUsertypesLoading}
/> />
)} )}
+6 -7
View File
@@ -1,25 +1,24 @@
import {StyleSheet, Text, View, Pressable} from "react-native"; import { StyleSheet, Text, View, Pressable } from "react-native";
const UserItem = ({user, onSelect}) => { const UserItem = ({ user, onSelect }) => {
// Initialisation ------------- // Initialisation -------------
// State ---------------------- // State ----------------------
// Handlers ------------------- // Handlers -------------------
// View ----------------------- // View -----------------------
return ( return (
<Pressable key={user.UserCode} onPress={() => onSelect(user)}> <Pressable key={user.UserID} onPress={() => onSelect(user)}>
<View style={styles.usersItem}> <View style={styles.userItem}>
<Text style={styles.text}> <Text style={styles.text}>
{user.UserCode} {user.UserName} `${user.UserFirstname} ${user.UserLastname}`
</Text> </Text>
</View> </View>
</Pressable> </Pressable>
); );
}; };
const styles = StyleSheet.create({ const styles = StyleSheet.create({
usersItem: { userItem: {
paddingVertical: 15, paddingVertical: 15,
borderBottomWidth: 1, borderBottomWidth: 1,
borderBottomColor: "lightgray", borderBottomColor: "lightgray",
+6 -6
View File
@@ -2,19 +2,19 @@ import {StyleSheet, ScrollView} from "react-native";
import UserItem from "./UserItem"; import UserItem from "./UserItem";
import React from "react"; import React from "react";
const UserList = ({modules, onSelect}) => { const UserList = ({users, onSelect}) => {
// Initialisation ------------- // Initialisation -------------
// State ---------------------- // State ----------------------
// Handlers ------------------- // Handlers -------------------
// View ----------------------- // View -----------------------
return ( return (
<ScrollView style={styles.modulesContainer}> <ScrollView style={styles.usersContainer}>
{modules.map((module) => { {users.map((user) => {
return ( return (
<UserItem <UserItem
module={module} module={user}
key={module.ModuleCode} key={user.UserCode}
onSelect={onSelect} onSelect={onSelect}
/> />
) )
@@ -26,7 +26,7 @@ const UserList = ({modules, onSelect}) => {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
modulesContainer: {}, usersContainer: {},
}); });
export default UserList; export default UserList;
+37 -52
View File
@@ -1,74 +1,59 @@
import {Alert, StyleSheet, Text, View} from "react-native"; import { StyleSheet, Text, View } from "react-native";
import FullWidthImage from "react-native-fullwidth-image"; import FullWidthImage from "react-native-fullwidth-image";
import {Button, ButtonTray} from "../../UI/Button"; import Icons from "../../UI/Icons";
import Icons from "../../UI/Icons.js" import { ListItem } from "../../UI/List";
const UserView = ({module, onDelete, onModify}) => { const UserItem = ({ user, onSelect }) => {
// Initialisation ------------- // Initialisation -------------
const fullName = `${user.UserFirstname} ${user.UserLastname}`;
// State ---------------------- // State ----------------------
// Handlers ------------------- // Handlers -------------------
const handleDelete = () => onDelete(module); const handleSelect = () => onSelect(user);
const requestDelete = () => {
Alert.alert(
'Delete Warning',
`Are you sure you want to delete module ${module.ModuleCode} ${module.ModuleName}?`,
[
{text: 'cancel'},
{text: 'Delete', onPress: handleDelete}
]
);
}
// View ----------------------- // View -----------------------
return (<View style={styles.container}> return (
<FullWidthImage source={{uri: module.ModuleImageURL}} style={styles.image}/> <ListItem onPress={handleSelect}>
<FullWidthImage
source={{ uri: user.UserImageURL }}
style={styles.image}
/>
<View style={styles.infoTray}> <View style={styles.infoTray}>
<Text style={styles.boldText}>View {module.ModuleCode} {module.ModuleName}</Text> <Text style={styles.boldText}>{fullName}</Text>
<Text style={styles.text}>Level {module.ModuleLevel}</Text> <Text style={styles.text}>{user.UserEmail}</Text>
<Text style={styles.text}>cohort {module.ModuleYearID}</Text> <Text style={styles.text}>
<Text style={styles.Text}> {user.UserUsertypeName || 'Unknown Type'}
{module.ModuleLeaderID} <Text style={styles.dimText}>(Module Leader)</Text> <Text style={styles.dimText}> (Level {user.UserLevel})</Text>
</Text> </Text>
</View> </View>
<ButtonTray> <Icons.Forward />
<Button </ListItem>
icon={<Icons.Edit/>} );
label={"Modify"}
onClick={onModify}
/>
<Button
icon={<Icons.Delete/>}
label={"Delete"}
// styleButton={{backgroundColor: 'mistyrose'}}
// styleLabel={{color: 'red'}}
onClick={requestDelete}
/>
</ButtonTray>
</View>);
}; };
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { image: {
gap: 15,
}, infoTray: {
gap: 5,
}, image: {
borderRadius: 3, borderRadius: 3,
}, text: { },
infoTray: {
gap: 5,
flex: 1,
},
text: {
fontSize: 16, fontSize: 16,
}, boldText: { },
fontSize: 16, fontWeight: 'bold', boldText: {
}, dimText: { fontSize: 16,
fontWeight: 'bold',
},
dimText: {
color: "grey", color: "grey",
} },
}); });
export default UserView; export default UserItem;
@@ -2,9 +2,6 @@
import {LogBox, Text} from "react-native"; import {LogBox, Text} from "react-native";
import Screen from "../layout/Screen"; import Screen from "../layout/Screen";
import ModuleList from "../entity/modules/ModuleList"; import ModuleList from "../entity/modules/ModuleList";
// import API from "../API/API";
// import initialModules from "../../data/modules.js";
// import RenderCount from "../UI/RenderCount";
import {Button, ButtonTray} from "../UI/Button"; import {Button, ButtonTray} from "../UI/Button";
import Icons from "../UI/Icons"; import Icons from "../UI/Icons";
import useLoad from "../API/useLoad"; import useLoad from "../API/useLoad";
@@ -15,7 +12,6 @@ const ModuleListScreen = ({navigation}) => {
// let modules = initialModules; // let modules = initialModules;
LogBox.ignoreLogs(['Non-serializable values were found in the navigation state']); LogBox.ignoreLogs(['Non-serializable values were found in the navigation state']);
const modulesEndpoint = 'https://softwarehub.uk/unibase/api/modules'; const modulesEndpoint = 'https://softwarehub.uk/unibase/api/modules';
// State ---------------------- // State ----------------------
+20 -44
View File
@@ -1,42 +1,32 @@
// import {useState, useEffect} from "react"; import { LogBox, Text } from "react-native";
import {LogBox, Text} from "react-native";
import Screen from "../layout/Screen"; import Screen from "../layout/Screen";
import {Button, ButtonTray} from "../UI/Button"; import UserList from "../entity/users/UserList";
import { Button, ButtonTray } from "../UI/Button";
import Icons from "../UI/Icons"; import Icons from "../UI/Icons";
import useLoad from "../API/useLoad"; import useLoad from "../API/useLoad";
import {createDrawerNavigator} from "@react-navigation/drawer";
import ModuleViewScreen from "./ModuleViewScreen";
import UserViewScreen from "./UserViewScreen";
const UserListScreen = ({ navigation }) => {
const UserListScreen = ({navigation}) => { // Initialisation -------------
// Initialisation -------------
// let modules = initialModules;
LogBox.ignoreLogs(['Non-serializable values were found in the navigation state']); LogBox.ignoreLogs(['Non-serializable values were found in the navigation state']);
const Drawer = createDrawerNavigator();
const usersEndpoint = 'https://softwarehub.uk/unibase/api/users'; const usersEndpoint = 'https://softwarehub.uk/unibase/api/users';
// State ---------------------- // State ----------------------
const [users, setUsers, isLoading, loadUsers] = useLoad(usersEndpoint); const [users, setUsers, isLoading, loadUsers] = useLoad(usersEndpoint);
// Handlers ------------------- // Handlers -------------------
const handleDelete = (user) => const handleDelete = (user) =>
setUsers(users.filter((item) => item.UserID !== module.UserID)); setUsers(users.filter((item) => item.UserID !== user.UserID));
const onDelete = (user) => { const onDelete = (user) => {
handleDelete(user); handleDelete(user);
navigation.goBack(); navigation.goBack();
} };
const handleAdd = (user) => setUsers([...users, user]); const handleAdd = (user) => setUsers([...users, user]);
const handleModify = (updatedUser) => setUsers( const handleModify = (updatedUser) => setUsers(
users.map((user) => (module.UserID === updatedUser.UserID) ? updatedUser : user), users.map((user) => (user.UserID === updatedUser.UserID) ? updatedUser : user),
); );
const onAdd = (user) => { const onAdd = (user) => {
@@ -46,45 +36,31 @@ const UserListScreen = ({navigation}) => {
const onModify = (user) => { const onModify = (user) => {
handleModify(user); handleModify(user);
navigation.replace('UserViewScreen', {user, onDelete, onModify}); navigation.replace('UserViewScreen', { user, onDelete, onModify });
}; };
const goToViewScreen = (module) => const goToViewScreen = (user) =>
navigation.navigate('UserViewScreen', {user, onDelete, onModify}); navigation.navigate('UserViewScreen', { user, onDelete, onModify });
const goToAddScreen = () => const goToAddScreen = () =>
navigation.navigate('UserAddScreen', {onAdd}); navigation.navigate('UserAddScreen', { onAdd });
const handleSwitchToModules = () => { const handleSwitchToModules = () => {
navigation.navigate("UserListScreen"); navigation.navigate("ModuleListScreen");
};
// View -----------------------
// View -----------------------
return ( return (
<Screen drawer={<Drawer onSwitch={handleSwitchToModules} currentView="users" />}>
<Drawer.Navigator id={"my-drawer"}>
<Drawer.Screen name='Module Crudler' component={ModuleViewScreen}/>
<Drawer.Screen name='User Crudler' component={UserViewScreen}/>
<Screen>
{/*<RenderCount/>*/}
<ButtonTray> <ButtonTray>
<Button label='Add' icon={<Icons.Add/>} onClick={goToAddScreen}/> <Button label='Add' icon={<Icons.Add />} onClick={goToAddScreen} />
</ButtonTray> </ButtonTray>
{isLoading && <Text>Loading Records...</Text>} {isLoading && <Text>Loading Records...</Text>}
<UserList users={users} onSelect={goToViewScreen}/> <UserList users={users} onSelect={goToViewScreen} />
</Screen> </Screen>
</Drawer.Navigator>
); );
};
}; };
// const styles = StyleSheet.create({});
export default UserListScreen; export default UserListScreen;
+84
View File
@@ -0,0 +1,84 @@
const users = [
{
UserID: 820,
UserFirstname: 'Graeme',
UserLastname: 'Jones',
UserEmail: 'Ku06696@kingston.ac.uk',
UserImageURL:
'https://images.generated.photos/Zx-gNUWFq9NPQDPRLEJQQPWx19QhpKGSAnzIPFUDz3k/rs:fit:512:512/wm:0.95:sowe:18:18:0.33/czM6Ly9pY29uczgu/Z3Bob3Rvcy1wcm9k/LnBob3Rvcy92Ml8w/MDM4MjcxLmpwZw.jpg',
UserType: 'Staff',
UserYear: null,
},
{
UserID: 824,
UserFirstname: 'Paul',
UserLastname: 'Knave',
UserEmail: 'K1234567@kingston.ac.uk',
UserImageURL:
'https://images.generated.photos/IitdqDaBBrr4auYZFuuC_dplp3OtwU2cCuN4q35rN8M/rs:fit:256:256/czM6Ly9pY29uczgu/Z3Bob3Rvcy1wcm9k/LnBob3Rvcy92Ml8w/NDcyMTg5LmpwZw.jpg',
UserType: 'Staff',
UserYear: null,
},
{
UserID: 527,
UserFirstname: 'Justin',
UserLastname: 'TWUMASI',
UserEmail: 'K3346661@kingston.ac.uk',
UserImageURL:
'https://images.generated.photos/1zzVOGo2BC7zlIbuqtT9E03KbcRrCFw0CeIkCRH-pQo/rs:fit:256:256/czM6Ly9pY29uczgu/Z3Bob3Rvcy1wcm9k/LnBob3Rvcy92M18w/OTU2NTI4LmpwZw.jpg',
UserType: 'Student',
UserYear: '2022-23',
},
{
UserID: 287,
UserFirstname: 'Faris',
UserLastname: 'AHMED',
UserEmail: 'K3265517@kingston.ac.uk',
UserImageURL:
'https://images.generated.photos/BdRHDOlzfO2nY3cm9SJuBaf_LPCCv0tzUq3hSv6-Ub8/rs:fit:256:256/czM6Ly9pY29uczgu/Z3Bob3Rvcy1wcm9k/LnBob3Rvcy92M18w/NDYzODY2LmpwZw.jpg',
UserType: 'Student',
UserYear: '2022-23',
},
{
UserID: 467,
UserFirstname: 'Tobi',
UserLastname: 'OLU',
UserEmail: 'K8769678@kingston.ac.uk',
UserImageURL:
'https://images.generated.photos/JaFMncOoAFAerEyw_xWIeFMjzgfkkseT_oGEyP6CgQI/rs:fit:256:256/czM6Ly9pY29uczgu/Z3Bob3Rvcy1wcm9k/LnBob3Rvcy92M18w/MzI5MTY3LmpwZw.jpg',
UserType: 'Student',
UserYear: '2022-23',
},
{
UserID: 534,
UserFirstname: 'Artur',
UserLastname: 'WAGNER',
UserEmail: 'K6664833@kingston.ac.uk',
UserImageURL:
'https://images.generated.photos/XRfSKWBVup-KW5T_lvS0tyce6rGaEBKUDWvk6lxZ8x8/rs:fit:256:256/czM6Ly9pY29uczgu/Z3Bob3Rvcy1wcm9k/LnBob3Rvcy92M18w/MDIwNTQwLmpwZw.jpg',
UserType: 'Student',
UserYear: '2022-23',
},
{
UserID: 515,
UserFirstname: 'Luke',
UserLastname: 'STEVENS',
UserEmail: 'K6845215@kingston.ac.uk',
UserImageURL:
'https://images.generated.photos/XtsBlRxQLgWzFAtycpalUkvVdf9tAvCfC9vEPtSVaxY/rs:fit:256:256/czM6Ly9pY29uczgu/Z3Bob3Rvcy1wcm9k/LnBob3Rvcy92M18w/MzQ2ODE2LmpwZw.jpg',
UserType: 'Student',
UserYear: '2022-23',
},
{
UserID: 276,
UserFirstname: 'Hashim',
UserLastname: 'ABDALLAH',
UserEmail: 'K1083353@kingston.ac.uk',
UserImageURL:
'https://images.generated.photos/eL1-OlKDqGf1IaL_b2O8aSj7osDX_eFVHZEoJ0f3ZV0/rs:fit:256:256/czM6Ly9pY29uczgu/Z3Bob3Rvcy1wcm9k/LnBob3Rvcy92M18w/NzYwNjc0LmpwZw.jpg',
UserType: 'Student',
UserYear: '2022-23',
},
];
export default users;