Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/FYP-2024-IQMA/fyp2024 in…
Browse files Browse the repository at this point in the history
…to SCRUM-110-Set-up-RabbitMQ
  • Loading branch information
xuanli286 committed Sep 10, 2024
2 parents 88c9594 + 8569859 commit d4c5e40
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 42 deletions.
4 changes: 2 additions & 2 deletions backend/dist/services/lessonService.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ function getAllLessons(sectionID, unitID) {
else {
const formattedLessons = data.map((lesson) => {
let formattedLessonURL = extractYouTubeID(lesson.lessonURL) || lesson.lessonURL;
console.log(formattedLessonURL);
// console.log(formattedLessonURL);
let description = lesson.lessonDescription;
console.log(description);
// console.log(description);
let formattedDescription = description
? description.split(/\r?\n/)
: null;
Expand Down
4 changes: 2 additions & 2 deletions backend/src/services/lessonService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ export async function getAllLessons(sectionID: string, unitID: string) {
const formattedLessons = data.map((lesson: any) => {
let formattedLessonURL =
extractYouTubeID(lesson.lessonURL) || lesson.lessonURL;
console.log(formattedLessonURL);
// console.log(formattedLessonURL);
let description = lesson.lessonDescription;
console.log(description);
// console.log(description);
let formattedDescription: string[] | null = description
? description.split(/\r?\n/)
: null;
Expand Down
155 changes: 155 additions & 0 deletions frontend/iQMA-Skills-Builder/app/CheatSheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import {ScrollView, StyleSheet, Text, View, SafeAreaView} from 'react-native';
import React, {useState, useLayoutEffect, useEffect} from 'react';
import {CustomButton} from '@/components/CustomButton';
import {router, useLocalSearchParams} from 'expo-router';
import {useNavigation} from '@react-navigation/native';
import ProgressBar from '@/components/ProgressBar';
import { OverviewCard } from '@/components/OverviewCard';
import * as lessonEndpoints from '@/helpers/lessonEndpoints';
import { formatUnit } from '@/helpers/formatUnitID';

const formatCheatSheet = (cheatsheet: any) => {
if (Array.isArray(cheatsheet)) {
if (cheatsheet.length === 0) {
return (
<OverviewCard
isError={true}
text="Lesson Cheatsheet is not available. Please check with your administrator."
/>
);
}
return cheatsheet.map((item, index) => (
<OverviewCard key={index} text={item}></OverviewCard>
));
} else {
if (Object.keys(cheatsheet).length === 0) {
return (
<OverviewCard
isError={true}
text="Lesson Cheatsheet is not available. Please check with your administrator."
/>
);
}
return Object.entries(cheatsheet).map(([title, text], index) => (
<OverviewCard
isCheatsheetObject={true}
key={index}
title={title}
text={text as string | string[]}
></OverviewCard>
));
}
};

// where things show up
export default function CheatSheet() {
const navigation = useNavigation();
const {sectionID, unitID} = useLocalSearchParams();
const [lessons, setLessons] = useState<any[]>([]);
const [unitNumber, setUnitNumber] = useState<string>('');

useLayoutEffect(() => {
navigation.setOptions({
headerTitle: () => (
<ProgressBar progress={0.25} isQuestionnaire={false}/>
),
});
}, [navigation]);

useEffect(() => {
if (sectionID && unitID) {
(async () => {

const lessonDetails = await lessonEndpoints.getAllLesson(
sectionID as string,
unitID as string
);

setLessons(lessonDetails);
})();
setUnitNumber(formatUnit(unitID as string));
}
}, [sectionID, unitID]);

const handlePress = () => {
// router.push("Lesson")
router.push({
pathname: "Lesson", // to be replaced with Unit Reality Check page
params: {sectionID: sectionID, unitID: unitID},
});
};

return (
<ScrollView style={styles.container}>
<View style={{marginBottom: 20}}>
<View style={{flex: 1}}>
<Text
style={{
fontSize: 14,
fontWeight: 'bold',
color: '#4143A3',
marginBottom: 20,
marginHorizontal: 10,
}}
>
Unit {unitNumber}: Cheat Sheet
</Text>
{lessons.length > 0 ? (
lessons.map((lesson, index) => (
<View key={index} style={[styles.cheatSheet]}>
<Text style={styles.title}>
{lesson.lessonName}
</Text>
{formatCheatSheet(lesson.lessonCheatSheet)}
</View>
))
) : (
<OverviewCard
text="Lesson Cheatsheets are not available. Please check with your administrator."
isError={true}
></OverviewCard>
)}
</View>
<View style={styles.buttonContainer}>
<CustomButton
label="continue"
backgroundColor="white"
onPressHandler={handlePress}
/>
</View>
</View>
</ScrollView>
);
}

const styles = StyleSheet.create({
container: {
backgroundColor: '#FFFFFF',
padding: 20,
},
title: {
fontSize: 14,
fontWeight: 'bold',
color: '#4143A3',
marginBottom: 20,
},
buttonContainer: {
alignItems: 'center',
justifyContent: 'flex-end',
paddingBottom: 20,
},
cheatSheet: {
borderColor: '#C3B1FF',
borderRadius: 10,
borderWidth: 2,
padding: 10,
marginBottom: 20,
backgroundColor: '#FFFFFF',
// shadow properties
shadowColor: '#000',
shadowOffset: {width: 0, height: 4},
shadowOpacity: 0.3,
shadowRadius: 6,
elevation: 5,
},
});
21 changes: 11 additions & 10 deletions frontend/iQMA-Skills-Builder/app/Lesson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default function Lesson() {

return (
<View style={styles.container}>
<View>
<View style={{flexGrow: 1}}>
<SectionCard
title={`SECTION ${sectionNumber}, UNIT ${unitNumber}`}
subtitle={unitName}
Expand All @@ -95,7 +95,14 @@ export default function Lesson() {
{lessonName}
</Text>

<OverviewCard text={lessonDescription!}></OverviewCard>
{lessonDescription ? (
<OverviewCard text={lessonDescription!}></OverviewCard>
) : (
<OverviewCard
isError={true}
text="Lesson Description is not available. Please check with your administrator."
/>
)}

{videoId ? (
<YoutubePlayer
Expand All @@ -107,16 +114,11 @@ export default function Lesson() {
) : (
<OverviewCard
isError={true}
text="Video not available. Please check with your administrator."
text="Video is not available. Please check with your administrator."
/>
)}
</View>
<View
style={{
alignSelf: 'center',
bottom: 20,
}}
>
<View style={{alignItems: 'center', justifyContent: 'flex-end'}}>
<CustomButton
label="continue"
backgroundColor="white"
Expand All @@ -132,6 +134,5 @@ const styles = StyleSheet.create({
backgroundColor: '#FFFFFF',
padding: 20,
flex: 1,
justifyContent: 'space-between',
},
});
14 changes: 4 additions & 10 deletions frontend/iQMA-Skills-Builder/app/SectionIntroduction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function SectionIntroduction() {

return (
<View style={styles.container}>
<View>
<View style={{flexGrow: 1}}>
<SectionCard
title={`SECTION ${sectionNumber}`}
subtitle={sectionName}
Expand All @@ -91,17 +91,12 @@ export default function SectionIntroduction() {
) : (
<OverviewCard
isError={true}
text="Video not available. Please check with your administrator."
text="Video is not available. Please check with your administrator."
/>
)}
</View>

<View
style={{
alignSelf: 'center',
bottom: 20,
}}
>
<View style={{alignItems: 'center', justifyContent: 'flex-end'}}>
<CustomButton
label="continue"
backgroundColor="white"
Expand All @@ -116,7 +111,6 @@ const styles = StyleSheet.create({
container: {
backgroundColor: '#FFFFFF',
padding: 20,
flex: 1,
justifyContent: 'space-between',
flex: 1,
},
});
25 changes: 13 additions & 12 deletions frontend/iQMA-Skills-Builder/app/UnitIntroduction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function UnitIntroduction() {

return (
<View style={styles.container}>
<View>
<View style={{flexGrow: 1}}>
<SectionCard
title={`SECTION ${sectionNumber}, UNIT ${unitNumber}`}
subtitle={unitName}
Expand All @@ -72,9 +72,16 @@ export default function UnitIntroduction() {
Unit {unitNumber}: Introduction
</Text>

{unitDescription.map((description, index) => (
<OverviewCard key={index} text={description} />
))}
{unitDescription.length > 0 ? (
unitDescription.map((description, index) => (
<OverviewCard key={index} text={description} />
))
) : (
<OverviewCard
isError={true}
text="Unit description is not available. Please check with your administrator."
/>
)}

<View style={{width: '100%', flexDirection: 'row-reverse'}}>
<Image
Expand All @@ -84,12 +91,7 @@ export default function UnitIntroduction() {
</View>
</View>

<View
style={{
alignSelf: 'center',
bottom: 20,
}}
>
<View style={{alignItems: 'center', justifyContent: 'flex-end'}}>
<CustomButton
label="continue"
backgroundColor="white"
Expand All @@ -104,7 +106,6 @@ const styles = StyleSheet.create({
container: {
backgroundColor: '#FFFFFF',
padding: 20,
flex: 1,
justifyContent: 'space-between',
flex: 1
},
});
5 changes: 3 additions & 2 deletions frontend/iQMA-Skills-Builder/app/screens/Chatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const saveChatHistory = async (
queryPair: queryPair,
};

const url = `${process.env.EXPO_PUBLIC_BACKEND_URL}/chat/createchathistory`;
const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/chat/createchathistory`;

const response = await fetch(url, {
method: 'POST',
Expand All @@ -100,7 +100,8 @@ const loadChatHistory = async (userId: string, sectionId: string) => {
console.log('LOAD CHAT HISTORY');

try {
const url = `${process.env.EXPO_PUBLIC_BACKEND_URL}/chat/getchathistory/${userId}/${sectionId}`;
const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/chat/getchathistory/${userId}/${sectionId}`;
console.log('URL: ', url);

const response = await fetch(url);

Expand Down
3 changes: 2 additions & 1 deletion frontend/iQMA-Skills-Builder/components/OverviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const OverviewCard = ({
<Text
style={[
styles.OverviewCardSubtitle,
isCheatsheetObject ? styles.OverviewCardSubtitleArr : {},
isError ? styles.ErrorCardSubtitle : {},
]}
>
Expand All @@ -64,7 +65,7 @@ const styles = StyleSheet.create({
backgroundColor: '#E66A63',
},
OverviewCardTitle: {
fontSize: 15,
fontSize: 14,
fontWeight: 'bold',
},
OverviewCardSubtitle: {
Expand Down
3 changes: 0 additions & 3 deletions frontend/iQMA-Skills-Builder/components/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ const ProgressBar: React.FC<ProgressBarProps> = ({
progress,
isQuestionnaire,
}) => {
// const screenWidth = Dimensions.get("window").width;
// const padding = 20;
// const progressBarWidth = screenWidth - 2 * padding - 30;

const handlePress = () => {
router.replace('Home');
Expand Down
1 change: 1 addition & 0 deletions frontend/iQMA-Skills-Builder/context/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const AuthProvider = ({children}: {children: React.ReactNode}) => {
// router.replace('VideoQuiz');
// router.replace('Lesson');
// router.replace("SectionIntroduction");
// router.replace('CheatSheet');
} else {
router.replace('IntroductionMascot');
}
Expand Down
16 changes: 16 additions & 0 deletions frontend/iQMA-Skills-Builder/helpers/lessonEndpoints.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,19 @@ export const getLessonDetails = async (
return;
}
};

export const getAllLesson = async (
sectionID: string,
unitID: string,
) => {
try {
const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/lesson/getalllessons/${sectionID}/${unitID}`;
const response = await fetch(url);
const lessonDetails = await response.json();
// console.log(lessonDetails);
return lessonDetails;
} catch (error) {
console.error('Error fetching lessonDetails:', error);
return;
}
};

0 comments on commit d4c5e40

Please sign in to comment.