From 8bb140379e1963124c3fbed236ad695f0aeb90d0 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Thu, 25 Jul 2024 22:02:04 +0000 Subject: [PATCH] style: format code with StandardJS This commit fixes the style issues introduced in dd91270 according to the output from StandardJS. Details: None --- .../settingComponents/generalPage.jsx | 785 +++++++++--------- 1 file changed, 389 insertions(+), 396 deletions(-) diff --git a/src/components/settingComponents/generalPage.jsx b/src/components/settingComponents/generalPage.jsx index 0e1ef3e5..c99f44ea 100644 --- a/src/components/settingComponents/generalPage.jsx +++ b/src/components/settingComponents/generalPage.jsx @@ -1,74 +1,70 @@ -import React, { useState, useEffect, useRef } from 'react'; -import { Transition, Dialog } from '@headlessui/react'; -import { Fragment } from 'react'; -import { Locations } from '@/components/settingComponents/locations'; -import { useRouter } from 'next/router'; -import request from '@/utils/request'; -import { getCookie } from '@/utils/request'; -import Cropper from 'react-easy-crop'; -import getCroppedImg from '@/components/cropImage'; -import Skeleton from 'react-loading-skeleton'; -import 'react-loading-skeleton/dist/skeleton.css'; -import { ToastContainer, toast } from 'react-toastify'; -import 'react-toastify/dist/ReactToastify.css'; -import Markdown from 'react-markdown'; -import { Context } from '@/context'; -import { useContext } from 'react'; - - -export default function General() { - const router = useRouter(); - const bioRef = useRef(null); - const { role } = useContext(Context); - - const [isBannerPopupOpen, setIsBannerPopupOpen] = useState(false); - const [isPopupOpen, setIsPopupOpen] = useState(false); - const [selectedImage, setSelectedImage] = useState(null); - const [imageUrl, setImageUrl] = useState(null); - const [username, setUsername] = useState(''); - const [inputText, setInputText] = useState(''); - const [firstName, setFirstName] = useState(''); - const [lastName, setLastName] = useState(''); - const [bio, setBio] = useState(''); - const [location, setLocation] = useState(''); - const [crop, setCrop] = useState({ x: 0, y: 0 }); - const [rotation, setRotation] = useState(0); - const [zoom, setZoom] = useState(1); - const [croppedAreaPixels, setCroppedAreaPixels] = useState(null); - const [croppedImage, setCroppedImage] = useState(null); - const [pfp, setPfp] = useState(''); - const [open, setOpen] = useState(true); - const [isSaving, setIsSaving] = useState(false); - const [isLoading, setIsLoading] = useState(true); - const [userData, setUserData] = useState(null); - const [tempBio, setTempBio] = useState(bio); - const [showBioPreview, setShowBioPreview] = useState(false); +import React, { useState, useEffect, useRef, Fragment, useContext } from 'react' +import { Transition, Dialog } from '@headlessui/react' +import { Locations } from '@/components/settingComponents/locations' +import { useRouter } from 'next/router' +import request, { getCookie } from '@/utils/request' +import Cropper from 'react-easy-crop' +import getCroppedImg from '@/components/cropImage' +import Skeleton from 'react-loading-skeleton' +import 'react-loading-skeleton/dist/skeleton.css' +import { ToastContainer, toast } from 'react-toastify' +import 'react-toastify/dist/ReactToastify.css' +import Markdown from 'react-markdown' +import { Context } from '@/context' + +export default function General () { + const router = useRouter() + const bioRef = useRef(null) + const { role } = useContext(Context) + + const [isBannerPopupOpen, setIsBannerPopupOpen] = useState(false) + const [isPopupOpen, setIsPopupOpen] = useState(false) + const [selectedImage, setSelectedImage] = useState(null) + const [imageUrl, setImageUrl] = useState(null) + const [username, setUsername] = useState('') + const [inputText, setInputText] = useState('') + const [firstName, setFirstName] = useState('') + const [lastName, setLastName] = useState('') + const [bio, setBio] = useState('') + const [location, setLocation] = useState('') + const [crop, setCrop] = useState({ x: 0, y: 0 }) + const [rotation, setRotation] = useState(0) + const [zoom, setZoom] = useState(1) + const [croppedAreaPixels, setCroppedAreaPixels] = useState(null) + const [croppedImage, setCroppedImage] = useState(null) + const [pfp, setPfp] = useState('') + const [open, setOpen] = useState(true) + const [isSaving, setIsSaving] = useState(false) + const [isLoading, setIsLoading] = useState(true) + const [userData, setUserData] = useState(null) + const [tempBio, setTempBio] = useState(bio) + const [showBioPreview, setShowBioPreview] = useState(false) const [banner, setBanner] = useState( 'https://images.unsplash.com/photo-1633259584604-afdc243122ea?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1770&q=80"e' - ); + ) const insertText = (text) => { - const textarea = bioRef.current; - const startPos = textarea.selectionStart; - const endPos = textarea.selectionEnd; + const textarea = bioRef.current + const startPos = textarea.selectionStart + const endPos = textarea.selectionEnd const newValue = textarea.value.substring(0, startPos) + text + - textarea.value.substring(endPos, textarea.value.length); - setTempBio(newValue); - textarea.focus(); - textarea.selectionEnd = startPos + text.length; - }; + textarea.value.substring(endPos, textarea.value.length) + setTempBio(newValue) + textarea.focus() + textarea.selectionEnd = startPos + text.length + } const magicSnippet = () => { - const id = Math.random().toString(36).substring(7); - insertText(`[Click to run: ${id}](https://ctfguide.com/magic/)`); - }; + const id = Math.random().toString(36).substring(7) + insertText(`[Click to run: ${id}](https://ctfguide.com/magic/)`) + } const onCropComplete = (croppedArea, croppedAreaPixels) => { - setCroppedAreaPixels(croppedAreaPixels); - showCroppedImage(); - }; + setCroppedAreaPixels(croppedAreaPixels) + showCroppedImage() + } const showCroppedImage = async () => { try { @@ -76,33 +72,33 @@ export default function General() { URL.createObjectURL(selectedImage), croppedAreaPixels, rotation - ); - console.log('donee', { croppedImage }); - setCroppedImage(croppedImage); + ) + console.log('donee', { croppedImage }) + setCroppedImage(croppedImage) } catch (e) { - console.log(e); + console.log(e) } - }; + } const handleInputChange = (event) => { - setInputText(event.target.value); - }; + setInputText(event.target.value) + } const handlePopupOpen = () => { - setIsPopupOpen(true); - }; + setIsPopupOpen(true) + } const handleBannerPopupOpen = () => { - setIsBannerPopupOpen(true); - }; + setIsBannerPopupOpen(true) + } const handleBannerChange = (event) => { - const file = event.target.files[0]; - setSelectedImage(file); // Ensure selectedImage is set for banner as well - setImageUrl(URL.createObjectURL(file)); - setBanner(URL.createObjectURL(file)); // Set the banner URL - setIsBannerPopupOpen(true); // Open the banner popup - }; + const file = event.target.files[0] + setSelectedImage(file) // Ensure selectedImage is set for banner as well + setImageUrl(URL.createObjectURL(file)) + setBanner(URL.createObjectURL(file)) // Set the banner URL + setIsBannerPopupOpen(true) // Open the banner popup + } useEffect(() => { const fetchUserData = async () => { @@ -111,539 +107,536 @@ export default function General() { `${process.env.NEXT_PUBLIC_API_URL}/account`, 'GET', null - ); - const userData = await response; - console.log('User Data:', userData); // Debugging statement + ) + const userData = await response + console.log('User Data:', userData) // Debugging statement // Set the fetched data into the state - setUserData(userData); - setUsername(userData.username); - setInputText(userData.githubUrl || ''); - setFirstName(userData.firstName || ''); - setLastName(userData.lastName || ''); - setBio(userData.bio || ''); - setTempBio(userData.bio || ''); - setLocation(userData.location || ''); - setBanner(userData.bannerImage || ''); - - const endPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${userData.username}/pfp`; - const result = await request(endPoint, 'GET', null); - console.log('Profile Picture Result:', result); // Debugging statement + setUserData(userData) + setUsername(userData.username) + setInputText(userData.githubUrl || '') + setFirstName(userData.firstName || '') + setLastName(userData.lastName || '') + setBio(userData.bio || '') + setTempBio(userData.bio || '') + setLocation(userData.location || '') + setBanner(userData.bannerImage || '') + + const endPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${userData.username}/pfp` + const result = await request(endPoint, 'GET', null) + console.log('Profile Picture Result:', result) // Debugging statement if (result) { - setPfp(result); + setPfp(result) } else { setPfp( `https://robohash.org/${userData.username}.png?set=set1&size=150x150` - ); + ) } } catch (err) { - console.error('Failed to fetch user data', err); + console.error('Failed to fetch user data', err) } finally { - setIsLoading(false); + setIsLoading(false) } - }; - fetchUserData(); - }, []); + } + fetchUserData() + }, []) const handlePopupClose = () => { - setIsPopupOpen(false); - }; + setIsPopupOpen(false) + } const handleImageChange = (event) => { - const file = event.target.files[0]; - setSelectedImage(file); - setImageUrl(URL.createObjectURL(file)); - }; + const file = event.target.files[0] + setSelectedImage(file) + setImageUrl(URL.createObjectURL(file)) + } const handleSaveChanges = async () => { - setIsSaving(true); + setIsSaving(true) if (!croppedImage) { - console.log('No cropped image available'); - setIsPopupOpen(false); - return; + console.log('No cropped image available') + setIsPopupOpen(false) + return } try { - const response = await fetch(croppedImage); - const blob = await response.blob(); + const response = await fetch(croppedImage) + const blob = await response.blob() const file = new File([blob], 'profile_picture.png', { - type: 'image/png', - }); + type: 'image/png' + }) - const formData = new FormData(); - formData.append('profilePic', file); + const formData = new FormData() + formData.append('profilePic', file) - const endPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${username}/updatePfp`; + const endPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${username}/updatePfp` const uploadResponse = await fetch(endPoint, { method: 'POST', headers: { Authorization: `Bearer ${getCookie()}`, - credentials: 'include', + credentials: 'include' }, - body: formData, - }); + body: formData + }) - const result = await uploadResponse.json(); - console.log('Here is the result: ', result); + const result = await uploadResponse.json() + console.log('Here is the result: ', result) if (result.success) { - console.log('Profile picture uploaded successfully'); - setIsSaving(false); - window.location.reload(); + console.log('Profile picture uploaded successfully') + setIsSaving(false) + window.location.reload() } else { - console.log('Failed to upload profile picture'); - setIsSaving(false); + console.log('Failed to upload profile picture') + setIsSaving(false) } } catch (err) { - console.log('An error occurred while uploading profile picture', err); + console.log('An error occurred while uploading profile picture', err) } finally { - setIsPopupOpen(false); + setIsPopupOpen(false) } - }; - + } const handleBannerSaveChanges = async () => { - setIsSaving(true); - + setIsSaving(true) try { - const response = await fetch(banner); - const blob = await response.blob(); + const response = await fetch(banner) + const blob = await response.blob() const file = new File([blob], 'banner.png', { - type: 'image/png', - }); + type: 'image/png' + }) - const formData = new FormData(); - formData.append('banner', file); + const formData = new FormData() + formData.append('banner', file) - const endPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${username}/updateBanner`; + const endPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${username}/updateBanner` const uploadResponse = await fetch(endPoint, { method: 'POST', headers: { Authorization: `Bearer ${getCookie()}`, - credentials: 'include', + credentials: 'include' }, - body: formData, - }); + body: formData + }) - const result = await uploadResponse.json(); - console.log('Here is the result: ', result); + const result = await uploadResponse.json() + console.log('Here is the result: ', result) if (result.success) { - console.log('Banner uploaded successfully'); - setIsSaving(false); - window.location.reload(); + console.log('Banner uploaded successfully') + setIsSaving(false) + window.location.reload() } else { - console.log('Failed to upload banner'); - setIsSaving(false); + console.log('Failed to upload banner') + setIsSaving(false) } } catch (err) { - console.log('An error occurred while uploading banner', err); + console.log('An error occurred while uploading banner', err) } finally { - setIsBannerPopupOpen(false); + setIsBannerPopupOpen(false) } - }; + } const saveGeneral = async () => { - setIsSaving(true); + setIsSaving(true) const data = { bio: tempBio || '', githubUrl: inputText || '', firstName: firstName || '', lastName: lastName || '', - location: location || '', - }; + location: location || '' + } try { const response = await request( `${process.env.NEXT_PUBLIC_API_URL}/account`, 'PUT', data - ); - console.log(response); - toast.success('Changes saved successfully!'); + ) + console.log(response) + toast.success('Changes saved successfully!') } catch (err) { - console.error('Failed to save general information', err); - toast.error('Failed to save changes.'); + console.error('Failed to save general information', err) + toast.error('Failed to save changes.') } finally { - setIsSaving(false); + setIsSaving(false) } - }; + } return ( -
+
This information will be displayed publicly so be careful what you share.
+
Brief description for your profile. URLs are hyperlinked.
+
This information will be displayed publicly so be careful what you share.
+
This information will be displayed publicly so be careful what you share.
+
Brief description for your profile. URLs are hyperlinked.