Advertisement
Fahim_7861

current2

Apr 5th, 2021
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.92 KB | None | 0 0
  1. import { PostAddOutlined } from "@material-ui/icons";
  2. import { isEmpty, set } from "lodash";
  3. import React, { useState } from "react";
  4. import { alignPropType } from "react-bootstrap/esm/DropdownMenu";
  5. import { useSelector } from "react-redux";
  6. import { Redirect, useHistory, useParams } from "react-router";
  7. import wrongSign from "../../assets/images/wrongSign.png";
  8. import trophy from "../../assets/images/trophy.jpg";
  9.  
  10. import {
  11. answersheet,
  12. examStandings,
  13. mainpage,
  14. RESPONSE,
  15. } from "../../constants/constants";
  16. import { resultDetails } from "../../urls";
  17. import AnsSheet from "./AnsSheet/AnsSheet";
  18. import Standings from "./Standings/Standings";
  19.  
  20. import LoaderComponent from "../../Components/LoaderComponent/LoaderComponent";
  21.  
  22. import ChartsPage from "../../Components/ChartsPage/ChartsPage";
  23.  
  24. const ResultDetails = () => {
  25. const { id, page, from } = useParams();
  26.  
  27. const [currentPage, setCurrentPage] = useState(mainpage);
  28.  
  29. const resultinitData = useSelector((state) => state.initData.results[id]);
  30.  
  31. const resultresponse = useSelector((state) => state.submitAnsResponse);
  32.  
  33. let allExams = [...useSelector((state) => state.initData.exams)];
  34.  
  35. let archievedExam = useSelector((state) => state.archievedData.exams);
  36.  
  37. if (archievedExam != undefined) allExams = [...allExams, ...archievedExam];
  38.  
  39. const history = useHistory();
  40.  
  41. const pageChange = (Page) => {
  42. setCurrentPage(Page);
  43.  
  44. history.replace(resultDetails(id, Page, from));
  45. };
  46.  
  47. let result,
  48. statistics = {},
  49. passed_examinees = 0,
  50. total_examinees = 0,
  51. cut_mark = 0,
  52. marks = 0,
  53. incorrect_answers = 0,
  54. correct_answers = 0,
  55. skippedCount = 0;
  56.  
  57. if (from == RESPONSE) {
  58. result = resultresponse;
  59. statistics = result.statistics;
  60. } else {
  61. result = resultinitData;
  62. statistics = result.exam_data.statistics;
  63. }
  64.  
  65. if (isEmpty(result) || result == undefined) {
  66. return <LoaderComponent />;
  67. }
  68.  
  69. let standings = [];
  70.  
  71. if (from != RESPONSE) {
  72. standings = result.exam_data.statistics.standings;
  73.  
  74. passed_examinees = statistics.passed_examinees;
  75. total_examinees = statistics.total_examinees;
  76. cut_mark = statistics.cut_mark;
  77. } else {
  78. if (result.exam_data != undefined) {
  79. standings = result.exam_data.statistics.standings;
  80. }
  81. }
  82.  
  83. if (from == RESPONSE) {
  84. let mp = {};
  85.  
  86. if (result.answer_sheet != undefined) {
  87. result.answer_sheet.forEach((ans) => {
  88. mp[ans.question] = ans.answers[0];
  89. });
  90.  
  91. const currentQuestion = allExams.filter((ex) => ex.id == id)[0].questions;
  92.  
  93. let newAnswerSheet = [];
  94.  
  95. currentQuestion.forEach((que) => {
  96. if (mp[que] != undefined)
  97. newAnswerSheet.push({
  98. answers: [mp[que]],
  99. question: que,
  100. });
  101. else
  102. newAnswerSheet.push({
  103. answers: [],
  104. question: que,
  105. });
  106. });
  107.  
  108. result = { ...result, ["answer_sheet"]: newAnswerSheet };
  109. }
  110. }
  111.  
  112. if (result != undefined && result.answer_sheet != undefined) {
  113. marks = result.statistics.marks;
  114. incorrect_answers = result.statistics.incorrect_answers;
  115. correct_answers = result.statistics.correct_answers;
  116. skippedCount =
  117. result.answer_sheet.length - (incorrect_answers + correct_answers);
  118. }
  119.  
  120. const pageCheck = (newPage) => newPage == currentPage;
  121.  
  122. const standingAvailable = () =>
  123. (standings != undefined && standings != null && standings.length > 0) ==
  124. true;
  125.  
  126. console.log(result);
  127.  
  128. const checkPosition = () => {
  129. if (
  130. result == undefined ||
  131. result.statistics == undefined ||
  132. result.statistics.position == undefined ||
  133. result.statistics.position == "N/A"
  134. )
  135. return false;
  136.  
  137. return true;
  138. };
  139.  
  140. const PassFailRemark = () => {
  141. if (
  142. result == undefined ||
  143. result.statistics == undefined ||
  144. result.statistics.grade == undefined ||
  145. result.statistics.grade == "fail"
  146. )
  147. return "আপনি অনুত্তীর্ণ হয়েছেন";
  148. else return "আপনি উত্তীর্ণ হয়েছেন";
  149. };
  150.  
  151. const passFailBorderColor = () => {
  152. if (
  153. result == undefined ||
  154. result.statistics == undefined ||
  155. result.statistics.grade == undefined ||
  156. result.statistics.grade == "fail"
  157. )
  158. return { border: "4px solid red" };
  159.  
  160. return {};
  161. };
  162.  
  163. const PassOrFaillImage = () => {
  164. if (
  165. result == undefined ||
  166. result.statistics == undefined ||
  167. result.statistics.grade == undefined ||
  168. result.statistics.grade == "fail"
  169. )
  170. return (
  171. <img style={{ width: "150px", height: "150px" }} src={wrongSign}></img>
  172. );
  173.  
  174. return <img style={{ width: "170px", height: "170px" }} src={trophy}></img>;
  175. };
  176.  
  177. return (
  178. <div >
  179. {currentPage == mainpage && (
  180.  
  181.  
  182. <div >
  183. <div
  184. style={{ marginTop: "20px" }}
  185.  
  186. >
  187. <div style={{ margin: "20px" }}>
  188. <PassOrFaillImage />
  189. </div>
  190.  
  191. <div
  192. style={{
  193. padding: "30px",
  194. border: "4px solid green",
  195. borderRadius: "20px",
  196. color: "grey",
  197. ...passFailBorderColor(),
  198. }}
  199. >
  200. <div style={{ fontSize: "20px" }}> {result.remarks}</div>
  201.  
  202. <div style={{ marginTop: "20px", fontSize: "28px" }}>
  203. <PassFailRemark />
  204.  
  205. {checkPosition() && (
  206. <span> আপনার অবস্থান {result.statistics.position} </span>
  207. )}
  208. </div>
  209. </div>
  210. </div>
  211.  
  212. <div
  213. style={{
  214. paddingTop: "10px",
  215. padding: "100px 0px 100px 100px",
  216. fontSize: "45px",
  217. }}
  218.  
  219. >
  220. <div className="row">
  221. <div className="col-md-5">আপনার মার্কস</div>
  222. <div className="col-md-2">:</div>
  223. <div className="col-md-3">
  224.  
  225. <div
  226. style={{
  227. backgroundColor: "#4067B2",
  228. color: "white",
  229. width: "150px",
  230. }}
  231. >
  232. {marks}
  233. </div>
  234. </div>
  235. </div>
  236.  
  237. {from != RESPONSE && (
  238. <div>
  239.  
  240. <div className="row" style={{ paddingTop: "10px" }}>
  241. <div className="col-md-5">কাট মার্ক</div>
  242. <div className="col-md-2">:</div>
  243. <div className="col-md-3">
  244. <div
  245. style={{
  246. backgroundColor: "#4067B2",
  247. color: "white",
  248. width: "150px",
  249. }}
  250. >
  251. {cut_mark}
  252. </div>
  253. </div>
  254. </div>
  255.  
  256. <div className="row" style={{ paddingTop: "10px" }}>
  257. <div className="col-md-5">মোট পরীক্ষার্থী সংখ্যা</div>
  258. <div className="col-md-2">:</div>
  259. <div className="col-md-3">
  260.  
  261. <div
  262. style={{
  263. backgroundColor: "#4067B2",
  264. color: "white",
  265. width: "150px",
  266. }}
  267. >
  268. {total_examinees}
  269. </div>
  270. </div>
  271. </div>
  272.  
  273. <div className="row" style={{ paddingTop: "10px" }}>
  274. <div className="col-md-5">উত্তীর্ণ পরীক্ষার্থীর সংখ্যা</div>
  275. <div className="col-md-2">:</div>
  276. <div className="col-md-3">
  277.  
  278. <div
  279. style={{
  280. backgroundColor: "#4067B2",
  281. color: "white",
  282. width: "150px",
  283. }}
  284. >
  285. {passed_examinees}
  286. </div>
  287. </div>
  288. </div>
  289.  
  290.  
  291.  
  292.  
  293. </div>
  294.  
  295.  
  296.  
  297. )}
  298.  
  299.  
  300.  
  301.  
  302. <div
  303. className="row"
  304. style={{ marginTop: "50px" }}
  305. >
  306. <ChartsPage
  307. skippedCount={skippedCount}
  308. correct_answers={correct_answers}
  309. incorrect_answers={incorrect_answers}
  310. />
  311. </div>
  312. <div className="row">
  313. <div className="col-md-5">
  314. <button
  315. style={{
  316. border: "none",
  317. backgroundColor: "white",
  318. color: "black",
  319. height: "70px",
  320. width: "250px",
  321. }}
  322. >
  323. <img
  324. style={{ height: "35px", width: "35px" }}
  325. // src={grade}
  326. ></img>
  327. <span style={{ fontSize: "20px", paddingLeft: "5px" }}>
  328. Result
  329. </span>
  330. </button>
  331. </div>
  332. <div className="col-md-4">Fahim</div>
  333. </div>
  334. </div>
  335.  
  336.  
  337. </div>
  338. )
  339.  
  340.  
  341.  
  342.  
  343. }
  344.  
  345.  
  346.  
  347.  
  348. {pageCheck(examStandings) && (
  349. <Standings standings={standings} userPos={result.statistics.position} />
  350. )}
  351.  
  352. {pageCheck(answersheet) && <AnsSheet result={result} />}
  353. </div>
  354. );
  355. };
  356.  
  357. export default ResultDetails;
  358.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement