From 99ce739fdfca673e9ef006433090c891c05217fb Mon Sep 17 00:00:00 2001
From: bmodee <bjomo323@student.liu.se>
Date: Thu, 6 May 2021 14:59:19 +0200
Subject: [PATCH] add comments

---
 client/src/pages/admin/dashboard/Dashboard.tsx    |  5 +++++
 client/src/pages/login/LoginPage.tsx              |  4 ++++
 client/src/pages/login/components/AdminLogin.tsx  |  2 ++
 .../pages/login/components/CompetitionLogin.tsx   |  4 +++-
 client/src/pages/views/OperatorViewPage.tsx       | 15 +++++++--------
 5 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/client/src/pages/admin/dashboard/Dashboard.tsx b/client/src/pages/admin/dashboard/Dashboard.tsx
index a0f569b0..51aa4f40 100644
--- a/client/src/pages/admin/dashboard/Dashboard.tsx
+++ b/client/src/pages/admin/dashboard/Dashboard.tsx
@@ -6,6 +6,11 @@ import NumberOfCompetitions from './components/NumberOfCompetitions'
 import NumberOfRegions from './components/NumberOfRegions'
 import NumberOfUsers from './components/NumberOfUsers'
 
+/**
+ * This is the first page that is shown after a user logs in. It shows som statistics about the site.
+ *
+ */
+
 const useStyles = makeStyles((theme: Theme) =>
   createStyles({
     root: {
diff --git a/client/src/pages/login/LoginPage.tsx b/client/src/pages/login/LoginPage.tsx
index 8f8e967c..34c9c5ae 100644
--- a/client/src/pages/login/LoginPage.tsx
+++ b/client/src/pages/login/LoginPage.tsx
@@ -1,3 +1,7 @@
+/** This is the login page, it contains two child components, one is
+ *   to log in as an admin, the other is to connect to a competition using a code
+ */
+
 import { AppBar, Tab, Tabs } from '@material-ui/core'
 import React from 'react'
 import AdminLogin from './components/AdminLogin'
diff --git a/client/src/pages/login/components/AdminLogin.tsx b/client/src/pages/login/components/AdminLogin.tsx
index 964fb8ab..4fe47524 100644
--- a/client/src/pages/login/components/AdminLogin.tsx
+++ b/client/src/pages/login/components/AdminLogin.tsx
@@ -1,3 +1,5 @@
+/** Component that handles the log in when a user is an admin */
+
 import { Button, TextField, Typography } from '@material-ui/core'
 import { Alert, AlertTitle } from '@material-ui/lab'
 import { Formik, FormikHelpers } from 'formik'
diff --git a/client/src/pages/login/components/CompetitionLogin.tsx b/client/src/pages/login/components/CompetitionLogin.tsx
index 8dbbee33..44463474 100644
--- a/client/src/pages/login/components/CompetitionLogin.tsx
+++ b/client/src/pages/login/components/CompetitionLogin.tsx
@@ -1,3 +1,5 @@
+/** Component that handles the log in when a user connects to a competition through a code */
+
 import { Button, TextField, Typography } from '@material-ui/core'
 import { Alert, AlertTitle } from '@material-ui/lab'
 import { Formik } from 'formik'
@@ -38,7 +40,7 @@ const CompetitionLogin: React.FC = () => {
   const handleCompetitionSubmit = async (values: CompetitionLoginFormModel) => {
     dispatch(loginCompetition(values.model.code, history, true))
   }
-  
+
   return (
     <Formik
       initialValues={competitionInitialValues}
diff --git a/client/src/pages/views/OperatorViewPage.tsx b/client/src/pages/views/OperatorViewPage.tsx
index 22d91ac3..a2979945 100644
--- a/client/src/pages/views/OperatorViewPage.tsx
+++ b/client/src/pages/views/OperatorViewPage.tsx
@@ -113,14 +113,13 @@ const OperatorViewPage: React.FC = () => {
 
   useEffect(() => {
     socketConnect()
-    socketSetSlide // Behövs denna?
+    socketSetSlide
     handleOpenCodes()
-    setTimeout(startCompetition, 1000) // Ghetto, wait for everything to load
-    // console.log(id)
+    setTimeout(startCompetition, 1000) // Wait for socket to connect
   }, [])
 
+  /** Handles the browsers back button and if pressed cancels the ongoing competition */
   window.onpopstate = () => {
-    //Handle browser back arrow
     alert('Tävlingen avslutas för alla')
     endCompetition()
   }
@@ -136,11 +135,12 @@ const OperatorViewPage: React.FC = () => {
   }
 
   const startCompetition = () => {
-    socketStartPresentation()
+    socketStartPresentation() // Calls the socket to start competition
     console.log('started competition for')
     console.log(competitionId)
   }
 
+  /** Making sure the user wants to exit the competition by displaying a dialog box */
   const handleVerifyExit = () => {
     setOpen(true)
   }
@@ -155,7 +155,7 @@ const OperatorViewPage: React.FC = () => {
     setOpen(false)
     socketEndPresentation()
     history.push('/admin/tävlingshanterare')
-    window.location.reload(false) // TODO: fix this ugly hack, we "need" to refresh site to be able to run the competition correctly again
+    window.location.reload(false) // TODO: fix this, we "need" to refresh site to be able to run the competition correctly again
   }
 
   const getCodes = async () => {
@@ -205,9 +205,8 @@ const OperatorViewPage: React.FC = () => {
     return typeName
   }
 
+  /** Sums the scores for the teams. */
   const addScore = (team: RichTeam) => {
-    // Sums the scores for the teams.
-
     let totalScore = 0
     for (let j = 0; j < team.question_answers.length; j++) {
       totalScore = totalScore + team.question_answers[j].score
-- 
GitLab