From aa8227755b30b8fd47d085cc21e2996f83569e65 Mon Sep 17 00:00:00 2001 From: davidyoum Date: Sat, 5 Apr 2025 13:24:39 -0400 Subject: [PATCH 1/6] Reverted to old edit.jsx --- src/pages/create/edit.jsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pages/create/edit.jsx b/src/pages/create/edit.jsx index 1a748b59..767ad52c 100644 --- a/src/pages/create/edit.jsx +++ b/src/pages/create/edit.jsx @@ -334,6 +334,10 @@ export default function Createchall() { const url = `${process.env.NEXT_PUBLIC_API_URL}/challenges/${router.query.id}`; const body = challengeInfo; + const hintURL = `${process.env.NEXT_PUBLIC_API_URL}/challenges/${router.query.id}/getHints`; + const hintData = await request(hintURL, "GET", null); + console.log(hintData) + console.log('Sending request to:', url, 'with body:', body); const data = await request(url, "PUT", body); @@ -361,13 +365,18 @@ export default function Createchall() { console.log(challengeId) const url = `${process.env.NEXT_PUBLIC_API_URL}/challenges/${challengeId}`; + const hintURL = `${process.env.NEXT_PUBLIC_API_URL}/challenges/${challengeId}/getHints`; + const data = await request(url, 'GET', null); + const hintData = await request(hintURL, 'GET', null); + if (data && data.success) { const challenge = data.body; + const hints = hintData.body; setNewChallengeName(challenge.title); setCategory(challenge.category[0]); - //setHints(challenge.hints); - // setPenalty(challenge.penalty); + setHints(hints); + setPenalty(challenge.penalty); setContentPreview(challenge.content); setSolution(challenge.solution); setDifficulty(challenge.difficulty.toLowerCase()); From a9925b6febe8e953116f5486bb58423eb21d8bef Mon Sep 17 00:00:00 2001 From: davidyoum Date: Mon, 7 Apr 2025 10:53:35 -0400 Subject: [PATCH 2/6] Implemented edits for solution and the hints. Also added the preview for the hints. --- src/pages/create/edit.jsx | 146 +++++++++++++++++++++++++++++++------- 1 file changed, 121 insertions(+), 25 deletions(-) diff --git a/src/pages/create/edit.jsx b/src/pages/create/edit.jsx index 767ad52c..d71ced62 100644 --- a/src/pages/create/edit.jsx +++ b/src/pages/create/edit.jsx @@ -317,31 +317,26 @@ export default function Createchall() { const uploadChallenge = async (fileId) => { setSending(true); try { - const nConfig = newConfig.replace('\n', ' && '); - - console.log('Uploading challenge with category:', category); - + // Include both challenge info and hints in one object const challengeInfo = { title: newChallengeName, category: [`${category}`], content: contentPreview, difficulty: difficulty.toUpperCase(), + hints: hints, // Add hints array directly + penalties: penalty, // Add penalties array directly + keyword: solution }; - console.log("updating with this info...") - console.log(challengeInfo) - - const url = `${process.env.NEXT_PUBLIC_API_URL}/challenges/${router.query.id}`; - const body = challengeInfo; + console.log("Updating challenge with:", challengeInfo); - const hintURL = `${process.env.NEXT_PUBLIC_API_URL}/challenges/${router.query.id}/getHints`; - const hintData = await request(hintURL, "GET", null); - console.log(hintData) + const challengeUrl = `${process.env.NEXT_PUBLIC_API_URL}/challenges/${router.query.id}`; - console.log('Sending request to:', url, 'with body:', body); - const data = await request(url, "PUT", body); + // Single PUT request with all data + const challengeData = await request(challengeUrl, "PUT", challengeInfo); + console.log("Challenge update response:", challengeData); - if (data && data.slug) { + if (challengeData && challengeData.slug) { toast.success('Challenge updated successfully'); window.location.href = '/create'; } else { @@ -349,6 +344,7 @@ export default function Createchall() { } } catch (err) { console.error('Error during challenge upload:', err); + console.error('Error details:', err.response?.data || err.message); toast.error('An error occurred during challenge upload'); } setSending(false); @@ -364,7 +360,6 @@ export default function Createchall() { const challengeId = router.query.id; console.log(challengeId) const url = `${process.env.NEXT_PUBLIC_API_URL}/challenges/${challengeId}`; - const hintURL = `${process.env.NEXT_PUBLIC_API_URL}/challenges/${challengeId}/getHints`; const data = await request(url, 'GET', null); @@ -372,13 +367,13 @@ export default function Createchall() { if (data && data.success) { const challenge = data.body; - const hints = hintData.body; + console.log(challenge) setNewChallengeName(challenge.title); setCategory(challenge.category[0]); - setHints(hints); - setPenalty(challenge.penalty); + setHints(hintData.hintArray.map(hint => hint.message)); + setPenalty(hintData.hintArray.map(hint => hint.penalty)); setContentPreview(challenge.content); - setSolution(challenge.solution); + setSolution(challenge.solution.keyword); setDifficulty(challenge.difficulty.toLowerCase()); setNewConfig(challenge.commands.replace(/ && /g, '\n')); } @@ -563,7 +558,6 @@ export default function Createchall() { - + + +
+ {hints.map((hint, idx) => { + return ( +
+
+ Hint {idx + 1} +
+
+ + { + setPenalty((prevState) => { + let newState = [...prevState]; + newState[idx] = parseInt(e.target.value); + return newState; + }); + }} + max={100} + min={0} + placeholder={idx * 5} + type="number" + className={ + penaltyErr === '' + ? 'mt-1 w-full rounded-lg border-neutral-800 bg-neutral-900 text-white shadow-lg' + : 'mt-1 w-full rounded-lg border-red-800 bg-neutral-900 text-white shadow-lg' + } + style={{ flexBasis: '15%' }} + /> +
+
+ ); + })} +
@@ -596,13 +643,64 @@ export default function Createchall() {
- +
+

Hints

+
toast.info(`Psst, you're in preview mode.`)} + > +
+

Hint 1

+
+ + {penalty[0]}% penalty + +
+
+
+ {hints[0]} +
+
+
toast.info(`Psst, you're in preview mode.`)} + > +
+

Hint 2

+
+ + {penalty[1]}% penalty + +
+
+
+ {hints[1]} +
+
+
toast.info(`Psst, you're in preview mode.`)} + > +
+

Hint 3

+
+ + {penalty[2]}% penalty + +
+
+
+ {hints[2]} +
+
+
-
+ +

Challenge Solution @@ -619,8 +717,6 @@ export default function Createchall() {

- -