Commit fef579c2 authored by Randika Monarawila's avatar Randika Monarawila

Merge branch 'KnowledgeIQFinalUI' into 'master'

Add Audio commands

See merge request !26
parents c36e6c68 a0495013
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import "./ActivityContainer.css"; import "./ActivityContainer.css";
import { PictureConcept, Arithmetic, ColourNumbers, DigitSpan, VideoPlayerScreen } from "../index"; import {
PictureConcept,
Arithmetic,
ColourNumbers,
DigitSpan,
DigitSpanController,
VideoPlayerScreen,
} from "../index";
import LetterPattern from "./mentalChronometryEval/letterPattern/LetterPattern"; import LetterPattern from "./mentalChronometryEval/letterPattern/LetterPattern";
import Coding from "./mentalChronometryEval/coding/Coding"; import Coding from "./mentalChronometryEval/coding/Coding";
import PairCancerlation from "./mentalChronometryEval/pairCancerlation/PairCancerlation"; import PairCancerlation from "./mentalChronometryEval/pairCancerlation/PairCancerlation";
...@@ -18,7 +25,7 @@ const ActivityContainer = () => { ...@@ -18,7 +25,7 @@ const ActivityContainer = () => {
setTimeout(() => { setTimeout(() => {
setIsGuideVideoClicked(state); setIsGuideVideoClicked(state);
}, 2000); }, 2000);
} };
const changeColor = () => { const changeColor = () => {
let currentDiv = document.getElementsById({ currentActivityNo }); let currentDiv = document.getElementsById({ currentActivityNo });
...@@ -109,7 +116,10 @@ const ActivityContainer = () => { ...@@ -109,7 +116,10 @@ const ActivityContainer = () => {
</div> </div>
<div id="activity-container-item-1"> <div id="activity-container-item-1">
{isGuideVideoClicked ? ( {isGuideVideoClicked ? (
<VideoPlayerScreen currentActivtyIndex={currentActivityNo} changeScreen={changeActivityScreen} /> <VideoPlayerScreen
currentActivtyIndex={currentActivityNo}
changeScreen={changeActivityScreen}
/>
) : ( ) : (
<> <>
{currentActivityNo === 1 && ( {currentActivityNo === 1 && (
...@@ -131,7 +141,7 @@ const ActivityContainer = () => { ...@@ -131,7 +141,7 @@ const ActivityContainer = () => {
<ColourNumbers nextActivity={nextActivityHandler} /> <ColourNumbers nextActivity={nextActivityHandler} />
)} )}
{currentActivityNo === 7 && ( {currentActivityNo === 7 && (
<DigitSpan nextActivity={nextActivityHandler} /> <DigitSpanController nextActivity={nextActivityHandler} />
)} )}
</> </>
)} )}
......
import React, { useState, useEffect } from "react";
import toast, { Toaster } from "react-hot-toast";
import { ContainerCard } from "../../components/index";
import Audio from "../../utility/audio";
const AudioPlayerScreen = ({ currentActivtyIndex, changeScreen }) => {
return (
<>
<div className="w-full">
<div id=" w-full h-full bg-white">
<ContainerCard>
<div>
<div >
<h2 className="text-base text-[#3d59c1] font-semibold tracking-wide uppercase mt-4">
Digit Span
</h2>
</div>
<div className="mt-10 sm:mt-0">
<Audio
currentActivtyIndex={currentActivtyIndex}
changeScreen={changeScreen}
/>
</div>
</div>
</ContainerCard>
</div>
</div>
</>
);
};
export default AudioPlayerScreen;
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { green, red } from '@mui/material/colors'; import { green, red } from "@mui/material/colors";
import Avatar from '@mui/material/Avatar'; import Avatar from "@mui/material/Avatar";
import Stack from '@mui/material/Stack'; import Stack from "@mui/material/Stack";
import MicSharpIcon from '@mui/icons-material/MicSharp'; import MicSharpIcon from "@mui/icons-material/MicSharp";
import MicOffSharpIcon from '@mui/icons-material/MicOffSharp'; import MicOffSharpIcon from "@mui/icons-material/MicOffSharp";
import VolumeUpIcon from '@mui/icons-material/VolumeUp'; import VolumeUpIcon from "@mui/icons-material/VolumeUp";
import VolumeOffIcon from '@mui/icons-material/VolumeOff'; import VolumeOffIcon from "@mui/icons-material/VolumeOff";
import Picture from '../../../../assets/digitspan.jpg'; import Picture from "../../../../assets/digitspan.jpg";
import Button from '@mui/material/Button'; import Button from "@mui/material/Button";
import Instruction1 from '../../../../assets/audio/audio.aac'; // import Instruction1 from '../../../../assets/audio/audio.aac';
import Instruction2 from '../../../../assets/audio/audio2.aac'; // import Instruction2 from '../../../../assets/audio/audio2.aac';
import Timer from "../../reasoningIqEval/timer/Timer"; import Timer from "../../reasoningIqEval/timer/Timer";
import {RecordingHandler} from "../recorder/Recorder"; import { RecordingHandler } from "../recorder/Recorder";
import "./DigitSpan.css"; import "./DigitSpan.css";
const DigitSpan = ({ GoNext, isAllCompleted }) => {
const DigitSpan = ({ nextActivity }) => {
const [buttonClicked, setButtonClicked] = useState(1); const [buttonClicked, setButtonClicked] = useState(1);
const [audio, setAudio] = useState(Instruction1); const [audio, setAudio] = useState("Instruction1");
const [allCompleted, setAllCompleted] = useState(false); const [allCompleted, setAllCompleted] = useState(false);
const [activityIndex, setActivityIndex] = useState(1); const [activityIndex, setActivityIndex] = useState(1);
const switchActivityHandler = () => { // const switchActivityHandler = ({switchActivity}) => {
let activityNo = activityIndex + 1; // let activityNo = activityIndex + 1;
setActivityIndex(activityNo); // setActivityIndex(activityNo);
// switch question // // switch question
console.log('switch'); // console.log("switch");
// if(activityNo < 4){ // // if(activityNo < 4){
// } // // }
// else{ // // else{
// setAllCompleted(true); // // setAllCompleted(true);
// } // // }
}; // };
// const audioFiles =[{source: Instruction1}, // const audioFiles =[{source: Instruction1},
// {source: Instruction2}]; // {source: Instruction2}];
...@@ -53,30 +51,29 @@ const DigitSpan = ({ nextActivity }) => { ...@@ -53,30 +51,29 @@ const DigitSpan = ({ nextActivity }) => {
// }) // })
// } // }
// } // }
useEffect(() => { useEffect(() => {
console.log('rec'); console.log("rec");
RecordingHandler(`DS.wav`, activityIndex); RecordingHandler(`DS.wav`, activityIndex);
}, [activityIndex]); }, [activityIndex]);
// const switchAudio = () => {
// const switchAudio = () => { // if (audio < audioFiles.length - 1) {
// setActivityIndex(activityIndex+1)
// if (audio < audioFiles.length - 1) {
// setActivityIndex(activityIndex+1)
// this.setState({ // this.setState({
// audio: audioFiles2[activityIndex] // audio: audioFiles2[activityIndex]
// }); // });
// //restart playlist // //restart playlist
// } else { // } else {
// console.log('ERROR'); // console.log('ERROR');
// } // }
// } // }
// useEffect(() => { // useEffect(() => {
// console.log('rec'); // console.log('rec');
// RecordingHandler(`CN.wav`, activityIndex); // RecordingHandler(`CN.wav`, activityIndex);
// }, [activityIndex]); // }, [activityIndex]);
return ( return (
<div className="container"> <div className="container">
...@@ -87,7 +84,7 @@ const DigitSpan = ({ nextActivity }) => { ...@@ -87,7 +84,7 @@ const DigitSpan = ({ nextActivity }) => {
src={Picture} src={Picture}
/> />
</div> */} </div> */}
{allCompleted && ( {isAllCompleted && (
<div className="w-4/6 h-4/6 m-auto"> <div className="w-4/6 h-4/6 m-auto">
{" "} {" "}
<img <img
...@@ -97,8 +94,13 @@ const DigitSpan = ({ nextActivity }) => { ...@@ -97,8 +94,13 @@ const DigitSpan = ({ nextActivity }) => {
/> />
</div> </div>
)} )}
<Stack direction="row" spacing={2} justifyContent="center" alignItems="center"> <Stack
{/* {buttonClicked === 1 && ( direction="row"
spacing={2}
justifyContent="center"
alignItems="center"
>
{/* {buttonClicked === 1 && (
<Avatar sx={{ bgcolor: green[500], width: 100, height: 100}} <Avatar sx={{ bgcolor: green[500], width: 100, height: 100}}
onClick={()=> {setButtonClicked(2)}}> onClick={()=> {setButtonClicked(2)}}>
<MicSharpIcon sx={{ fontSize: 60 }}/> <MicSharpIcon sx={{ fontSize: 60 }}/>
...@@ -110,7 +112,7 @@ const DigitSpan = ({ nextActivity }) => { ...@@ -110,7 +112,7 @@ const DigitSpan = ({ nextActivity }) => {
<MicOffSharpIcon sx={{ fontSize: 60 }}/> <MicOffSharpIcon sx={{ fontSize: 60 }}/>
</Avatar> </Avatar>
)} */} )} */}
{/* {buttonClicked === 1 && ( {/* {buttonClicked === 1 && (
<Avatar sx={{ bgcolor: green[500], width: 100, height: 100}} <Avatar sx={{ bgcolor: green[500], width: 100, height: 100}}
onClick={()=> {}}> onClick={()=> {}}>
<VolumeUpIcon sx={{ fontSize: 60 }}/> <VolumeUpIcon sx={{ fontSize: 60 }}/>
...@@ -122,8 +124,8 @@ const DigitSpan = ({ nextActivity }) => { ...@@ -122,8 +124,8 @@ const DigitSpan = ({ nextActivity }) => {
<VolumeOffIcon sx={{ fontSize: 60 }}/> <VolumeOffIcon sx={{ fontSize: 60 }}/>
</Avatar> </Avatar>
)} */} )} */}
{!allCompleted && <Timer switchActivity={switchActivityHandler} />} {!isAllCompleted && <Timer switchActivity={GoNext} />}
</Stack> </Stack>
{/* <Button {/* <Button
onClick={() => { onClick={() => {
nextActivity(); nextActivity();
...@@ -135,4 +137,4 @@ const DigitSpan = ({ nextActivity }) => { ...@@ -135,4 +137,4 @@ const DigitSpan = ({ nextActivity }) => {
); );
}; };
export default DigitSpan; export default DigitSpan;
\ No newline at end of file
import React, { useState, useEffect } from "react";
import { DigitSpan } from "../../..";
import AudioPlayerScreen from "../../audioPlayerScreen";
const DigitSpanController = () => {
const activityCount = 4;
const [currentActivityNo, setCurrentActivityNo] = useState(1);
const [isAudioCompleted, setIsAudioCompleted] = useState(false);
const [isAllCompleted, setIsAllCompleted] = useState(false);
const nextActivityHandler = () => {
if (currentActivityNo < activityCount - 1) {
setCurrentActivityNo(currentActivityNo + 1);
} else {
setIsAllCompleted(true);
}
setIsAudioCompleted(false);
};
const StartRecording = (state) => {
setTimeout(() => {
setIsAudioCompleted(true);
}, 1000);
};
return (
<>
<div className="w-full h-full">
<div>
{!isAudioCompleted ? (
<AudioPlayerScreen
currentActivtyIndex={currentActivityNo}
changeScreen={StartRecording}
/>
) : (
<>
<DigitSpan
GoNext={nextActivityHandler}
isAllCompleted={isAllCompleted}
/>
</>
)}
</div>
</div>
</>
);
};
export default DigitSpanController;
...@@ -10,3 +10,5 @@ export { default as ColourNumbers } from "./activities/knowledgeIqEval/colourNum ...@@ -10,3 +10,5 @@ export { default as ColourNumbers } from "./activities/knowledgeIqEval/colourNum
export { default as DigitSpan } from "./activities/knowledgeIqEval/digitSpan/DigitSpan"; export { default as DigitSpan } from "./activities/knowledgeIqEval/digitSpan/DigitSpan";
export { default as EthicalClearenceScreen } from "./activities/ethicalClearence"; export { default as EthicalClearenceScreen } from "./activities/ethicalClearence";
export { default as VideoPlayerScreen } from "./activities/videoPlayer"; export { default as VideoPlayerScreen } from "./activities/videoPlayer";
export { default as AudioPlayerScreen } from "./activities/audioPlayerScreen";
export { default as DigitSpanController } from "./activities/knowledgeIqEval/digitSpan/digitSpanController";
import React, { useState, useEffect, useRef } from "react";
import A1 from "../Audio/A1.mp3";
import A2 from "../Audio/A2.mp3";
const Audio = ({ currentActivtyIndex, changeScreen }) => {
const myAudio = useRef();
const [audio, setAudio] = useState("");
const vidRef = useRef();
useEffect(() => {
switch (currentActivtyIndex) {
case 1:
setAudio(A1);
break;
case 2:
setAudio(A2);
break;
case 3:
setAudio(A1);
break;
case 4:
setAudio(A2);
break;
case 5:
setAudio(A1);
break;
default:
}
const timer = setTimeout(() => {
myAudio.current.play();
}, 3000);
return () => clearTimeout(timer);
}, []);
const myCallback = () => {
changeScreen(false);
};
// const audio = "A2.mp3";
const handleBeep = () => {
console.log("Clicked");
};
return (
<div className="flex items-center">
{Audio && (
<>
<audio
id="beep"
ref={myAudio}
src={audio}
type="audio"
onEnded={() => myCallback()}
/>
<button className="text-black" onClick={handleBeep}>
Start
</button>
</>
)}
</div>
);
};
export default Audio;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment