Skip to content

Commit

Permalink
Merge pull request #73 from FYP-2024-IQMA/SCRUM-130-Fix-Section-Lesso…
Browse files Browse the repository at this point in the history
…n-Introduction-Video-Bug

SCRUM-130 setPlaying false when user click continue
  • Loading branch information
xuanli286 authored Sep 16, 2024
2 parents 213fa61 + b596839 commit a2e6b65
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
29 changes: 15 additions & 14 deletions backend/dist/services/clickstreamService.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,33 @@ const s3 = new aws_sdk_1.default.S3({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
});
function uploadToS3(queue, userID, newClickstream) {
function uploadToS3(queue, newClickstream) {
return __awaiter(this, void 0, void 0, function* () {
const key = `${queue}/${userID}.json`;
const key = `${queue}/${newClickstream.userID}.json`;
const params = {
Bucket: `isb-raw-data-athena`,
Bucket: 'isb-raw-data-athena',
Key: key,
};
let existingClickstream = [];
try {
const existingData = yield s3.getObject(params).promise();
let existingClickstream = JSON.parse(existingData.Body.toString('utf-8'));
if (Array.isArray(existingClickstream)) {
existingClickstream.push(JSON.parse(newClickstream));
}
else {
existingClickstream = [existingClickstream, JSON.parse(newClickstream)];
}
yield s3.putObject(Object.assign(Object.assign({}, params), { Body: JSON.stringify(existingClickstream), ContentType: "application/json" })).promise();
let fileContent = existingData.Body.toString('utf-8');
existingClickstream = fileContent
.split('\n')
.filter((line) => line.trim().length > 0)
.map((line) => JSON.parse(line));
}
catch (error) {
if (error.code === 'NoSuchKey') {
yield s3.upload(Object.assign(Object.assign({}, params), { Body: JSON.stringify([JSON.parse(newClickstream)]), ContentType: "application/json" })).promise();
console.log("Creating new file");
}
else {
console.error("Error uploading to S3", error);
}
}
existingClickstream.push(newClickstream);
const lineDelimitedJson = existingClickstream.map(item => JSON.stringify(item)).join('\n');
s3.putObject(Object.assign(Object.assign({}, params), { Body: lineDelimitedJson, ContentType: "application/json" })).promise();
});
}
const QUEUE_NAMES = ['timeTaken', 'attemptsTaken'];
Expand All @@ -59,9 +60,9 @@ function consumeMessage() {
channel.consume(queue, (message) => __awaiter(this, void 0, void 0, function* () {
if (message !== null) {
const data = message.content.toString();
const parsedData = JSON.parse(data);
let parsedData = JSON.parse(data);
try {
yield uploadToS3(queue, parsedData.userID, data);
yield uploadToS3(queue, parsedData);
channel.ack(message);
console.log(message);
}
Expand Down
6 changes: 2 additions & 4 deletions frontend/iQMA-Skills-Builder/app/Lesson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function Lesson() {
}, [navigation]);

const handlePress = () => {
setPlaying(false);
router.push({
pathname: 'VideoQuiz',
// params: {sectionID: sectionID, unitID: unitID, lessonID: '1a'},
Expand Down Expand Up @@ -75,15 +76,12 @@ export default function Lesson() {
}, [sectionID, unitID]);

const onStateChange = (state: string) => {
if (state === 'ended') {
if (state === 'ended' || state === 'paused') {
setPlaying(false);
}
if (state === 'playing') {
setPlaying(true);
}
if (state === 'paused') {
setPlaying(false);
}
};

return (
Expand Down
6 changes: 2 additions & 4 deletions frontend/iQMA-Skills-Builder/app/SectionIntroduction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,20 @@ export default function SectionIntroduction() {

const handlePress = () => {
// router.push('UnitIntroduction');
setPlaying(false);
router.push({
pathname: 'UnitIntroduction',
params: {sectionID, unitID, lessonID},
});
};

const onStateChange = (state: string) => {
if (state === 'ended') {
if (state === 'ended' || state === 'paused') {
setPlaying(false);
}
if (state === 'playing') {
setPlaying(true);
}
if (state === 'paused') {
setPlaying(false);
}
};

return (
Expand Down

0 comments on commit a2e6b65

Please sign in to comment.