Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

feat: add challenge suggestions with problem. (#1255)

Ayush Kumar Yadav3f01a82d4b36
diff --git a/apps/web/src/app/[locale]/challenge/_components/description/index.tsx b/apps/web/src/app/[locale]/challenge/_components/description/index.tsx
index 0178c20b..be8733f4 100644
--- a/apps/web/src/app/[locale]/challenge/_components/description/index.tsx
+++ b/apps/web/src/app/[locale]/challenge/_components/description/index.tsx
@@ -28,6 +28,7 @@ import { addOrRemoveBookmark } from '../bookmark.action';
import { ShareForm } from '../share-form';
import { Vote } from '../vote';
import { AOT_CHALLENGES } from '../../[slug]/aot-slugs';
+import { Suggestions } from './suggestions';
interface Props {
challenge: ChallengeRouteData['challenge'];
@@ -175,6 +176,8 @@ export function Description({ challenge }: Props) {
<div className="prose-invert prose-h3:text-xl mt-6 leading-7">
<Markdown>{challenge.description}</Markdown>
</div>
+ {/* More Challenges Suggestions */}
+ <Suggestions challengeId={challenge.id} />
</div>
);
}
diff --git a/apps/web/src/app/[locale]/challenge/_components/description/suggestions-skeleton.tsx b/apps/web/src/app/[locale]/challenge/_components/description/suggestions-skeleton.tsx
new file mode 100644
index 00000000..f85a7a82
--- /dev/null
+++ b/apps/web/src/app/[locale]/challenge/_components/description/suggestions-skeleton.tsx
@@ -0,0 +1,20 @@
+import { Skeleton } from '@repo/ui/components/skeleton';
+
+export function SuggestionsSkeleton() {
+ return (
+ <div className="mt-2 flex flex-col gap-2">
+ <div className="flex h-10 w-full items-center justify-between rounded-3xl bg-neutral-500/10 px-3 dark:from-neutral-900/70 lg:rounded-lg">
+ <Skeleton className="h-6 w-1/2 rounded bg-zinc-300 dark:bg-zinc-700" />
+ <Skeleton className="h-6 w-14 rounded-full bg-zinc-300 dark:bg-zinc-700" />
+ </div>
+ <div className="flex h-10 w-full items-center justify-between rounded-3xl bg-neutral-500/10 px-3 dark:from-neutral-900/70 lg:rounded-lg">
+ <Skeleton className="h-6 w-1/2 rounded bg-zinc-300 dark:bg-zinc-700" />
+ <Skeleton className="h-6 w-14 rounded-full bg-zinc-300 dark:bg-zinc-700" />
+ </div>
+ <div className="flex h-10 w-full items-center justify-between rounded-3xl bg-neutral-500/10 px-3 dark:from-neutral-900/70 lg:rounded-lg">
+ <Skeleton className="h-6 w-1/2 rounded bg-zinc-300 dark:bg-zinc-700" />
+ <Skeleton className="h-6 w-14 rounded-full bg-zinc-300 dark:bg-zinc-700" />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/[locale]/challenge/_components/description/suggestions.tsx b/apps/web/src/app/[locale]/challenge/_components/description/suggestions.tsx
new file mode 100644
index 00000000..d03d359e
--- /dev/null
+++ b/apps/web/src/app/[locale]/challenge/_components/description/suggestions.tsx
@@ -0,0 +1,46 @@
+import { useQuery } from '@tanstack/react-query';
+import Link from 'next/link';
+import { TrackChallenge } from '~/app/[locale]/tracks/_components/track-challenge-card';
+import { getSimilarChallenges } from '~/utils/server/get-similar-challenges';
+import { SuggestionsSkeleton } from './suggestions-skeleton';
+
+export function Suggestions({ challengeId }: { challengeId: number }) {
+ const { data: similarChallenges, status } = useQuery({
+ queryKey: ['similar-challenges', challengeId],
+ queryFn: () => {
+ return getSimilarChallenges(challengeId, 3);
+ },
+ });
+
+ if (status === 'error') {
+ return null;
+ }
+
+ return (
+ <div>
+ <div className="flex items-center justify-between">
+ <h3 className="text-foreground text-lg font-semibold md:text-xl">More Challenges</h3>
+ </div>
+ {status === 'pending' ? (
+ <SuggestionsSkeleton />
+ ) : (
+ <div>
+ {similarChallenges?.map((challenge, idx) => {
+ return (
+ <Link href={`/challenge/${challenge.slug}`} key={idx}>
+ <TrackChallenge
+ className="to-neutral-500/10 px-3 py-2 dark:from-neutral-700/70 dark:to-neutral-700/70"
+ challenge={{ ...challenge, submission: [] }}
+ hideSubmissionStatus
+ isCompleted={false}
+ isCompact
+ isInProgress={false}
+ />
+ </Link>
+ );
+ })}
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/apps/web/src/app/[locale]/tracks/_components/track-challenge-card.tsx b/apps/web/src/app/[locale]/tracks/_components/track-challenge-card.tsx
index 4426a41b..a344ec56 100644
--- a/apps/web/src/app/[locale]/tracks/_components/track-challenge-card.tsx
+++ b/apps/web/src/app/[locale]/tracks/_components/track-challenge-card.tsx
@@ -20,6 +20,7 @@ interface TrackChallengeProps {
isCompact?: boolean;
/* Hide submission status */
hideSubmissionStatus?: boolean;
+ className?: string;
}
const BGS_BY_DIFFICULTY = {
@@ -40,6 +41,7 @@ export function TrackChallenge({
isSelected = false,
isCompact = false,
hideSubmissionStatus = false,
+ className,
}: TrackChallengeProps) {
const isMobile = useIsMobile();
const backgroundColor = isCompleted
@@ -66,6 +68,7 @@ export function TrackChallenge({
'group-hover/challenge:scale-[1.025] group-hover/challenge:bg-neutral-500/20 lg:group-hover/challenge:rounded-xl':
!isMobile,
},
+ className,
)}
>
<div className="w-full space-y-2">