Skip to content

feat: load on scroll to reduce cdn + robohash impact, remove weird points badge? #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"react-firebase-hooks": "^5.1.1",
"react-google-charts": "^4.0.1",
"react-image-crop": "^11.0.5",
"react-intersection-observer": "^9.13.1",
"react-joyride": "^2.7.2",
"react-loading-skeleton": "^3.2.0",
"react-markdown": "^9.0.1",
Expand Down
1 change: 1 addition & 0 deletions src/components/onboarding/DataAsk.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export function DataAsk(props) {
</p>
</div>


<div className="mx-auto mx-auto text-center mt-4">
<button
onClick={() => {
Expand Down
87 changes: 55 additions & 32 deletions src/components/practice/community.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Listbox, Transition } from '@headlessui/react';
import { CheckIcon, ChevronUpDownIcon } from '@heroicons/react/24/solid';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faFolderOpen } from '@fortawesome/free-solid-svg-icons';
import { useInView } from 'react-intersection-observer';

function getCategoryIcon(category) {
switch (category.toLowerCase()) {
Expand Down Expand Up @@ -136,6 +137,13 @@ export function Community({ challenges }) {
const [results, setResults] = useState([]);
const [filter, setFilter] = useState('');
const [solvedFilter, setSolvedFilter] = useState('all');
const [displayedResults, setDisplayedResults] = useState([]);
const [page, setPage] = useState(1);
const itemsPerPage = 12;

const { ref, inView } = useInView({
threshold: 0,
});

useEffect(() => {
if (typeof window !== 'undefined') {
Expand Down Expand Up @@ -197,8 +205,20 @@ export function Community({ challenges }) {
});

setResults(filteredChallenges);
setPage(1);
setDisplayedResults(filteredChallenges.slice(0, itemsPerPage));
}, [difficulty, category, challenges, solvedFilter]);

useEffect(() => {
if (inView && page * itemsPerPage < results.length) {
const startIndex = page * itemsPerPage;
const endIndex = startIndex + itemsPerPage;
const nextBatch = results.slice(0, endIndex);
setDisplayedResults(nextBatch);
setPage((prev) => prev + 1);
}
}, [inView, results, page]);

const search = (event) => {
setFilter(event.target.value);
};
Expand Down Expand Up @@ -317,39 +337,42 @@ export function Community({ challenges }) {
</div>
</div>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-4 mt-6">
{results.length > 0 ? (
results
.filter((challenge) => {
if (
difficulty.toLowerCase() !== 'all' &&
challenge.difficulty.toLowerCase() !== difficulty.toLowerCase()
) {
return false;
}
if (
filter !== '' &&
challenge.category.includes(filter.toLowerCase())
) {
{displayedResults.length > 0 ? (
<>
{displayedResults
.filter((challenge) => {
if (
difficulty.toLowerCase() !== 'all' &&
challenge.difficulty.toLowerCase() !== difficulty.toLowerCase()
) {
return false;
}
if (
filter !== '' &&
challenge.category.includes(filter.toLowerCase())
) {
return true;
}
if (
filter !== '' &&
!(
challenge.title
.toLowerCase()
.includes(filter.toLowerCase()) ||
challenge.content
.toLowerCase()
.includes(filter.toLowerCase())
)
) {
return false;
}
return true;
}
if (
filter !== '' &&
!(
challenge.title
.toLowerCase()
.includes(filter.toLowerCase()) ||
challenge.content
.toLowerCase()
.includes(filter.toLowerCase())
)
) {
return false;
}
return true;
})
.map((challenge) => (
<ChallengeCard challenge={challenge} key={challenge.challengeId} />
))
})
.map((challenge) => (
<ChallengeCard challenge={challenge} key={challenge.challengeId} />
))}
<div ref={ref} className="h-10 w-full col-span-full" />
</>
) : (
// kinda hacky but it works
challenges.length != 0 && (
Expand Down
7 changes: 1 addition & 6 deletions src/pages/users/[user].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -995,12 +995,7 @@ export default function Create() {
</h1>
<p className="text-white">

{user && points && (
<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">
<i className=""></i> Points: {points}
</span>
)}


<i className="fas fa-map-marker-alt mt-2"></i>{' '}
{(user && user.location) || (
<Skeleton
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7885,6 +7885,11 @@ react-innertext@^1.1.5:
resolved "https://registry.yarnpkg.com/react-innertext/-/react-innertext-1.1.5.tgz#8147ac54db3f7067d95f49e2d2c05a720d27d8d0"
integrity sha512-PWAqdqhxhHIv80dT9znP2KvS+hfkbRovFp4zFYHFFlOoQLRiawIic81gKb3U1wEyJZgMwgs3JoLtwryASRWP3Q==

react-intersection-observer@^9.13.1:
version "9.13.1"
resolved "https://registry.yarnpkg.com/react-intersection-observer/-/react-intersection-observer-9.13.1.tgz#6c61a75801162491c6348bad09967f2caf445584"
integrity sha512-tSzDaTy0qwNPLJHg8XZhlyHTgGW6drFKTtvjdL+p6um12rcnp8Z5XstE+QNBJ7c64n5o0Lj4ilUleA41bmDoMw==

react-is@^16.10.2, react-is@^16.13.1, react-is@^16.7.0:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
Expand Down