From 2ec99ca364e20b3908927dd1b4788100ac5018b1 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 15:13:31 +0000 Subject: [PATCH] style: format code with StandardJS This commit fixes the style issues introduced in ecaeac8 according to the output from StandardJS. Details: None --- src/pages/create/editor.jsx | 441 ++++++++++++++++-------------------- 1 file changed, 199 insertions(+), 242 deletions(-) diff --git a/src/pages/create/editor.jsx b/src/pages/create/editor.jsx index c0d93722..5aeeddde 100644 --- a/src/pages/create/editor.jsx +++ b/src/pages/create/editor.jsx @@ -1,128 +1,121 @@ -import Head from 'next/head'; -import { useState, useEffect } from 'react'; -import dynamic from 'next/dynamic'; -import { StandardNav } from '@/components/StandardNav'; -import { Footer } from '@/components/Footer'; -import request from "@/utils/request"; -import { MarkdownViewer } from '@/components/MarkdownViewer'; -import { useRouter } from 'next/router'; -export default function Create() { - const [isOpen, setIsOpen] = useState(false); - const [contentPreview, setContentPreview] = useState(''); - const [title, setTitle] = useState(''); - const [isLoading, setIsLoading] = useState(true); - const [isSaving, setIsSaving] = useState(false); - const [editorFailure, setEditorFailure] = useState(false); - const [publishView, setPublishView] = useState(false); - const [isPublishSaved, setPublishSaved] = useState(false); - const router = useRouter(); - const [isPublished, setIsPublished] = useState(false); +import Head from 'next/head' +import { useState, useEffect } from 'react' +import dynamic from 'next/dynamic' +import { StandardNav } from '@/components/StandardNav' +import { Footer } from '@/components/Footer' +import request from '@/utils/request' +import { MarkdownViewer } from '@/components/MarkdownViewer' +import { useRouter } from 'next/router' +export default function Create () { + const [isOpen, setIsOpen] = useState(false) + const [contentPreview, setContentPreview] = useState('') + const [title, setTitle] = useState('') + const [isLoading, setIsLoading] = useState(true) + const [isSaving, setIsSaving] = useState(false) + const [editorFailure, setEditorFailure] = useState(false) + const [publishView, setPublishView] = useState(false) + const [isPublishSaved, setPublishSaved] = useState(false) + const router = useRouter() + const [isPublished, setIsPublished] = useState(false) useEffect(() => { try { - request(`${process.env.NEXT_PUBLIC_API_URL}/account`, "GET", null) + request(`${process.env.NEXT_PUBLIC_API_URL}/account`, 'GET', null) .then((data) => { - handleLoad(); - if (router.query.publish == "done") { - setPublishSaved(true); + handleLoad() + if (router.query.publish == 'done') { + setPublishSaved(true) } }) .catch((err) => { - console.log(err); - }); + console.log(err) + }) } catch (error) { - console.error(error); + console.error(error) } - }, [router.query.cid]); + }, [router.query.cid]) const handleLoad = (event) => { - let cid = router.query.cid; // Challenge ID + const cid = router.query.cid // Challenge ID if (!cid) { - console.log("CID is undefined"); - setIsLoading(false); - return; + console.log('CID is undefined') + setIsLoading(false) + return } - request(`${process.env.NEXT_PUBLIC_API_URL}/writeups/fetch/${cid}`, "GET", null) // Fetch the writeup + request(`${process.env.NEXT_PUBLIC_API_URL}/writeups/fetch/${cid}`, 'GET', null) // Fetch the writeup .then((data) => { - console.log(data); - setTitle(data.title); - setContentPreview(data.content); - setIsPublished(data.draft); + console.log(data) + setTitle(data.title) + setContentPreview(data.content) + setIsPublished(data.draft) - - setIsLoading(false); + setIsLoading(false) }) .catch((err) => { - console.log(err); - }); + console.log(err) + }) } - - - const magicSnippet = () => { // creaate a random id - const id = Math.random().toString(36).substring(7); + const id = Math.random().toString(36).substring(7) - insertText(`[Click to run: ${id}](https://ctfguide.com/magic/)`); - }; + insertText(`[Click to run: ${id}](https://ctfguide.com/magic/)`) + } const insertText = (text) => { - const textarea = document.getElementById('content'); - const startPos = textarea.selectionStart; - const endPos = textarea.selectionEnd; - const newValue = textarea.value.substring(0, startPos) + text + textarea.value.substring(endPos, textarea.value.length); - setContentPreview(newValue); - textarea.focus(); - textarea.selectionEnd = startPos + text.length; - }; - + const textarea = document.getElementById('content') + const startPos = textarea.selectionStart + const endPos = textarea.selectionEnd + const newValue = textarea.value.substring(0, startPos) + text + textarea.value.substring(endPos, textarea.value.length) + setContentPreview(newValue) + textarea.focus() + textarea.selectionEnd = startPos + text.length + } + const handleSave = () => { - // sometimes auto save triggers before cid is avaliable for usage. + // sometimes auto save triggers before cid is avaliable for usage. // without this if -- it'll try to save data for undefined. lol. if (router.query.cid) { - console.log(`Saving ${router.query.cid}...`) - - setIsSaving(true); - const cid = router.query.cid; - request(`${process.env.NEXT_PUBLIC_API_URL}/writeups/${cid}`, "PUT", { - title: title, - content: contentPreview, - }) - .then((data) => { - - setTimeout(() => { - setIsSaving(false); - }, 2000); + console.log(`Saving ${router.query.cid}...`) + + setIsSaving(true) + const cid = router.query.cid + request(`${process.env.NEXT_PUBLIC_API_URL}/writeups/${cid}`, 'PUT', { + title, + content: contentPreview }) - .catch((err) => { - console.log(err); - }); + .then((data) => { + setTimeout(() => { + setIsSaving(false) + }, 2000) + }) + .catch((err) => { + console.log(err) + }) } - }; + } const handlePublish = () => { - if (router.query.cid) { - handleSave(); + if (router.query.cid) { + handleSave() } - const cid = router.query.cid; - request(`${process.env.NEXT_PUBLIC_API_URL}/writeups/${cid}/publish`, "PUT") + const cid = router.query.cid + request(`${process.env.NEXT_PUBLIC_API_URL}/writeups/${cid}/publish`, 'PUT') .then((data) => { - - if (data.message == "Writeup published successfully") { - window.location.href = window.location.href + "&publish=done"; + if (data.message == 'Writeup published successfully') { + window.location.href = window.location.href + '&publish=done' } else { console.log(data) - setEditorFailure(true); + setEditorFailure(true) } - }) .catch((err) => { - console.log(err); - }); - }; + console.log(err) + }) + } return ( <> @@ -134,194 +127,158 @@ export default function Create() { - { isPublishSaved && -
-

🎉 Congratulations! Your writeup has been published!

+ {isPublishSaved && +
+

🎉 Congratulations! Your writeup has been published!

+
} + {isLoading && +
+
+

+

Setting up CTFGuide Editor

-} -{ isLoading && -
-
-

-

Setting up CTFGuide Editor

-
-
- -} - +
} + {editorFailure && +
+
+

+

CTFGuide Editor failed to load.

+
+
} -{ editorFailure && -
-
-

-

CTFGuide Editor failed to load.

-
-
+ {(!isLoading && !editorFailure) && +
-} +
+
+

CTFGuide Editor BETA

+
- { (!isLoading && !editorFailure )&& -
+
+ + -
-
-

CTFGuide Editor BETA

+ {isPublished && + } +
-
- +
- +
- { isPublished && - - - } -
-
- -
- -
- -
- setTitle(event.target.value)} - className='px-0 mt-2 bg-transparent border-none w-full text-white text-4xl placeholder-neutral-700 focus:outline-none focus:ring-0 focus:border-transparent focus:shadow-none' - placeholder='Enter your title here' - autoFocus - /> -
-
- { !isPublished && -published -} -
-
-
-
-
- - - - - - +
+ setTitle(event.target.value)} + className='px-0 mt-2 bg-transparent border-none w-full text-white text-4xl placeholder-neutral-700 focus:outline-none focus:ring-0 focus:border-transparent focus:shadow-none' + placeholder='Enter your title here' + autoFocus + /> +
+
+ {!isPublished && + published}
-