Skip to content

Commit ff25cda

Browse files
authored
Merge pull request #110 from kynhix/dev
Big refactor
2 parents 98b70dc + f1c7bb3 commit ff25cda

File tree

13 files changed

+1894
-2018
lines changed

13 files changed

+1894
-2018
lines changed

src/components/StandardNav.jsx

Lines changed: 160 additions & 187 deletions
Large diffs are not rendered by default.

src/components/dashboard/DashboardHeader.jsx

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ export function DashboardHeader() {
1919

2020
useEffect(() => {
2121
try {
22-
request(`${process.env.NEXT_PUBLIC_API_URL}/account`, 'GET', null)
22+
request(`${process.env.NEXT_PUBLIC_API_URL}/account`, 'GET', null)
2323
.then((data) => {
2424
setUsername(data.username);
2525
setLocation(data.location);
2626
localStorage.setItem("username", data.username)
27-
27+
2828
setJoin(data.createdAt.substring(0, 10));
2929
if (data.githubUrl) {
3030
setGithub(`https://github.com/${data.githubUrl}`);
@@ -41,28 +41,28 @@ export function DashboardHeader() {
4141
}, []);
4242

4343
// get user's profile picture
44-
useEffect(() => {
45-
if (!username) {
46-
return;
47-
}
48-
const fetchData = async () => {
49-
try {
50-
const endPoint = process.env.NEXT_PUBLIC_API_URL + '/users/' + username + '/pfp';
51-
const result = await request(endPoint, "GET", null);
52-
console.log(result)
53-
if (result) {
54-
setPfp(result)
55-
localStorage("pfp", result)
56-
} else {
57-
setPfp(`https://robohash.org/${username}.png?set=set1&size=150x150`)
58-
}
44+
useEffect(() => {
45+
if (!username) {
46+
return;
47+
}
48+
const fetchData = async () => {
49+
try {
50+
const endPoint = process.env.NEXT_PUBLIC_API_URL + '/users/' + username + '/pfp';
51+
const result = await request(endPoint, "GET", null);
52+
console.log(result)
53+
if (result) {
54+
setPfp(result)
55+
localStorage("pfp", result)
56+
} else {
57+
setPfp(`https://robohash.org/${username}.png?set=set1&size=150x150`)
58+
}
5959

60-
} catch (err) {
61-
console.log('failed to get profile picture')
62-
}
63-
};
64-
fetchData();
65-
}, [username]);
60+
} catch (err) {
61+
console.log('failed to get profile picture')
62+
}
63+
};
64+
fetchData();
65+
}, [username]);
6666

6767
function createPopupWin(pageURL, pageTitle,
6868
popupWinWidth, popupWinHeight) {
@@ -114,7 +114,7 @@ export function DashboardHeader() {
114114
)}
115115
</h1>
116116
<p className="text-white">
117-
<i class="fas fa-map-marker-alt mt-2"></i>{' '}
117+
<i className="fas fa-map-marker-alt mt-2"></i>{' '}
118118
{location || (
119119
<Skeleton baseColor="#262626" highlightColor="#262626" />
120120
)}
@@ -144,19 +144,15 @@ export function DashboardHeader() {
144144
)}
145145
</div>
146146

147-
148147
<div
149148
onClick={() => {
150-
151149
createPopupWin('../terminal',
152150
'CTFGuide Terminal', 1200, 650);
153-
154-
155151
}}
156152
className="hidden cursor-pointer ml-2 mt-8 mb-0 rounded-lg px-10 py-1 flex items-center space-x-1 duration-4000 bg-neutral-800 transition ease-in-out hover:bg-neutral-800/40"
157153
>
158154

159-
<p className="mt-0 text-white"><i class="fas fa-terminal mr-1"></i> Terminal</p>
155+
<p className="mt-0 text-white"><i className="fas fa-terminal mr-1"></i> Terminal</p>
160156
</div>
161157
<div
162158
className="ml-4 mt-8 mb-0 rounded-lg px-10 py-1 hidden"

src/components/dashboard/Suggest.jsx

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Link from "next/link";
2+
13
export function Suggest() {
24
return (
35
<>
@@ -10,62 +12,19 @@ export function Suggest() {
1012

1113
<div className="mb-5 grid grid-cols-2 gap-x-4">
1214
<div className="">
13-
<a href='../challenges/cypher_decoding'>
15+
<Link href='/challenges/cypher_decoding'>
1416
<div className=" relative isolate overflow-hidden rounded-md bg-black/10 bg-neutral-900 pb-4 ">
1517
<div className="relative mx-auto max-w-7xl px-5">
16-
<div
17-
className="absolute -bottom-8 -left-96 -z-10 transform-gpu blur-3xl sm:-bottom-64 sm:-left-40 lg:-bottom-32 lg:left-8 xl:-left-10"
18-
aria-hidden="true"
19-
>
20-
<div
21-
className="aspect-[1266/975] w-[79.125rem] bg-gradient-to-tr from-[#081e75] to-[#0737f2] opacity-30"
22-
style={{
23-
clipPath:
24-
'polygon(74.1% 44.1%, 100% 61.6%, 97.5% 26.9%, 85.5% 0.1%, 80.7% 2%, 72.5% 32.5%, 60.2% 62.4%, 52.4% 68.1%, 47.5% 58.3%, 45.2% 34.5%, 27.5% 76.7%, 0.1% 64.9%, 17.9% 100%, 27.6% 76.8%, 76.1% 97.7%, 74.1% 44.1%)',
25-
}}
26-
/>
27-
</div>
28-
<div className="mx-auto lg:mx-0 lg:max-w-3xl">
18+
<div className="mx-auto lg:mx-0 lg:max-w-3xl">
2919
<div className="mt-4 text-lg leading-8 text-gray-300">
3020
<h1 className=" text-xl text-white">Suggested for you </h1>
3121
<h1 className="text-2xl font-semibold text-white">Cypher Decoding</h1>
3222
</div>
3323
</div>
3424
</div>
3525
</div>
36-
</a>
37-
</div>
38-
39-
40-
<div className="">
41-
<a href='../challenges/obedient_cat'>
42-
<div className=" relative isolate overflow-hidden rounded-md bg-black/10 bg-neutral-900 pb-4 ">
43-
<div className="relative mx-auto max-w-7xl px-5">
44-
<div
45-
className="absolute -bottom-8 -left-96 -z-10 transform-gpu blur-3xl sm:-bottom-64 sm:-left-40 lg:-bottom-32 lg:left-8 xl:-left-10"
46-
aria-hidden="true"
47-
>
48-
<div
49-
className="aspect-[1266/975] w-[79.125rem] bg-gradient-to-tr from-[#081e75] to-[#0737f2] opacity-30"
50-
style={{
51-
clipPath:
52-
'polygon(74.1% 44.1%, 100% 61.6%, 97.5% 26.9%, 85.5% 0.1%, 80.7% 2%, 72.5% 32.5%, 60.2% 62.4%, 52.4% 68.1%, 47.5% 58.3%, 45.2% 34.5%, 27.5% 76.7%, 0.1% 64.9%, 17.9% 100%, 27.6% 76.8%, 76.1% 97.7%, 74.1% 44.1%)',
53-
}}
54-
/>
55-
</div>
56-
<div className="mx-auto lg:mx-0 lg:max-w-3xl">
57-
<div className="mt-4 text-lg leading-8 text-gray-300">
58-
<h1 className=" text-xl text-white">Popular on CTFGuide </h1>
59-
<h1 className="text-2xl font-semibold text-white">Obedient Cat</h1>
60-
</div>
61-
</div>
62-
</div>
63-
</div>
64-
</a>
26+
</Link>
6527
</div>
66-
67-
68-
6928
</div>
7029
</>
7130
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param props {import("react").HTMLAttributes<HTMLDivElement> & {position?: 'top' | 'left'}}
3+
*/
4+
export function CardDecorator({ className = '', position = 'top', ...props }) {
5+
const getCardStyle = (pos) => {
6+
if (pos == 'top') {
7+
return 'card-decorator-top';
8+
} else if (pos == 'left') {
9+
return 'card-decorator-left';
10+
} else {
11+
console.error('Invalid card position.')
12+
}
13+
}
14+
return (
15+
<div {...props} className={`card-decorator ${getCardStyle(position)} ${className}`}></div>
16+
);
17+
}

src/components/practice/PracticeNav.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ export function PracticeNav() {
55
return (
66
<>
77
<div
8-
className=" mt-8 flex-none text-white w-full list-none mx-auto rounded-sm shadow-lg"
9-
8+
className="w-[200px] mt-8 text-white list-none rounded-sm shadow-lg"
9+
1010
>
1111
<hr className='border-none '></hr>
12-
12+
1313
<ul className="list-none">
1414
<li className="py-1 px-2 hover:bg-neutral-800/60 rounded-sm border border-white/10 hover:border-white/30">
1515
<a
@@ -32,8 +32,8 @@ export function PracticeNav() {
3232
href="https://discord.gg/q3hgRBvgkX"
3333
className="text-lg font-medium text-white tracking-tight flex"
3434
>
35-
Join our community!
36-
<svg className="ml-2 mr-2 h-16 w-16 fill-current text-[#5865F2]" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M524.531,69.836a1.5,1.5,0,0,0-.764-.7A485.065,485.065,0,0,0,404.081,32.03a1.816,1.816,0,0,0-1.923.91,337.461,337.461,0,0,0-14.9,30.6,447.848,447.848,0,0,0-134.426,0,309.541,309.541,0,0,0-15.135-30.6,1.89,1.89,0,0,0-1.924-.91A483.689,483.689,0,0,0,116.085,69.137a1.712,1.712,0,0,0-.788.676C39.068,183.651,18.186,294.69,28.43,404.354a2.016,2.016,0,0,0,.765,1.375A487.666,487.666,0,0,0,176.02,479.918a1.9,1.9,0,0,0,2.063-.676A348.2,348.2,0,0,0,208.12,430.4a1.86,1.86,0,0,0-1.019-2.588,321.173,321.173,0,0,1-45.868-21.853,1.885,1.885,0,0,1-.185-3.126c3.082-2.309,6.166-4.711,9.109-7.137a1.819,1.819,0,0,1,1.9-.256c96.229,43.917,200.41,43.917,295.5,0a1.812,1.812,0,0,1,1.924.233c2.944,2.426,6.027,4.851,9.132,7.16a1.884,1.884,0,0,1-.162,3.126,301.407,301.407,0,0,1-45.89,21.83,1.875,1.875,0,0,0-1,2.611,391.055,391.055,0,0,0,30.014,48.815,1.864,1.864,0,0,0,2.063.7A486.048,486.048,0,0,0,610.7,405.729a1.882,1.882,0,0,0,.765-1.352C623.729,277.594,590.933,167.465,524.531,69.836ZM222.491,337.58c-28.972,0-52.844-26.587-52.844-59.239S193.056,219.1,222.491,219.1c29.665,0,53.306,26.82,52.843,59.239C275.334,310.993,251.924,337.58,222.491,337.58Zm195.38,0c-28.971,0-52.843-26.587-52.843-59.239S388.437,219.1,417.871,219.1c29.667,0,53.307,26.82,52.844,59.239C470.715,310.993,447.538,337.58,417.871,337.58Z"/></svg>
35+
Join our community!
36+
<svg className="ml-2 mr-2 h-16 w-16 fill-current text-[#5865F2]" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M524.531,69.836a1.5,1.5,0,0,0-.764-.7A485.065,485.065,0,0,0,404.081,32.03a1.816,1.816,0,0,0-1.923.91,337.461,337.461,0,0,0-14.9,30.6,447.848,447.848,0,0,0-134.426,0,309.541,309.541,0,0,0-15.135-30.6,1.89,1.89,0,0,0-1.924-.91A483.689,483.689,0,0,0,116.085,69.137a1.712,1.712,0,0,0-.788.676C39.068,183.651,18.186,294.69,28.43,404.354a2.016,2.016,0,0,0,.765,1.375A487.666,487.666,0,0,0,176.02,479.918a1.9,1.9,0,0,0,2.063-.676A348.2,348.2,0,0,0,208.12,430.4a1.86,1.86,0,0,0-1.019-2.588,321.173,321.173,0,0,1-45.868-21.853,1.885,1.885,0,0,1-.185-3.126c3.082-2.309,6.166-4.711,9.109-7.137a1.819,1.819,0,0,1,1.9-.256c96.229,43.917,200.41,43.917,295.5,0a1.812,1.812,0,0,1,1.924.233c2.944,2.426,6.027,4.851,9.132,7.16a1.884,1.884,0,0,1-.162,3.126,301.407,301.407,0,0,1-45.89,21.83,1.875,1.875,0,0,0-1,2.611,391.055,391.055,0,0,0,30.014,48.815,1.864,1.864,0,0,0,2.063.7A486.048,486.048,0,0,0,610.7,405.729a1.882,1.882,0,0,0,.765-1.352C623.729,277.594,590.933,167.465,524.531,69.836ZM222.491,337.58c-28.972,0-52.844-26.587-52.844-59.239S193.056,219.1,222.491,219.1c29.665,0,53.306,26.82,52.843,59.239C275.334,310.993,251.924,337.58,222.491,337.58Zm195.38,0c-28.971,0-52.843-26.587-52.843-59.239S388.437,219.1,417.871,219.1c29.667,0,53.307,26.82,52.844,59.239C470.715,310.993,447.538,337.58,417.871,337.58Z" /></svg>
3737
</a>
3838
</li>
3939
<li className="mb-4 py-1 hidden">

src/components/practice/community.jsx

Lines changed: 43 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useState, useEffect } from 'react';
22
import Challenge from '../challenge/ChallengeComponent';
3+
import ChallengeCard from '../profile/ChallengeCard';
34

45
export function Community({ challenges }) {
56
const [difficulty, setDifficulty] = useState('all');
@@ -38,12 +39,10 @@ export function Community({ challenges }) {
3839
setFilter(event.target.value);
3940
};
4041

41-
42-
4342
return (
4443
<>
45-
<div className="mt-10 flex max-w-6xl">
46-
<div className="w-full max-w-xs flex-row-reverse">
44+
<div className="flex flex-col md:flex-row max-w-7xl gap-4">
45+
<div className="w-full flex-row-reverse">
4746
<label
4847
htmlFor="difficulty"
4948
className="block text-sm font-medium leading-5 text-gray-200"
@@ -53,7 +52,7 @@ export function Community({ challenges }) {
5352
<select
5453
style={{ backgroundColor: '#212121' }}
5554
id="difficulty"
56-
className="mt-1 block w-full rounded border-none py-2 pr-40 pl-3 pr-10 text-base leading-6 text-white focus:outline-none sm:text-sm sm:leading-5"
55+
className="mt-1 block w-full rounded border-none text-base leading-6 text-white focus:outline-none sm:text-sm sm:leading-5"
5756
onChange={(e) => {
5857
setDifficulty(e.target.value);
5958
}}
@@ -69,7 +68,7 @@ export function Community({ challenges }) {
6968
</select>
7069
</div>
7170

72-
<div className="ml-4 w-full">
71+
<div className="w-full">
7372
<label
7473
htmlFor="sort-category"
7574
className="block text-sm font-medium leading-5 text-gray-200"
@@ -79,7 +78,7 @@ export function Community({ challenges }) {
7978
<select
8079
style={{ backgroundColor: '#212121' }}
8180
id="sort-category"
82-
className="mt-1 block w-full rounded border-none py-2 pr-40 pl-3 pr-10 text-base leading-6 text-white focus:outline-none sm:text-sm sm:leading-5"
81+
className="mt-1 block w-full rounded border-none text-base leading-6 text-white focus:outline-none sm:text-sm sm:leading-5"
8382
onChange={(e) => {
8483
setResults(
8584
[...challenges].sort((a, b) => {
@@ -110,7 +109,7 @@ export function Community({ challenges }) {
110109
<option value="basic">basic</option>
111110
</select>
112111
</div>
113-
<div className="w-full ml-4">
112+
<div className="w-full">
114113
<label
115114
htmlFor="search"
116115
className="block text-sm font-medium border-none leading-5 text-gray-200"
@@ -122,78 +121,46 @@ export function Community({ challenges }) {
122121
style={{ backgroundColor: '#212121' }}
123122
onChange={search}
124123
placeholder="Search for a Challenge"
125-
className="mt-1 block w-full rounded py-2 pr-40 pl-3 pr-10 leading-6 border-none text-white focus:outline-none sm:text-sm sm:leading-5"
124+
className="mt-1 block w-full rounded py-2 leading-6 border-none text-white focus:outline-none sm:text-sm sm:leading-5"
126125
></input>
127126
</div>
128127
</div>
129-
<div className="mt-6 max-w-6xl text-left">
130-
<h1 className="text-3xl font-semibold text-white"> Community Challenges </h1>
131-
<div className="mt-4 grid grid-cols-1 gap-4 gap-y-6 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
132-
{results.length > 0
133-
? results
134-
.filter((challenge) => {
135-
if (
136-
difficulty.toLowerCase() !== 'all' &&
137-
challenge.difficulty.toLowerCase() !== difficulty.toLowerCase()
138-
) {
139-
return false;
140-
}
141-
if (
142-
filter !== '' &&
143-
challenge.category.includes(filter.toLowerCase())
144-
) {
145-
return true;
146-
}
147-
if (
148-
filter !== '' &&
149-
!(
150-
challenge.title
151-
.toLowerCase()
152-
.includes(filter.toLowerCase()) ||
153-
challenge.content
154-
.toLowerCase()
155-
.includes(filter.toLowerCase())
156-
)
157-
) {
158-
return false;
159-
}
160-
return true;
161-
})
162-
.map((challenge, index) => (
163-
<Challenge data={challenge} key={index} />
164-
))
165-
: challenges
166-
.filter((challenge) => {
167-
if (
168-
difficulty.toLowerCase() !== 'all' &&
169-
challenge.difficulty.toLowerCase() !== difficulty.toLowerCase()
170-
) {
171-
return false;
172-
}
173-
if (
174-
filter !== '' &&
175-
challenge.category.includes(filter.toLowerCase())
176-
) {
177-
return true;
178-
}
179-
if (
180-
filter !== '' &&
181-
!(
182-
challenge.title
183-
.toLowerCase()
184-
.includes(filter.toLowerCase()) ||
185-
challenge.content
186-
.toLowerCase()
187-
.includes(filter.toLowerCase())
188-
)
189-
) {
190-
return false;
191-
}
128+
<div className="mt-6 max-w-7xl text-left">
129+
<h1 className="text-3xl font-semibold text-white mb-4"> Community Challenges </h1>
130+
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-4">
131+
{challenges && (results.length > 0 ? results : challenges)
132+
.filter((challenge) => {
133+
if (
134+
difficulty.toLowerCase() !== 'all' &&
135+
challenge.difficulty.toLowerCase() !== difficulty.toLowerCase()
136+
) {
137+
return false;
138+
}
139+
if (
140+
filter !== '' &&
141+
challenge.category.includes(filter.toLowerCase())
142+
) {
192143
return true;
193-
})
194-
.map((challenge, index) => (
195-
<Challenge data={challenge} key={index} />
196-
))}
144+
}
145+
if (
146+
filter !== '' &&
147+
!(
148+
challenge.title
149+
.toLowerCase()
150+
.includes(filter.toLowerCase()) ||
151+
challenge.content
152+
.toLowerCase()
153+
.includes(filter.toLowerCase())
154+
)
155+
) {
156+
return false;
157+
}
158+
return true;
159+
})
160+
.map((challenge) => (
161+
<ChallengeCard challenge={challenge} key={challenge.challengeId} />
162+
))
163+
}
197164
</div>
198165
</div>
199166
</>

0 commit comments

Comments
 (0)