Skip to content
Closed
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
128 changes: 64 additions & 64 deletions src/components/profile/ChallengeCard.jsx
Original file line number Diff line number Diff line change
@@ -1,102 +1,102 @@
import React, { useEffect, useState } from 'react';
import { CardDecorator } from '../design/CardDecorator';
import Link from 'next/link';
import Skeleton from 'react-loading-skeleton';
import { EyeIcon, HeartIcon, PuzzlePieceIcon, ThumbUpIcon, ThumbDownIcon } from '@heroicons/react/20/solid';
import request from '@/utils/request';
import React, { useEffect, useState } from 'react'
import { CardDecorator } from '../design/CardDecorator'
import Link from 'next/link'
import Skeleton from 'react-loading-skeleton'
import { EyeIcon, HeartIcon, PuzzlePieceIcon, ThumbUpIcon, ThumbDownIcon } from '@heroicons/react/20/solid'
import request from '@/utils/request'

/**
* @param {import('react').HTMLAttributes<HTMLDivElement> & { challenge: {id: string, title: string, category: string, difficulty: string, createdAt: string, creator: string, views: number, likes: number} }} props
/**
* @param {import('react').HTMLAttributes<HTMLDivElement> & { challenge: {id: string, title: string, category: string, difficulty: string, createdAt: string, creator: string, views: number, likes: number} }} props
* */
const ChallengeCard = (_props) => {
const { challenge, ...props } = _props;
const [creatorPfp, setCreatorPfp] = useState('');
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_URL;
const { challenge, ...props } = _props
const [creatorPfp, setCreatorPfp] = useState('')
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_URL
// generate code to hit /users endpoint for each challenge creator
const [creator, setCreator] = useState(null);
const [creator, setCreator] = useState(null)
useEffect(() => {
async function fetchCreatorData(username) {
const endPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${username}`;
const result = await request(endPoint, "GET", null);
setCreator(result);
async function fetchCreatorData (username) {
const endPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${username}`
const result = await request(endPoint, 'GET', null)
setCreator(result)
if (result.profileImage) {
setCreatorPfp(result.profileImage);
setCreatorPfp(result.profileImage)
} else {
setCreatorPfp(`https://robohash.org/${username}.png?set=set1&size=150x150`);
setCreatorPfp(`https://robohash.org/${username}.png?set=set1&size=150x150`)
}
}
if (challenge && challenge.creator) {
fetchCreatorData(challenge.creator);
fetchCreatorData(challenge.creator)
}
}, [challenge]);
}, [challenge])

const dateFormatted = (date) =>
new Date(date)
.toLocaleDateString('en-US', {
month: '2-digit',
day: '2-digit',
year: 'numeric',
});
year: 'numeric'
})

const colorBG = {
'BEGINNER': 'group-hover:bg-blue-500',
'EASY': 'group-hover:bg-green-500',
'MEDIUM': 'group-hover:bg-orange-500',
'HARD': 'group-hover:bg-red-500',
'INSANE': 'group-hover:bg-purple-500',
};
BEGINNER: 'group-hover:bg-blue-500',
EASY: 'group-hover:bg-green-500',
MEDIUM: 'group-hover:bg-orange-500',
HARD: 'group-hover:bg-red-500',
INSANE: 'group-hover:bg-purple-500'
}
const colorText = {
'BEGINNER': 'bg-blue-500 text-blue-50',
'EASY': 'bg-green-500 text-green-50',
'MEDIUM': 'bg-orange-500 text-orange-50',
'HARD': 'bg-red-500 text-red-50',
'INSANE': 'bg-purple-500 text-purple-50',
};
BEGINNER: 'bg-blue-500 text-blue-50',
EASY: 'bg-green-500 text-green-50',
MEDIUM: 'bg-orange-500 text-orange-50',
HARD: 'bg-red-500 text-red-50',
INSANE: 'bg-purple-500 text-purple-50'
}
const colorBorder = {
'BEGINNER': 'border-blue-500',
'EASY': 'border-green-500',
'MEDIUM': 'border-orange-500',
'HARD': 'border-red-500',
'INSANE': 'border-purple-500',
};
BEGINNER: 'border-blue-500',
EASY: 'border-green-500',
MEDIUM: 'border-orange-500',
HARD: 'border-red-500',
INSANE: 'border-purple-500'
}

return (
challenge && (
<Link {...props} className={`group w-full border-l-4 ${colorBorder[challenge.difficulty]} bg-[#212121] px-5 py-6 transition-all duration-300 hover:bg-[#2c2c2c] ${props.className ?? ''}`} href={`${baseUrl}/challenges/${challenge.id}`} >
<div className="flex justify-between">
<h1 className="truncate text-2xl font-bold text-white w-2/3">{challenge.title}</h1>
<Link {...props} className={`group w-full border-l-4 ${colorBorder[challenge.difficulty]} bg-[#212121] px-5 py-6 transition-all duration-300 hover:bg-[#2c2c2c] ${props.className ?? ''}`} href={`${baseUrl}/challenges/${challenge.id}`}>
<div className='flex justify-between'>
<h1 className='truncate text-2xl font-bold text-white w-2/3'>{challenge.title}</h1>

<div className="flex items-center text-gray-400">
<span className='text-green-300'><i className="fas fa-arrow-up text-green-300"></i> {challenge.upvotes !== undefined ? challenge.upvotes : <Skeleton width={20} />}</span>
<span className='ml-2 text-red-300'><i className="fas fa-arrow-down text-red-200"></i> {challenge.downvotes !== undefined ? challenge.downvotes : <Skeleton width={20} />}</span>
<div className='flex items-center text-gray-400'>
<span className='text-green-300'><i className='fas fa-arrow-up text-green-300' /> {challenge.upvotes !== undefined ? challenge.upvotes : <Skeleton width={20} />}</span>
<span className='ml-2 text-red-300'><i className='fas fa-arrow-down text-red-200' /> {challenge.downvotes !== undefined ? challenge.downvotes : <Skeleton width={20} />}</span>
</div>
</div>
<div className="mt-2 flex items-center text-gray-400">
<div className='mt-2 flex items-center text-gray-400'>
<img
className="h-5 w-5 mr-2 rounded-full"
className='h-5 w-5 mr-2 rounded-full'
src={creatorPfp || 'default-profile-image-url'}
alt="Profile Picture"
alt='Profile Picture'
/>
<span>@{challenge.creator}</span>
{creator && creator.role === 'ADMIN' && (
<span className="text-red-500 text-xs ml-1"><i className="fas fa-code fa-fw"></i></span>
<span className='text-red-500 text-xs ml-1'><i className='fas fa-code fa-fw' /></span>
)}
{creator && creator.role === 'PRO' && (
<span className="text-yellow-500 text-xs ml-1"><i className="fas fa-crown fa-fw"></i></span>
)}
<span className='text-yellow-500 text-xs ml-1'><i className='fas fa-crown fa-fw' /></span>

)}
</div>

<div className="mt-4 flex items-center">
<PuzzlePieceIcon className="h-5 w-5 mr-2 text-white" />
<span className="text-white">{challenge.category}</span>
<div className='mt-4 flex items-center'>
<PuzzlePieceIcon className='h-5 w-5 mr-2 text-white' />
<span className='text-white'>{challenge.category}</span>
<span className={`ml-4 px-2 rounded-sm text-sm font-bold capitalize ${colorText[challenge.difficulty || 0]}`}>{challenge.difficulty?.toLowerCase() || <Skeleton />}</span>

<div className=" ml-auto flex text-gray-400">
<EyeIcon className="h-5 w-5 mr-2" />
<span>{challenge.views !== undefined ? challenge.views : <Skeleton width={20} />}</span>
</div>
<div className=' ml-auto flex text-gray-400'>
<EyeIcon className='h-5 w-5 mr-2' />
<span>{challenge.views !== undefined ? challenge.views : <Skeleton width={20} />}</span>

</div>
</div>
</Link>
) || (
Expand All @@ -107,7 +107,7 @@ const ChallengeCard = (_props) => {
<Skeleton baseColor='#262626' highlightColor='#3a3a3a' />
</div>
)
);
};
)
}

export default ChallengeCard;
export default ChallengeCard
79 changes: 41 additions & 38 deletions src/components/profile/Following.jsx
Original file line number Diff line number Diff line change
@@ -1,74 +1,77 @@
import React from 'react';
import { CardDecorator } from '../design/CardDecorator';
import Link from 'next/link';
import Skeleton from 'react-loading-skeleton';
import { Tooltip } from 'react-tooltip';
import FriendCard from '../social/FriendCard';
import React from 'react'
import { CardDecorator } from '../design/CardDecorator'
import Link from 'next/link'
import Skeleton from 'react-loading-skeleton'
import { Tooltip } from 'react-tooltip'
import FriendCard from '../social/FriendCard'

const Following = ({ followings, pageData, userData }) => {
const { user, ownUser } = userData;
const { setDisplayMode, page, totalPages, prevPage, nextPage } = pageData;
const { user, ownUser } = userData
const { setDisplayMode, page, totalPages, prevPage, nextPage } = pageData

return (
<>
<div className="bg-neutral-800 px-4 py-4">
<div className="flex">
<div className='bg-neutral-800 px-4 py-4'>
<div className='flex'>
<span>
<i
class="fas fa-angle-double-left mr-2 py-1.5 text-2xl text-white hover:text-gray-400"
class='fas fa-angle-double-left mr-2 py-1.5 text-2xl text-white hover:text-gray-400'
onClick={() => setDisplayMode('default')}
></i>
/>
</span>
<h1 className="mb-4 text-2xl font-bold uppercase text-white">
<h1 className='mb-4 text-2xl font-bold uppercase text-white'>
{user && user.username}'s Following
</h1>
</div>

{followings.length>0 ? (
<div className="gap-4">
<div className="flex justify-center p-4">
<div className="grid max-w-7xl grid-cols-1 gap-1 md:grid-cols-2 lg:grid-cols-3">
{followings.length > 0 ? (
followings.map((following, index) => (
<FriendCard key={index} data={following} mutual={true} />
))
) : (
<p className="col-span-3 text-lg text-white">
You have no friends yet.
</p>
)}
{followings.length > 0
? (
<div className='gap-4'>
<div className='flex justify-center p-4'>
<div className='grid max-w-7xl grid-cols-1 gap-1 md:grid-cols-2 lg:grid-cols-3'>
{followings.length > 0
? (
followings.map((following, index) => (
<FriendCard key={index} data={following} mutual />
))
)
: (
<p className='col-span-3 text-lg text-white'>
You have no friends yet.
</p>
)}
</div>
</div>
</div>
</div>
) : (
<p className="text-neutral-400">{user && user.username} is not following anyone yet.</p>
)}
)
: (
<p className='text-neutral-400'>{user && user.username} is not following anyone yet.</p>
)}
{totalPages > 0 && (
<div className="flex items-center justify-center gap-x-5 py-4">
<div className='flex items-center justify-center gap-x-5 py-4'>
<button
onClick={prevPage}
className="w-24 rounded-sm bg-gray-800 px-4 py-2 font-bold text-white hover:bg-gray-700 disabled:opacity-50 "
className='w-24 rounded-sm bg-gray-800 px-4 py-2 font-bold text-white hover:bg-gray-700 disabled:opacity-50 '
disabled={page === 0}
>
Previous
</button>
<span className="text-white">
<span className='text-white'>
Page {page + 1} of {totalPages}
</span>
<button
onClick={nextPage}
className="w-24 rounded-sm bg-gray-800 px-4 py-2 font-bold text-white hover:bg-gray-700 disabled:opacity-50"
className='w-24 rounded-sm bg-gray-800 px-4 py-2 font-bold text-white hover:bg-gray-700 disabled:opacity-50'
disabled={page + 1 >= totalPages}
>
Next
</button>
</div>
)}
</div>


</>
);
};
)
}

export default Following;
export default Following
Loading