From 165c8bbb18bedcd1312282b3d03c6c19e06a6753 Mon Sep 17 00:00:00 2001 From: rrachea Date: Mon, 21 Oct 2024 22:16:47 +0800 Subject: [PATCH] edit calculation to count once only --- .../iQMA-Skills-Builder/app/Assessment.tsx | 24 +++++++++++ .../iQMA-Skills-Builder/app/KeyTakeaway.tsx | 23 +---------- .../app/SelfReflection.tsx | 40 +++++++++---------- .../iQMA-Skills-Builder/app/VideoQuiz.tsx | 22 ++++++++++ 4 files changed, 67 insertions(+), 42 deletions(-) diff --git a/frontend/iQMA-Skills-Builder/app/Assessment.tsx b/frontend/iQMA-Skills-Builder/app/Assessment.tsx index 450fbd9..6fa7d84 100644 --- a/frontend/iQMA-Skills-Builder/app/Assessment.tsx +++ b/frontend/iQMA-Skills-Builder/app/Assessment.tsx @@ -142,6 +142,30 @@ export default function Assessment() { currentUser.sub, questions[currentQnsIdx].quizID ); + + try { + const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/accounts/updatepoints`; + + let points = await AsyncStorage.getItem( + 'totalPoints' + ); + const numPoints = parseInt(points as string); + + const data = { + userID: currentUser.sub, + points: numPoints, + }; + + const response = await axios.patch(url, data); + const result = await response.data; + console.log('Points successfully updated:', result); + AsyncStorage.setItem('totalPoints', '0'); + } catch (error: any) { + console.error( + 'Error updating points:', + error.response.data + ); + } } } catch (error) { console.error('Error in Assessment:', error); diff --git a/frontend/iQMA-Skills-Builder/app/KeyTakeaway.tsx b/frontend/iQMA-Skills-Builder/app/KeyTakeaway.tsx index a23315a..2bad0d1 100644 --- a/frontend/iQMA-Skills-Builder/app/KeyTakeaway.tsx +++ b/frontend/iQMA-Skills-Builder/app/KeyTakeaway.tsx @@ -36,7 +36,7 @@ export default function KeyTakeaway() { }); }, [navigation]); - const handlePress = () => { + const handlePress = async () => { let nextLessonIdx = parseInt(currentLessonIdx as string) + 1; let pathName = 'Lesson'; @@ -108,27 +108,6 @@ export default function KeyTakeaway() { totalLesson ) { (async () => { - try { - const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/accounts/updatepoints`; - - let points = await AsyncStorage.getItem('totalPoints'); - const numPoints = parseInt(points as string); - - const data = { - userID: currentUser.sub, - points: numPoints, - }; - - const response = await axios.patch(url, data); - const result = await response.data; - console.log('Points successfully updated:', result); - AsyncStorage.setItem('totalPoints', '0'); - } catch (error: any) { - console.error( - 'Error updating points:', - error.response.data - ); - } try { const unitDetails = await unitEndpoints.getUnitDetails( sectionID as string, diff --git a/frontend/iQMA-Skills-Builder/app/SelfReflection.tsx b/frontend/iQMA-Skills-Builder/app/SelfReflection.tsx index d6ad198..5e44d70 100644 --- a/frontend/iQMA-Skills-Builder/app/SelfReflection.tsx +++ b/frontend/iQMA-Skills-Builder/app/SelfReflection.tsx @@ -60,26 +60,6 @@ export default function SelfReflection() { startTimer(); if (sectionID && unitID) { (async () => { - try { - const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/accounts/updatepoints`; - - let points = await AsyncStorage.getItem('totalPoints'); - const numPoints = parseInt(points as string); - - const data = { - userID: currentUser.sub, - points: numPoints, - }; - - const response = await axios.patch(url, data); - - AsyncStorage.setItem('totalPoints', '0'); - } catch (error: any) { - console.error( - 'Error updating points:', - error.response.data - ); - } try { const unitDetails = await unitEndpoints.getUnitDetails( sectionID as string, @@ -114,6 +94,26 @@ export default function SelfReflection() { currentUser.sub, parseInt(quizID as string) ); + try { + const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/accounts/updatepoints`; + + let points = await AsyncStorage.getItem('totalPoints'); + const numPoints = parseInt(points as string); + + const data = { + userID: currentUser.sub, + points: numPoints, + }; + + const response = await axios.patch(url, data); + + AsyncStorage.setItem('totalPoints', '0'); + } catch (error: any) { + console.error( + 'Error updating points:', + error.response.data + ); + } } } catch (error) { console.error( diff --git a/frontend/iQMA-Skills-Builder/app/VideoQuiz.tsx b/frontend/iQMA-Skills-Builder/app/VideoQuiz.tsx index adf9fd9..9d3791e 100644 --- a/frontend/iQMA-Skills-Builder/app/VideoQuiz.tsx +++ b/frontend/iQMA-Skills-Builder/app/VideoQuiz.tsx @@ -134,6 +134,28 @@ export default function VideoQuiz() { currentUser.sub, questions[currentQnsIdx].quizID ); + + try { + const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/accounts/updatepoints`; + + let points = await AsyncStorage.getItem('totalPoints'); + const numPoints = parseInt(points as string); + + const data = { + userID: currentUser.sub, + points: numPoints, + }; + + const response = await axios.patch(url, data); + const result = await response.data; + console.log('Points successfully updated:', result); + AsyncStorage.setItem('totalPoints', '0'); + } catch (error: any) { + console.error( + 'Error updating points:', + error.response.data + ); + } } let pathName = 'KeyTakeaway';