Skip to content

Commit f81a98b

Browse files
authored
Merge pull request #216 from ctfguide-tech/dev
2 parents 3a9ce4b + e149257 commit f81a98b

File tree

5 files changed

+63
-38
lines changed

5 files changed

+63
-38
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"react-firebase-hooks": "^5.1.1",
6464
"react-google-charts": "^4.0.1",
6565
"react-image-crop": "^11.0.5",
66+
"react-intersection-observer": "^9.13.1",
6667
"react-joyride": "^2.7.2",
6768
"react-loading-skeleton": "^3.2.0",
6869
"react-markdown": "^9.0.1",

src/components/onboarding/DataAsk.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export function DataAsk(props) {
262262
</p>
263263
</div>
264264

265+
265266
<div className="mx-auto mx-auto text-center mt-4">
266267
<button
267268
onClick={() => {

src/components/practice/community.jsx

+55-32
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Listbox, Transition } from '@headlessui/react';
55
import { CheckIcon, ChevronUpDownIcon } from '@heroicons/react/24/solid';
66
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
77
import { faFolderOpen } from '@fortawesome/free-solid-svg-icons';
8+
import { useInView } from 'react-intersection-observer';
89

910
function getCategoryIcon(category) {
1011
switch (category.toLowerCase()) {
@@ -136,6 +137,13 @@ export function Community({ challenges }) {
136137
const [results, setResults] = useState([]);
137138
const [filter, setFilter] = useState('');
138139
const [solvedFilter, setSolvedFilter] = useState('all');
140+
const [displayedResults, setDisplayedResults] = useState([]);
141+
const [page, setPage] = useState(1);
142+
const itemsPerPage = 12;
143+
144+
const { ref, inView } = useInView({
145+
threshold: 0,
146+
});
139147

140148
useEffect(() => {
141149
if (typeof window !== 'undefined') {
@@ -197,8 +205,20 @@ export function Community({ challenges }) {
197205
});
198206

199207
setResults(filteredChallenges);
208+
setPage(1);
209+
setDisplayedResults(filteredChallenges.slice(0, itemsPerPage));
200210
}, [difficulty, category, challenges, solvedFilter]);
201211

212+
useEffect(() => {
213+
if (inView && page * itemsPerPage < results.length) {
214+
const startIndex = page * itemsPerPage;
215+
const endIndex = startIndex + itemsPerPage;
216+
const nextBatch = results.slice(0, endIndex);
217+
setDisplayedResults(nextBatch);
218+
setPage((prev) => prev + 1);
219+
}
220+
}, [inView, results, page]);
221+
202222
const search = (event) => {
203223
setFilter(event.target.value);
204224
};
@@ -317,39 +337,42 @@ export function Community({ challenges }) {
317337
</div>
318338
</div>
319339
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-4 mt-6">
320-
{results.length > 0 ? (
321-
results
322-
.filter((challenge) => {
323-
if (
324-
difficulty.toLowerCase() !== 'all' &&
325-
challenge.difficulty.toLowerCase() !== difficulty.toLowerCase()
326-
) {
327-
return false;
328-
}
329-
if (
330-
filter !== '' &&
331-
challenge.category.includes(filter.toLowerCase())
332-
) {
340+
{displayedResults.length > 0 ? (
341+
<>
342+
{displayedResults
343+
.filter((challenge) => {
344+
if (
345+
difficulty.toLowerCase() !== 'all' &&
346+
challenge.difficulty.toLowerCase() !== difficulty.toLowerCase()
347+
) {
348+
return false;
349+
}
350+
if (
351+
filter !== '' &&
352+
challenge.category.includes(filter.toLowerCase())
353+
) {
354+
return true;
355+
}
356+
if (
357+
filter !== '' &&
358+
!(
359+
challenge.title
360+
.toLowerCase()
361+
.includes(filter.toLowerCase()) ||
362+
challenge.content
363+
.toLowerCase()
364+
.includes(filter.toLowerCase())
365+
)
366+
) {
367+
return false;
368+
}
333369
return true;
334-
}
335-
if (
336-
filter !== '' &&
337-
!(
338-
challenge.title
339-
.toLowerCase()
340-
.includes(filter.toLowerCase()) ||
341-
challenge.content
342-
.toLowerCase()
343-
.includes(filter.toLowerCase())
344-
)
345-
) {
346-
return false;
347-
}
348-
return true;
349-
})
350-
.map((challenge) => (
351-
<ChallengeCard challenge={challenge} key={challenge.challengeId} />
352-
))
370+
})
371+
.map((challenge) => (
372+
<ChallengeCard challenge={challenge} key={challenge.challengeId} />
373+
))}
374+
<div ref={ref} className="h-10 w-full col-span-full" />
375+
</>
353376
) : (
354377
// kinda hacky but it works
355378
challenges.length != 0 && (

src/pages/users/[user].jsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -995,12 +995,7 @@ export default function Create() {
995995
</h1>
996996
<p className="text-white">
997997

998-
{user && points && (
999-
<span className="mr-2 font-bold rounded-sm bg-gradient-to-br from-green-400 to-blue-600 px-2 py-1 text-sm text-white">
1000-
<i className=""></i> Points: {points}
1001-
</span>
1002-
)}
1003-
998+
1004999
<i className="fas fa-map-marker-alt mt-2"></i>{' '}
10051000
{(user && user.location) || (
10061001
<Skeleton

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -7885,6 +7885,11 @@ react-innertext@^1.1.5:
78857885
resolved "https://registry.yarnpkg.com/react-innertext/-/react-innertext-1.1.5.tgz#8147ac54db3f7067d95f49e2d2c05a720d27d8d0"
78867886
integrity sha512-PWAqdqhxhHIv80dT9znP2KvS+hfkbRovFp4zFYHFFlOoQLRiawIic81gKb3U1wEyJZgMwgs3JoLtwryASRWP3Q==
78877887

7888+
react-intersection-observer@^9.13.1:
7889+
version "9.13.1"
7890+
resolved "https://registry.yarnpkg.com/react-intersection-observer/-/react-intersection-observer-9.13.1.tgz#6c61a75801162491c6348bad09967f2caf445584"
7891+
integrity sha512-tSzDaTy0qwNPLJHg8XZhlyHTgGW6drFKTtvjdL+p6um12rcnp8Z5XstE+QNBJ7c64n5o0Lj4ilUleA41bmDoMw==
7892+
78887893
react-is@^16.10.2, react-is@^16.13.1, react-is@^16.7.0:
78897894
version "16.13.1"
78907895
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"

0 commit comments

Comments
 (0)