Commit 36dfc9ae authored by janithgamage1.ed's avatar janithgamage1.ed

fix: update

Desc : update project
parent 332f3fea
...@@ -19,11 +19,13 @@ import ReportCard from "components/cards/statistics/ReportCard"; ...@@ -19,11 +19,13 @@ import ReportCard from "components/cards/statistics/ReportCard";
import { itemResultProps, selectedCommonDataProps, selectedItemContentProps } from "./types/types"; import { itemResultProps, selectedCommonDataProps, selectedItemContentProps } from "./types/types";
import CircularWithPath from "components/@extended/progress/CircularWithPath"; import CircularWithPath from "components/@extended/progress/CircularWithPath";
import useAuth from "hooks/useAuth";
import { useParams } from "react-router"; import { useParams } from "react-router";
import Webcam from 'react-webcam'; import Webcam from 'react-webcam';
import { useDispatch, useSelector } from "store"; import { useDispatch, useSelector } from "store";
import { CalculateMarks, toInitialState } from "store/reducers/marksCalculator"; import { CalculateMarks, toInitialState } from "store/reducers/marksCalculator";
import { openSnackbar } from "store/reducers/snackbar"; import { openSnackbar } from "store/reducers/snackbar";
import { fetchUserProgress, updateUserProgress, toInitialState as userProgressToInitialState } from "store/reducers/userProgress";
// action style // action style
const actionSX = { const actionSX = {
...@@ -49,8 +51,9 @@ const Tutorial = () => { ...@@ -49,8 +51,9 @@ const Tutorial = () => {
const theme = useTheme(); const theme = useTheme();
const dispatch = useDispatch(); const dispatch = useDispatch();
const { marksCalculator, error, success, isLoading } = useSelector(state => state.marksCalculator); const { marksCalculator, error, success, isLoading } = useSelector(state => state.marksCalculator);
const { userProgress } = useSelector(state => state.userProgress); const { userProgress, error: errorUserProgress, isLoading: isLoadingUserProgress, success: successUserProgress } = useSelector(state => state.userProgress);
const { curriculumIndex, tutorialIndex } = useParams(); const { curriculumIndex, tutorialIndex } = useParams();
const { user } = useAuth()
const [data, setData] = useState<tutorialTypeUserProgress>() const [data, setData] = useState<tutorialTypeUserProgress>()
const [selectedItem, setSelectedItem] = useState<{ selectedCommonData: selectedCommonDataProps | null, backgroundColor: any | null }>({ const [selectedItem, setSelectedItem] = useState<{ selectedCommonData: selectedCommonDataProps | null, backgroundColor: any | null }>({
...@@ -79,7 +82,7 @@ const Tutorial = () => { ...@@ -79,7 +82,7 @@ const Tutorial = () => {
setData(selectedTutorial); setData(selectedTutorial);
} }
} }
}, [userProgress]); }, [userProgress]);
const handleItemClick = (item: selectedCommonDataProps, backgroundColor: any) => { const handleItemClick = (item: selectedCommonDataProps, backgroundColor: any) => {
setSelectedItem({ setSelectedItem({
...@@ -127,11 +130,17 @@ const Tutorial = () => { ...@@ -127,11 +130,17 @@ const Tutorial = () => {
//alert model //alert model
const [openModel, setOpenModel] = useState(false); const [openModel, setOpenModel] = useState(false);
const [modelOpenFor, setModelOpenFor] = useState<"Practice" | "Complete">("Practice")
const handleModelClose = () => { const handleModelClose = () => {
setOpenModel(!openModel); setOpenModel(!openModel);
}; };
const handleModelOpen = (modelFor: "Practice" | "Complete") => {
setModelOpenFor(modelFor)
setOpenModel(true);
};
// web cam // web cam
const webcamRef = useRef<Webcam>(null); const webcamRef = useRef<Webcam>(null);
const [capturedImage, setCapturedImage] = useState<string | null>(null); const [capturedImage, setCapturedImage] = useState<string | null>(null);
...@@ -147,7 +156,7 @@ const Tutorial = () => { ...@@ -147,7 +156,7 @@ const Tutorial = () => {
const [uploadImage, setUploadImage] = useState<any>(); const [uploadImage, setUploadImage] = useState<any>();
const PracticeTask = (uploadImage: any, imgData: any, title: string) => { const TaskTrigger = (uploadImage: any, imgData: any, title: string) => {
if (itemPracticeReferenceData == "capture") { if (itemPracticeReferenceData == "capture") {
if (typeof imgData === 'string' && imgData.trim() !== '') { if (typeof imgData === 'string' && imgData.trim() !== '') {
const curriculumIndex: number = 1; const curriculumIndex: number = 1;
...@@ -220,7 +229,7 @@ const Tutorial = () => { ...@@ -220,7 +229,7 @@ const Tutorial = () => {
}) })
); );
} }
} else if (itemPracticeReferenceData == "upload") { } else if (itemPracticeReferenceData == "upload") {
const curriculumIndex: number = 1; const curriculumIndex: number = 1;
const tutorialIndex: number = 1; const tutorialIndex: number = 1;
const imageData: any = uploadImage[0]; // Your image data const imageData: any = uploadImage[0]; // Your image data
...@@ -265,7 +274,6 @@ const Tutorial = () => { ...@@ -265,7 +274,6 @@ const Tutorial = () => {
dispatch(CalculateMarks(curriculumIndex, tutorialIndex, imageData, targetClass)); dispatch(CalculateMarks(curriculumIndex, tutorialIndex, imageData, targetClass));
} }
} }
/** /**
...@@ -305,10 +313,59 @@ const Tutorial = () => { ...@@ -305,10 +313,59 @@ const Tutorial = () => {
close: true close: true
}) })
); );
if (modelOpenFor == "Complete") {
dispatch(updateUserProgress(
user?.id!,
userProgress?.curriculums?.[parseInt(curriculumIndex!)].curriculumCode!,
data?.tutorialCode!,
selectedItemContent?.title!,
((selectedItemContent?.taskItemMark! * parseInt(marksCalculator?.confidence!)) / 100)!,
0
))
}
dispatch(toInitialState()) dispatch(toInitialState())
} }
}, [success]) }, [success])
// handel error
useEffect(() => {
if (errorUserProgress != null) {
dispatch(
openSnackbar({
open: true,
//@ts-ignore
message: errorUserProgress ? errorUserProgress.Message : "Something went wrong ...",
variant: 'alert',
alert: {
color: 'error'
},
close: true
})
);
dispatch(userProgressToInitialState())
}
}, [errorUserProgress])
// handel success
useEffect(() => {
if (successUserProgress != null) {
dispatch(
openSnackbar({
open: true,
message: successUserProgress,
variant: 'alert',
alert: {
color: 'success'
},
close: true
})
);
dispatch(fetchUserProgress(user?.id!));
dispatch(userProgressToInitialState())
}
}, [successUserProgress])
return ( return (
<> <>
<Grid container spacing={2}> <Grid container spacing={2}>
...@@ -524,7 +581,7 @@ const Tutorial = () => { ...@@ -524,7 +581,7 @@ const Tutorial = () => {
endIcon={<PlayCircleOutlined />} endIcon={<PlayCircleOutlined />}
fullWidth fullWidth
sx={{ my: 1, width: "100%", height: "100%" }} sx={{ my: 1, width: "100%", height: "100%" }}
onClick={() => { setOpenModel(true) }} onClick={() => { handleModelOpen("Practice") }}
color="warning" color="warning"
size="small" size="small"
> >
...@@ -537,7 +594,7 @@ const Tutorial = () => { ...@@ -537,7 +594,7 @@ const Tutorial = () => {
endIcon={<CheckOutlined />} endIcon={<CheckOutlined />}
fullWidth fullWidth
sx={{ my: 1, width: "100%", height: "100%" }} sx={{ my: 1, width: "100%", height: "100%" }}
onClick={() => { }} onClick={() => { handleModelOpen("Complete") }}
color="success" color="success"
size="small" size="small"
> >
...@@ -592,7 +649,7 @@ const Tutorial = () => { ...@@ -592,7 +649,7 @@ const Tutorial = () => {
sx={{ '& .MuiDialog-paper': { p: 0 }, transition: 'transform 225ms' }} sx={{ '& .MuiDialog-paper': { p: 0 }, transition: 'transform 225ms' }}
aria-describedby="alert-dialog-slide-description" aria-describedby="alert-dialog-slide-description"
> >
<DialogTitle>Practice</DialogTitle> <DialogTitle>{modelOpenFor} Item</DialogTitle>
<Divider /> <Divider />
<DialogContent sx={{ p: 2.5 }}> <DialogContent sx={{ p: 2.5 }}>
<Grid container spacing={2}> <Grid container spacing={2}>
...@@ -649,8 +706,8 @@ const Tutorial = () => { ...@@ -649,8 +706,8 @@ const Tutorial = () => {
secondary="To Complete the task you should get 85% or higher of the task mark" color={theme.palette.success.dark} /> secondary="To Complete the task you should get 85% or higher of the task mark" color={theme.palette.success.dark} />
</Grid> </Grid>
<Grid item md={12}> <Grid item md={12}>
<Button variant="contained" color="success" onClick={() => { PracticeTask(uploadImage, webcamRef.current?.getScreenshot(), selectedItemContent?.title!) }} fullWidth disabled={isLoading}> <Button variant="contained" color="success" onClick={() => { TaskTrigger(uploadImage, webcamRef.current?.getScreenshot(), selectedItemContent?.title!) }} fullWidth disabled={isLoading && isLoadingUserProgress}>
{isLoading ? <CircularWithPath /> : <>Get Result</>} {isLoading && isLoadingUserProgress ? <CircularWithPath /> : <>{modelOpenFor} Task</>}
</Button> </Button>
</Grid> </Grid>
</Grid> </Grid>
......
...@@ -125,7 +125,7 @@ export function fetchUserProgress(userId: string) { ...@@ -125,7 +125,7 @@ export function fetchUserProgress(userId: string) {
* @param updatedUserProgress * @param updatedUserProgress
* @returns * @returns
*/ */
export function updateUserProgress(userId: string, curriculumCode: string, tutorialCode: string, taskItemTitle: string, taskItemMarkUser: string, taskItemSpentTime: string) { export function updateUserProgress(userId: string, curriculumCode: string, tutorialCode: string, taskItemTitle: string, taskItemMarkUser: number, taskItemSpentTime: number) {
return async () => { return async () => {
dispatch(slice.actions.startLoading()); dispatch(slice.actions.startLoading());
......
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