Advertisement
Fahim_7861

examCard

Jul 2nd, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.46 KB | None | 0 0
  1. import React, { useEffect, useState } from "react";
  2.  
  3. import { Card } from "react-bootstrap";
  4. import { MdRateReview } from "react-icons/md";
  5. import { FcBusinessman } from "react-icons/fc";
  6. import { MdDateRange } from "react-icons/md";
  7. import { Box, Grid, Paper, Typography } from "@material-ui/core";
  8. import { makeStyles } from "@material-ui/core/styles";
  9. import coins from "../../../assets/images/coins.png";
  10.  
  11. import examinee from "../../../assets/images/examinee.png";
  12. import running from "../../../assets/images/running.png";
  13. import { examDetails, helloBcsImg } from "../../../urls";
  14. import { useWindowSize } from "use-window-size-hook";
  15. import { useHistory } from "react-router";
  16.  
  17. const useStyles = makeStyles((theme) => ({
  18. root: {
  19. flexGrow: 1,
  20. },
  21. paper: {
  22. padding: theme.spacing(3),
  23.  
  24. color: theme.palette.text.secondary,
  25. },
  26. titleStyle : {
  27. fontSize: "12px",fontWeight : "bold",
  28. overflow: 'hidden',
  29. textOverflow: 'ellipsis',
  30. whiteSpace: 'nowrap',
  31.  
  32. width : "95%",
  33. textAlign : "left"
  34. },
  35. rootImage : {
  36. height: "50px", width: "50px"
  37. },
  38. iconText : {
  39. marginLeft: "5px",
  40. fontSize: "15px",
  41. fontWeight: "bold",
  42. },
  43. runningIconText : {
  44. fontWeight: "bold",
  45. fontSize: "10px",
  46. marginLeft: "5px",
  47. },
  48.  
  49. container2: {
  50. marginTop: "20px"
  51. },
  52. iconStyle : {
  53. height : "18px"
  54. }
  55.  
  56.  
  57.  
  58. }));
  59.  
  60. const ExamCard = (props) => {
  61. // const { width } = useWindowSize();
  62.  
  63. const history = useHistory();
  64.  
  65. const { exam, img } = props;
  66.  
  67. const { cost } = exam;
  68.  
  69. const Image = img[0].image || helloBcsImg();
  70.  
  71. const classes = useStyles();
  72.  
  73. const routeChange = (program, id) => {
  74. return history.push(examDetails(program, id, exam.state));
  75. };
  76.  
  77.  
  78.  
  79. const size = useWindowSize();
  80.  
  81. const [timeLeft, setTimeLeft] = useState(
  82. new Date(exam.end_time).getTime() - new Date().getTime()
  83. );
  84.  
  85.  
  86.  
  87. useEffect(() => {
  88. if (timeLeft<1) {
  89. return;
  90. }
  91.  
  92. const intervalId = setInterval(() => {
  93. setTimeLeft(timeLeft - 1000);
  94. console.log('intervalId');
  95. }, 1000);
  96.  
  97.  
  98. return () => clearInterval(intervalId);
  99. }, [timeLeft]);
  100.  
  101. // useEffect(()=>
  102. // {
  103. // return ()=>
  104. // {
  105.  
  106. // }
  107. // })
  108.  
  109. const getTimeFormat = () => {
  110. let h, m, s;
  111. h = Math.floor(timeLeft / 3600000);
  112. m = Math.floor((timeLeft / 3600000 - h) * 60);
  113. s = Math.floor(((timeLeft / 3600000 - h) * 60 - m) * 60);
  114.  
  115. s < 10 ? (s = `0${s}`) : (s = `${s}`);
  116. m < 10 ? (m = `0${m}`) : (m = `${m}`);
  117. h < 10 ? (h = `0${h}`) : (h = `${h}`);
  118.  
  119. return `${h} :${m}: ${s}`;
  120. };
  121.  
  122. // console.log('crv crv ',timeLeft);
  123.  
  124. return (
  125. <Box style={{ margin: "20px 10px 10px 10px" }}>
  126. <Paper style={{ width: "100%", padding: "10px" }} onClick={()=>routeChange(exam.program,exam.id)}>
  127. <Grid
  128. container
  129.  
  130. direction="row"
  131. justify="center"
  132.  
  133. spacing={1}
  134. >
  135. <Grid
  136. item
  137. xs={9}
  138. container
  139. justify="center"
  140. direction="column"
  141. alignItems="flex-start"
  142.  
  143. >
  144. <Typography className = {classes.titleStyle}> {exam.title}
  145.  
  146. </Typography>
  147. </Grid>
  148.  
  149. <Grid item xs={3} container justify="flex-end"
  150.  
  151. >
  152.  
  153.  
  154. <Paper>
  155.  
  156. <img
  157.  
  158. className={classes.rootImage}
  159. src={Image}
  160. alt=""
  161. ></img>
  162.  
  163.  
  164.  
  165. </Paper>
  166.  
  167.  
  168.  
  169.  
  170.  
  171. </Grid>
  172. </Grid>
  173.  
  174. <Grid
  175. container
  176. spacing={1}
  177.  
  178. className = {classes.container2}
  179.  
  180. justify="center"
  181. alignItems="center"
  182.  
  183.  
  184.  
  185. >
  186. <Grid
  187. item
  188. xs={4}
  189. container
  190. style={{ textAlign: "center" }}
  191. justify="center"
  192. alignItems="center"
  193. >
  194. <Grid item>
  195. <img className = {classes.iconStyle} src={running} alt=""></img>
  196. </Grid>
  197.  
  198. <Grid
  199. item
  200. className = {classes.runningIconText}
  201. >
  202. <Grid item >
  203. Running
  204. </Grid>
  205.  
  206. <Grid item style={{fontSize : "8px",textAlign : 'center'}}>
  207. {getTimeFormat()}
  208. </Grid>
  209. </Grid>
  210. </Grid>
  211.  
  212. <Grid item xs={4} style={{textAlign : 'center',
  213. margin : "auto"}} >
  214.  
  215.  
  216. <Grid item>
  217. <img className = {classes.iconStyle} src={examinee} alt=""></img>
  218.  
  219. <span
  220.  
  221. className ={classes.iconText}
  222. >
  223. {exam.statistics.total_examinees || 0}
  224. </span>
  225. </Grid>
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235. </Grid>
  236.  
  237. <Grid item xs={4}>
  238. <span>
  239. {" "}
  240. <img className={classes.iconStyle} src={coins} alt=''></img>
  241. <span
  242. className={classes.iconText}
  243. >
  244. {cost}
  245. </span>
  246. </span>
  247. </Grid>
  248. </Grid>
  249. </Paper>
  250. </Box>
  251.  
  252.  
  253. );
  254. };
  255.  
  256. export default ExamCard;
  257.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement