Skip to content

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

feat: adds solved indicator to explore card

bautistaaab3b83f081b1d
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 aef626f4..3dfe6bd2 100644
--- a/apps/web/src/app/[locale]/challenge/_components/description/index.tsx
+++ b/apps/web/src/app/[locale]/challenge/_components/description/index.tsx
@@ -91,7 +91,7 @@ export function Description({ challenge }: Props) {
{challenge.hasSolved ? (
<Tooltip>
<TooltipTrigger asChild>
- <CheckCircle className="stroke-green-600 dark:stroke-green-300" />
+ <CheckCircle className="stroke-green-600 dark:stroke-green-300" size={20} />
</TooltipTrigger>
<TooltipContent>
<p>Solved</p>
diff --git a/apps/web/src/app/[locale]/explore/_components/explore-card.tsx b/apps/web/src/app/[locale]/explore/_components/explore-card.tsx
index e7bcc323..2a09e789 100644
--- a/apps/web/src/app/[locale]/explore/_components/explore-card.tsx
+++ b/apps/web/src/app/[locale]/explore/_components/explore-card.tsx
@@ -7,7 +7,16 @@ import {
} from '@repo/ui/components/card';
import { DifficultyBadge } from '@repo/ui/components/difficulty-badge';
import { Markdown } from '@repo/ui/components/markdown';
-import { Circle, Diamond, MessageCircle, Plus, Sparkle, ThumbsUp, Triangle } from '@repo/ui/icons';
+import {
+ CheckCircle,
+ Circle,
+ Diamond,
+ MessageCircle,
+ Plus,
+ Sparkle,
+ ThumbsUp,
+ Triangle,
+} from '@repo/ui/icons';
import dynamic from 'next/dynamic';
import type { ExploreChallengeData } from './explore.action';
@@ -16,10 +25,7 @@ const RelativeTime = dynamic(() => import('./relative-time'), {
});
interface ExploreCardProps {
- challenge: Pick<
- Awaited<ExploreChallengeData>[0],
- '_count' | 'difficulty' | 'name' | 'shortDescription' | 'updatedAt' | 'user'
- >;
+ challenge: Awaited<ExploreChallengeData>[0];
}
const BORDERS_BY_DIFFICULTY = {
@@ -45,6 +51,8 @@ const SHADOWS_BY_DIFFICULTY = {
};
export function ExploreCard({ challenge }: ExploreCardProps) {
+ const hasBeenSolved = challenge.submission.length > 0;
+
return (
<Card
className={`group/card bg-background hover:bg-card-hovered relative overflow-hidden duration-300 sm:min-w-[300px] xl:min-w-[333px]
@@ -86,8 +94,11 @@ export function ExploreCard({ challenge }: ExploreCardProps) {
<CardTitle className="max-w-[75%] truncate text-2xl duration-300">
{challenge.name}
</CardTitle>
- <div className="flex items-center gap-6 text-center duration-300">
+ <div className="flex items-center gap-5 text-center duration-300">
<DifficultyBadge difficulty={challenge.difficulty} />
+ {Boolean(hasBeenSolved) && (
+ <CheckCircle className="stroke-green-600 dark:stroke-green-300" size={18} />
+ )}
<div className="flex items-center gap-2 text-sm">
<MessageCircle size={18} />
{challenge._count.comment}
diff --git a/apps/web/src/app/[locale]/explore/_components/explore.action.ts b/apps/web/src/app/[locale]/explore/_components/explore.action.ts
index 98b255ae..fceb9388 100644
--- a/apps/web/src/app/[locale]/explore/_components/explore.action.ts
+++ b/apps/web/src/app/[locale]/explore/_components/explore.action.ts
@@ -1,5 +1,6 @@
'use server';
+import { getServerAuthSession } from '@repo/auth/server';
import { prisma } from '@repo/db';
import { Tags, type Difficulty } from '@repo/db/types';
@@ -10,6 +11,7 @@ const allTags: Tags[] = Object.values(Tags);
* Fetches challenges either by tag or difficulty.
*/
export async function getChallengesByTagOrDifficulty(str: string, take?: number) {
+ const session = await getServerAuthSession();
const formattedStr = str.trim().toUpperCase();
return prisma.challenge.findMany({
@@ -38,6 +40,13 @@ export async function getChallengesByTagOrDifficulty(str: string, take?: number)
name: true,
},
},
+ submission: {
+ where: {
+ userId: session?.user.id || '',
+ isSuccessful: true,
+ },
+ take: 1,
+ },
},
...(take && {
take,