diff --git a/src/components/profile/v2/CreatedChallenges.jsx b/src/components/profile/v2/CreatedChallenges.jsx index 5b36a8b9..1a07499e 100644 --- a/src/components/profile/v2/CreatedChallenges.jsx +++ b/src/components/profile/v2/CreatedChallenges.jsx @@ -1,76 +1,78 @@ -import React, { useEffect, useState } from 'react'; -import request from '@/utils/request'; -import ChallengeCard from '@/components/profile/ChallengeCard'; +import React, { useEffect, useState } from 'react' +import request from '@/utils/request' +import ChallengeCard from '@/components/profile/ChallengeCard' const CreatedChallenges = ({ user }) => { - const [createdChallenges, setCreatedChallenges] = useState([]); - const [displayedChallenges, setDisplayedChallenges] = useState([]); - const [page, setPage] = useState(1); - const [hasMore, setHasMore] = useState(true); - const challengesPerPage = 4; + const [createdChallenges, setCreatedChallenges] = useState([]) + const [displayedChallenges, setDisplayedChallenges] = useState([]) + const [page, setPage] = useState(1) + const [hasMore, setHasMore] = useState(true) + const challengesPerPage = 4 useEffect(() => { if (!user) { - return; + return } const fetchData = async () => { try { - const challengeEndPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${user.username}/challenges`; - const challengeResult = await request(challengeEndPoint, 'GET', null); + const challengeEndPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${user.username}/challenges` + const challengeResult = await request(challengeEndPoint, 'GET', null) if (!challengeResult || challengeResult.length === 0) { - setHasMore(false); - return; + setHasMore(false) + return } const publicChallenges = challengeResult.filter( (challenge) => challenge.state === 'STANDARD_VERIFIED' - ); - setCreatedChallenges(publicChallenges); - setDisplayedChallenges(publicChallenges.slice(0, challengesPerPage)); + ) + setCreatedChallenges(publicChallenges) + setDisplayedChallenges(publicChallenges.slice(0, challengesPerPage)) } catch (err) { - console.log(err); + console.log(err) } - }; + } - fetchData(); - }, [user]); + fetchData() + }, [user]) const loadMore = () => { - const nextPage = page + 1; - const newChallenges = createdChallenges.slice(0, nextPage * challengesPerPage); - setDisplayedChallenges(newChallenges); - setPage(nextPage); + const nextPage = page + 1 + const newChallenges = createdChallenges.slice(0, nextPage * challengesPerPage) + setDisplayedChallenges(newChallenges) + setPage(nextPage) if (newChallenges.length === createdChallenges.length) { - setHasMore(false); + setHasMore(false) } - }; + } return ( -
-
+