Added useLoad function, updated moduleView to include cohort, added useLoad to module list screen and module form, so there is a dropdown now for leaders as well.

This commit is contained in:
bobbert committed 2025-12-06 16:52:00 +00:00
1 parent 57369791a4
commit dd5324ff39
5 files changed
+41 -49

No files matched your search

+1 -1
View File
@@ -22,7 +22,7 @@ const useLoad = (loadEndpoint) => {
// return ---------------------- // return ----------------------
return[records, setRecords, isLoading, loadRecords]; return [records, setRecords, isLoading, loadRecords];
}; };
export default useLoad; export default useLoad;
+3 -3
View File
@@ -1,5 +1,5 @@
import { useRef } from "react"; import {useRef} from "react";
import { Text, StyleSheet } from "react-native"; import {Text, StyleSheet} from "react-native";
const RenderCount = ({backgroundColor = 'dodgerblue', fontColor = 'white'}) => { const RenderCount = ({backgroundColor = 'dodgerblue', fontColor = 'white'}) => {
// Initialisation ------------- // Initialisation -------------
@@ -9,7 +9,7 @@ const RenderCount = ({backgroundColor = 'dodgerblue', fontColor = 'white'}) => {
// Handlers ------------------- // Handlers -------------------
// View ----------------------- // View -----------------------
return ( return (
<Text style={[styles.count, { backgroundColor, color: fontColor}]}> <Text style={[styles.count, {backgroundColor, color: fontColor}]}>
Number of renders: {renderCount.current} Number of renders: {renderCount.current}
</Text> </Text>
); );
+2 -1
View File
@@ -29,8 +29,9 @@ const ModuleView = ({module, onDelete, onModify}) => {
<View style={styles.infoTray}> <View style={styles.infoTray}>
<Text style={styles.boldText}>View {module.ModuleCode} {module.ModuleName}</Text> <Text style={styles.boldText}>View {module.ModuleCode} {module.ModuleName}</Text>
<Text style={styles.text}>Level {module.ModuleLevel}</Text> <Text style={styles.text}>Level {module.ModuleLevel}</Text>
<Text style={styles.text}>cohort {module.ModuleYearID}</Text>
<Text style={styles.Text}> <Text style={styles.Text}>
{module.ModuleLeaderName} <Text style={styles.dimText}>(Module Leader)</Text> {module.ModuleLeaderID} <Text style={styles.dimText}>(Module Leader)</Text>
</Text> </Text>
</View> </View>
+26 -28
View File
@@ -1,16 +1,16 @@
import {StyleSheet, Text, TextInput, View} from "react-native"; import { Text } from "react-native";
import {useEffect, useState} from "react"; import {useState} from "react";
import Icons from "../../UI/Icons"; import Icons from "../../UI/Icons";
import Form from "../../UI/Form"; import Form from "../../UI/Form";
import API from "../../API/API"; import useLoad from "../../API/useLoad";
const defaultModule = { const defaultModule = {
ModuleID: null, ModuleID: null,
ModuleCode: null, ModuleCode: null,
ModuleName: null, ModuleName: null,
ModuleLevel: null, ModuleLevel: null,
ModuleLeaderID: null,
ModuleYearID: null, ModuleYearID: null,
ModuleLeaderID: null,
ModuleImageURL: null, ModuleImageURL: null,
}; };
@@ -23,6 +23,8 @@ const ModuleForm = ({originalModule, onSubmit, onCancel}) => {
const yearsEndpoint = 'https://softwarehub.uk/unibase/api/years'; const yearsEndpoint = 'https://softwarehub.uk/unibase/api/years';
const staffEndpoint = 'https://softwarehub.uk/unibase/api/users/staff';
const levels = [ const levels = [
{value: 3, label: '3 (Foundation)'}, {value: 3, label: '3 (Foundation)'},
{value: 4, label: '4 (First Year)'}, {value: 4, label: '4 (First Year)'},
@@ -44,18 +46,9 @@ const ModuleForm = ({originalModule, onSubmit, onCancel}) => {
const [module, setModule] = useState(originalModule || defaultModule); const [module, setModule] = useState(originalModule || defaultModule);
const [years, setYears] = useState([]); const [years, , isYearsLoading] = useLoad(yearsEndpoint);
const [isYearsLoading, setIsYearsLoading] = useState(true);
const loadYears = async (endpoint) => { const [Leaders, , isLeadersLoading] = useLoad(staffEndpoint);
const response = await API.get(endpoint);
setIsYearsLoading(false);
if (response.isSuccess) setYears(response.result);
};
useEffect(() => {
loadYears(yearsEndpoint)
}, []);
// Handlers ------------------- // Handlers -------------------
@@ -71,8 +64,11 @@ const ModuleForm = ({originalModule, onSubmit, onCancel}) => {
const submitLabel = originalModule ? 'Modify' : 'Add'; const submitLabel = originalModule ? 'Modify' : 'Add';
const submitIcon = originalModule ? <Icons.Edit/> : <Icons.Add/>; const submitIcon = originalModule ? <Icons.Edit/> : <Icons.Add/>;
const cohorts = years.map((year) => ({value: year.YearID, label: year.YearName}) ); const cohorts = years.map((year) => ({value: year.YearID, label: year.YearName}));
const staff = Leaders.map((leader) => ({
value: leader.UserID,
label: ` ${leader.UserFirstname} ${leader.UserLastname} `
}));
return ( return (
<Form <Form
@@ -93,7 +89,7 @@ const ModuleForm = ({originalModule, onSubmit, onCancel}) => {
value={module.ModuleName} value={module.ModuleName}
onChange={(value) => handleChange('ModuleName', value)} onChange={(value) => handleChange('ModuleName', value)}
/> />
{ isYearsLoading ? <Text>Loading Levels...</Text> : {isYearsLoading ? <Text>Loading Levels...</Text> :
<Form.InputSelect <Form.InputSelect
label='Module Level' label='Module Level'
prompt={'Select module level...'} prompt={'Select module level...'}
@@ -106,18 +102,23 @@ const ModuleForm = ({originalModule, onSubmit, onCancel}) => {
<Form.InputSelect <Form.InputSelect
label='Module cohort' label='Module cohort'
prompt={'Select module cohort...'}
options={cohorts}
value={module.ModuleYearID} value={module.ModuleYearID}
onChange={(value) => handleChange('ModuleYearID', value)} onChange={(value) => handleChange('ModuleYearID', value)}
prompt={'Select module cohort...'}
options={cohorts}
isLoading={isYearsLoading}
/> />
<Form.InputText <Form.InputSelect
label='Module Leader Name' label='Module Leader'
value={module.ModuleLeaderName} value={module.ModuleLeaderID}
onChange={(value) => handleChange('ModuleLeaderName', value)} onChange={(value) => handleChange('ModuleLeaderID', value)}
prompt={'Select module leader...'}
options={staff}
isLoading={isLeadersLoading}
/> />
<Form.InputText <Form.InputText
label='Module Image URL' label='Module Image URL'
value={module.ModuleImageURL} value={module.ModuleImageURL}
@@ -131,9 +132,6 @@ const ModuleForm = ({originalModule, onSubmit, onCancel}) => {
); );
}; };
const styles = StyleSheet.create({ // const styles = StyleSheet.create({});
formContainer: {},
item: {},
});
export default ModuleForm; export default ModuleForm;
+9 -16
View File
@@ -1,33 +1,26 @@
import {useState, useEffect} from "react"; // import {useState, useEffect} from "react";
import {LogBox, StyleSheet, 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 API from "../API/API";
// import initialModules from "../../data/modules.js"; // import initialModules from "../../data/modules.js";
// import RenderCount from "../UI/RenderCount"; // 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";
const ModuleListScreen = ({navigation}) => { const ModuleListScreen = ({navigation}) => {
// Initialisation ------------- // Initialisation -------------
// 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 ----------------------
const [modules, setModules] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const loadModules = async (endpoint) => { const [modules, setModules, isLoading, loadModules] = useLoad(modulesEndpoint);
const response = await API.get(endpoint);
setIsLoading(false);
if (response.isSuccess) setModules(response.result);
};
useEffect(() => {
loadModules(modulesEndpoint)
}, []);
// Handlers ------------------- // Handlers -------------------
@@ -79,7 +72,7 @@ const ModuleListScreen = ({navigation}) => {
); );
}; };
const styles = StyleSheet.create({}); // const styles = StyleSheet.create({});
export default ModuleListScreen; export default ModuleListScreen;