From bc5bf4bec2b636e2c422a0798d81dcfbfba568a9 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 24 Jul 2024 03:15:49 +0000 Subject: [PATCH] style: format code with StandardJS This commit fixes the style issues introduced in fb5216c according to the output from StandardJS. Details: None --- .../groups/assignments/create-challenge.jsx | 489 +++---- src/components/nav/SearchModal.jsx | 106 +- src/pages/challenges/[...id].jsx | 1147 ++++++++--------- 3 files changed, 860 insertions(+), 882 deletions(-) diff --git a/src/components/groups/assignments/create-challenge.jsx b/src/components/groups/assignments/create-challenge.jsx index 6f82841d..18b631d0 100644 --- a/src/components/groups/assignments/create-challenge.jsx +++ b/src/components/groups/assignments/create-challenge.jsx @@ -1,14 +1,14 @@ -import Head from 'next/head'; -import { useState, useEffect } from 'react'; -import { StandardNav } from '@/components/StandardNav'; -import { Footer } from '@/components/Footer'; -import { MarkdownViewer } from '@/components/MarkdownViewer'; - -import { ToastContainer, toast } from 'react-toastify'; -import 'react-toastify/dist/ReactToastify.css'; -import fileApi from '@/utils/file-api'; -import request, { getCookie } from '@/utils/request'; -import { jwtDecode } from 'jwt-decode'; +import Head from 'next/head' +import { useState, useEffect } from 'react' +import { StandardNav } from '@/components/StandardNav' +import { Footer } from '@/components/Footer' +import { MarkdownViewer } from '@/components/MarkdownViewer' + +import { ToastContainer, toast } from 'react-toastify' +import 'react-toastify/dist/ReactToastify.css' +import fileApi from '@/utils/file-api' +import request, { getCookie } from '@/utils/request' +import { jwtDecode } from 'jwt-decode' const styles = { h1: { fontSize: '2.4rem' }, @@ -16,45 +16,44 @@ const styles = { h3: { fontSize: '1.8rem' }, h4: { fontSize: '1.6rem' }, h5: { fontSize: '1.4rem' }, - h6: { fontSize: '1.2rem' }, -}; - -export default function Createchall(props) { + h6: { fontSize: '1.2rem' } +} +export default function Createchall (props) { const pages = [ { name: 'Create Assignment', click: () => props.setDisplay(false), href: '../create', - current: false, + current: false }, { name: 'Challenge Creation', href: './', current: true, - click: () => {}, - }, - ]; + click: () => {} + } + ] - const [contentPreview, setContentPreview] = useState(''); - const [penalty, setPenalty] = useState([0, 0, 0]); + const [contentPreview, setContentPreview] = useState('') + const [penalty, setPenalty] = useState([0, 0, 0]) const [hints, setHints] = useState([ 'Looks like the challenge creator did not set hint 1.', 'Looks like the challenge creator did not set hint 2.', - 'Looks like the challenge creator did not set hint 3.', - ]); + 'Looks like the challenge creator did not set hint 3.' + ]) - const [solution, setSolution] = useState(''); - const [difficulty, setDifficulty] = useState('Easy'); - const [category, setCategory] = useState('forensics'); - const [newChallengeName, setNewChallengeName] = useState(''); - const [errMessage, setErrMessage] = useState(''); - const [penaltyErr, setPenaltyErr] = useState(''); - const [username, setUsername] = useState('anonymous'); + const [solution, setSolution] = useState('') + const [difficulty, setDifficulty] = useState('Easy') + const [category, setCategory] = useState('forensics') + const [newChallengeName, setNewChallengeName] = useState('') + const [errMessage, setErrMessage] = useState('') + const [penaltyErr, setPenaltyErr] = useState('') + const [username, setUsername] = useState('anonymous') - const [newConfig, setNewConfig] = useState(''); - const [selectedFile, setSelectedFile] = useState(null); - const [isCreating, setIsCreating] = useState(false); + const [newConfig, setNewConfig] = useState('') + const [selectedFile, setSelectedFile] = useState(null) + const [isCreating, setIsCreating] = useState(false) const validateNewChallege = async () => { for (const p of penalty) { @@ -67,44 +66,43 @@ export default function Createchall(props) { pauseOnHover: true, draggable: true, progress: undefined, - theme: 'dark', - }); - setPenaltyErr("Can't have a positive value for penalties"); - return false; + theme: 'dark' + }) + setPenaltyErr("Can't have a positive value for penalties") + return false } } - setPenaltyErr(''); - return true; - }; + setPenaltyErr('') + return true + } const sendToFileApi = async () => { - const isValid = await validateNewChallege(); + const isValid = await validateNewChallege() if (isValid) { - setIsCreating(true); + setIsCreating(true) if (!selectedFile) { - await uploadChallenge(''); - return; + await uploadChallenge('') } else { - const cookie = getCookie('idToken'); - const data = jwtDecode(cookie); + const cookie = getCookie('idToken') + const data = jwtDecode(cookie) - const token = data.id; - const fileId = await fileApi(token, selectedFile); - if(fileId !== null) { - await uploadChallenge(fileId); + const token = data.id + const fileId = await fileApi(token, selectedFile) + if (fileId !== null) { + await uploadChallenge(fileId) } else { - toast.error('Something went wrong with the file upload'); + toast.error('Something went wrong with the file upload') } } } else { - console.warn('Either the file, toke, or challenge is invalid'); + console.warn('Either the file, toke, or challenge is invalid') } - }; + } const uploadChallenge = async (fileId) => { try { - const nConfig = newConfig.replace('\n', ' && '); - let new_solution = props.assignmentInfo.option !== "dynamicLab" ? solution : ""; + const nConfig = newConfig.replace('\n', ' && ') + const new_solution = props.assignmentInfo.option !== 'dynamicLab' ? solution : '' const challengeInfo = { name: newChallengeName, @@ -116,16 +114,17 @@ export default function Createchall(props) { difficulty, category, commands: nConfig, - fileId: fileId, - }; - - const classCode = window.location.pathname.split('/')[2]; - const assignmentInfo = props.assignmentInfo; - const url = `${process.env.NEXT_PUBLIC_API_URL}/classroom-assignments/create-new-assignment/${classCode}`; - const data = await request(url, 'POST', { - challengeInfo, assignmentInfo, - username: localStorage.getItem('username') - }); + fileId + } + + const classCode = window.location.pathname.split('/')[2] + const assignmentInfo = props.assignmentInfo + const url = `${process.env.NEXT_PUBLIC_API_URL}/classroom-assignments/create-new-assignment/${classCode}` + const data = await request(url, 'POST', { + challengeInfo, + assignmentInfo, + username: localStorage.getItem('username') + }) if (data && data.success) { toast.success('Assignment Created', { position: 'bottom-right', @@ -135,22 +134,22 @@ export default function Createchall(props) { pauseOnHover: true, draggable: true, progress: undefined, - theme: 'dark', - }); - window.location.reload(); + theme: 'dark' + }) + window.location.reload() } } catch (err) { - console.log(err); + console.log(err) } - }; + } useEffect(() => { - setUsername(localStorage.getItem('username')); - }, []); + setUsername(localStorage.getItem('username')) + }, []) const handleFileChange = (event) => { - setSelectedFile(event.target.files[0]); - console.log(event.target.files[0]); + setSelectedFile(event.target.files[0]) + console.log(event.target.files[0]) toast.success(`Successfully uploaded ${event.target.files[0].name}`, { position: 'bottom-right', autoClose: 5000, @@ -159,9 +158,9 @@ export default function Createchall(props) { pauseOnHover: true, draggable: true, progress: undefined, - theme: 'dark', - }); - }; + theme: 'dark' + }) + } return ( <> @@ -176,34 +175,34 @@ export default function Createchall(props) {
- {/*/ Create a new challenge */} + {/* / Create a new challenge */} { - setNewChallengeName(event.target.value); + setNewChallengeName(event.target.value) }} className={ errMessage !== '' ? 'w-3/4 rounded-lg border border-red-600 bg-neutral-900/90 px-4 py-2 text-3xl font-semibold text-white shadow-lg' : 'w-3/4 rounded-lg border border-neutral-600 bg-neutral-900/90 px-4 py-2 text-3xl font-semibold text-white shadow-lg' } - placeholder="Untitled Challenge" + placeholder='Untitled Challenge' />
{errMessage}
Something went wrong on our end. Your changes have not been saved. You can try again now or later.
-
-
+
+

Difficulty

-
+

Category

-
-
-

+
+
+

Challenge Content

-
-
+
+
Challenge Instructions
+ /> -
+
{hints.map((hint, idx) => { return (
-
+
Hint {idx + 1}
+ /> { setPenalty((prevState) => { - let newState = [...prevState]; - newState[idx] = parseInt(e.target.value); - return newState; - }); + const newState = [...prevState] + newState[idx] = parseInt(e.target.value) + return newState + }) }} max={0} placeholder={-idx * 5} - type="number" + type='number' className={ penaltyErr === '' ? 'mt-1 w-full rounded-lg border-neutral-800 bg-neutral-900 text-white shadow-lg' @@ -352,50 +351,50 @@ export default function Createchall(props) { />
- ); + ) })}
-
-

+
+

Challenge Content Preview

-
+

{' '} {newChallengeName}{' '}

-
-
-

Created by

+
+
+

Created by

-

{username}

+

{username}

-
+
@@ -404,40 +403,40 @@ export default function Createchall(props) {
{ - props.assignmentInfo && props.assignmentInfo.option !== "dynamicLab" && ( -
-

- Challenge Solution -

-
- -
-
+ props.assignmentInfo && props.assignmentInfo.option !== 'dynamicLab' && ( +
+

+ Challenge Solution +

+
+ + className='mt-4 w-full border-none bg-black text-white' + />
-
-
+
+
✨ What is this?

When we spin up your container, we will run the commands in @@ -447,53 +446,57 @@ export default function Createchall(props) {

-

+
-
+

Import files from your computer

-