Skip to content

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

explore carousel and sum stuff (#337)

PickleNik63c371666e79
diff --git a/src/components/explore/explore-card.tsx b/src/components/explore/explore-card.tsx
index 0747f8d3..f00ce8ff 100644
--- a/src/components/explore/explore-card.tsx
+++ b/src/components/explore/explore-card.tsx
@@ -47,7 +47,7 @@ const GRADIENTS_BY_DIFFICULTY = {
export const ExploreCard = ({ challenge }: ExploreCardProps) => {
return (
<Card
- className={`group relative overflow-hidden duration-300 sm:min-w-[300px] xl:min-w-[382px]
+ className={`group relative overflow-hidden duration-300 sm:min-w-[300px] xl:min-w-[333px]
${GRADIENTS_BY_DIFFICULTY[challenge.difficulty]}
${SHADOWS_BY_DIFFICULTY[challenge.difficulty]}
${BORDERS_BY_DIFFICULTY[challenge.difficulty]}
diff --git a/src/components/explore/section-carousel.tsx b/src/components/explore/section-carousel.tsx
new file mode 100644
index 00000000..9dd29396
--- /dev/null
+++ b/src/components/explore/section-carousel.tsx
@@ -0,0 +1,115 @@
+'use client';
+import Link from 'next/link';
+import { ExploreCard } from './explore-card';
+import type { Difficulty } from '@prisma/client';
+import { useEffect, useRef, useState } from 'react';
+import { ChevronRight } from 'lucide-react';
+import type { ExploreChallengeFetcher } from '.';
+
+interface Props {
+ challenges: Awaited<ReturnType<ExploreChallengeFetcher>>;
+}
+
+const difficultyToNumber: Record<Difficulty, number> = {
+ BEGINNER: 0,
+ EASY: 1,
+ MEDIUM: 2,
+ HARD: 3,
+ EXTREME: 4,
+};
+
+export function ExploreCarousel({ challenges }: Props) {
+ const containerRef = useRef<HTMLDivElement>(null);
+ const [showLeftButton, setShowLeftButton] = useState(false);
+ const [showRightButton, setShowRightButton] = useState(true);
+
+ useEffect(() => {
+ const containerElement = containerRef.current;
+
+ const handleSlideRight = () => {
+ if (containerElement) {
+ containerElement.scrollLeft += 330;
+ }
+ };
+
+ const handleSlideLeft = () => {
+ if (containerElement) {
+ containerElement.scrollLeft -= 330;
+ }
+ };
+
+ const handleScroll = () => {
+ if (containerElement) {
+ const scrollLeft = containerElement.scrollLeft;
+ const scrollWidth = containerElement.scrollWidth;
+ const clientWidth = containerElement.clientWidth;
+
+ setShowLeftButton(scrollLeft > 0);
+ setShowRightButton(scrollLeft + clientWidth < scrollWidth);
+ }
+ };
+
+ const buttonRight = containerElement?.querySelector('#slideRight');
+ const buttonLeft = containerElement?.querySelector('#slideLeft');
+
+ if (containerElement) {
+ containerElement.addEventListener('scroll', handleScroll);
+ }
+
+ if (buttonRight) {
+ buttonRight.addEventListener('click', handleSlideRight);
+ }
+
+ if (buttonLeft) {
+ buttonLeft.addEventListener('click', handleSlideLeft);
+ }
+
+ return () => {
+ if (containerElement) {
+ containerElement.removeEventListener('scroll', handleScroll);
+ }
+ if (buttonRight) {
+ buttonRight.removeEventListener('click', handleSlideRight);
+ }
+ if (buttonLeft) {
+ buttonLeft.removeEventListener('click', handleSlideLeft);
+ }
+ };
+ }, []);
+
+ return (
+ <div
+ id="container"
+ ref={containerRef}
+ className="hide-scrollbar flex w-full snap-x flex-nowrap gap-4 overflow-x-scroll scroll-smooth p-6"
+ >
+ {challenges
+ .sort((a, b) =>
+ difficultyToNumber[a.difficulty] !== difficultyToNumber[b.difficulty]
+ ? difficultyToNumber[a.difficulty] - difficultyToNumber[b.difficulty]
+ : a.name.localeCompare(b.name),
+ )
+ .map((challenge) => (
+ <Link
+ className="group snap-center focus:outline-none sm:w-[330px] xl:w-[333px]"
+ href={`/challenge/${challenge.id}`}
+ key={challenge.id}
+ >
+ <ExploreCard key={`challenge-${challenge.id}`} challenge={challenge} />
+ </Link>
+ ))}
+ <button
+ className="absolute -right-5 top-1/2 hidden -translate-y-1/2 rounded-[5rem] bg-background p-4 pl-1 duration-300 active:scale-95 sm:block"
+ id="slideRight"
+ >
+ <ChevronRight className="h-4 w-4" />
+ </button>
+ <button
+ className="absolute -left-5 top-1/2 hidden -translate-y-1/2 rounded-[5rem] bg-background p-4 pr-1 duration-300 active:scale-95 sm:block"
+ id="slideLeft"
+ >
+ <ChevronRight className="h-4 w-4 rotate-180 transform" />
+ </button>
+ </div>
+ );
+}
diff --git a/src/components/explore/section.tsx b/src/components/explore/section.tsx
index 219a1ac8..02184282 100644
--- a/src/components/explore/section.tsx
+++ b/src/components/explore/section.tsx
@@ -1,25 +1,13 @@
-import Link from 'next/link';
-
-import { ExploreCard } from './explore-card';
-
import type { ExploreChallengeFetcher } from '.';
-import type { Difficulty } from '@prisma/client';
import { Button } from '../ui/button';
-import { ChevronRight, Circle, Diamond, Plus, Sparkle, Triangle } from 'lucide-react';
+import { ChevronRight, Diamond } from 'lucide-react';
+import { ExploreCarousel } from './section-carousel';
interface Props {
title: string;
fetcher: ExploreChallengeFetcher;
}
-const difficultyToNumber: Record<Difficulty, number> = {
- BEGINNER: 0,
- EASY: 1,
- MEDIUM: 2,
- HARD: 3,
- EXTREME: 4,
-};
-
const COLORS_BY_DIFFICULTY = {
BEGINNER: 'bg-gradient-to-r from-50% from-pink-600/10 dark:from-pink-500/10',
EASY: 'bg-gradient-to-r from-50% from-green-600/10 dark:from-green-500/10',
@@ -75,7 +63,7 @@ export async function ExploreSection({ title, fetcher }: Props) {
</>
)}
- <div className="flex items-center justify-between p-5 pb-0 pl-7">
+ <div className="flex items-center justify-between gap-3 p-5 pb-0 pl-7">
{/* <div className="hidden w-[117px] md:block"></div> */}
<h2
className={`bg-clip-text text-3xl font-bold tracking-tight text-transparent ${
@@ -93,23 +81,7 @@ export async function ExploreSection({ title, fetcher }: Props) {
<ChevronRight className="ml-2 h-4 w-4 stroke-[3] duration-300 group-hover:translate-x-1" />
</Button>
</div>
- <div className="hide-scrollbar flex w-full snap-x flex-nowrap gap-4 overflow-x-scroll p-5">
- {challenges
- .sort((a, b) =>
- difficultyToNumber[a.difficulty] !== difficultyToNumber[b.difficulty]
- ? difficultyToNumber[a.difficulty] - difficultyToNumber[b.difficulty]
- : a.name.localeCompare(b.name),
- )
- .map((challenge) => (
- <Link
- className="group snap-center focus:outline-none sm:w-[330px] xl:w-[382px]"
- href={`/challenge/${challenge.id}`}
- key={challenge.id}
- >
- <ExploreCard key={`challenge-${challenge.id}`} challenge={challenge} />
- </Link>
- ))}
- </div>
+ <ExploreCarousel challenges={challenges} />
</section>
);
}
diff --git a/src/components/landing/hero.tsx b/src/components/landing/hero.tsx
index 4bc2ff8f..d881d2c9 100644
--- a/src/components/landing/hero.tsx
+++ b/src/components/landing/hero.tsx
@@ -124,7 +124,7 @@ const Hero = () => (
className="group"
>
<HeroChallengeCard
- difficulty="BEGINNER"
+ difficulty="EASY"
className="absolute"
title="Implement a union type of number and string"
prompt="Implement a union type of number and string"
diff --git a/src/components/landing/waitlist/waitlist-form.tsx b/src/components/landing/waitlist/waitlist-form.tsx
index 786c08e1..b604cb4b 100644
--- a/src/components/landing/waitlist/waitlist-form.tsx
+++ b/src/components/landing/waitlist/waitlist-form.tsx
@@ -54,7 +54,7 @@ export default function WaitlistForm() {
return (
<div className="w-full md:w-[350px]">
<Form {...form}>
- <form onSubmit={form.handleSubmit(onSubmit)} className="flex flex-col gap-4">
+ <form onSubmit={form.handleSubmit(onSubmit)} className="flex flex-col">
<FormField
control={form.control}
name="name"
@@ -63,9 +63,9 @@ export default function WaitlistForm() {
<FormControl>
<Input
className={clsx({
- 'rounded-xl border border-red-600 bg-white/50 backdrop-blur-md dark:border-red-400 dark:bg-neutral-950/50':
+ 'rounded-b-none rounded-t-xl border border-b-0 border-red-600 bg-white/50 backdrop-blur-md dark:border-red-400 dark:bg-neutral-950/50':
form.formState.errors.name,
- 'rounded-xl border-black/30 bg-white/20 backdrop-blur-md dark:border-white/30 dark:bg-neutral-950/20':
+ 'rounded-b-none rounded-t-xl border-b-0 border-black/30 bg-white/20 backdrop-blur-md dark:border-white/30 dark:bg-neutral-950/20':
!form.formState.errors.name,
})}
{...field}
@@ -86,9 +86,9 @@ export default function WaitlistForm() {
<FormControl>
<Input
className={clsx({
- 'rounded-xl border border-red-600 bg-white/50 backdrop-blur-md dark:border-red-400 dark:bg-neutral-950/50':
+ 'rounded-none border border-red-600 bg-white/50 backdrop-blur-md dark:border-red-400 dark:bg-neutral-950/50':
form.formState.errors.email,
- 'rounded-xl border-black/30 bg-white/20 backdrop-blur-md dark:border-white/30 dark:bg-neutral-950/20':
+ 'rounded-none border-black/30 bg-white/20 backdrop-blur-md dark:border-white/30 dark:bg-neutral-950/20':
!form.formState.errors.email,
})}
{...field}
@@ -110,9 +110,9 @@ export default function WaitlistForm() {
<FormControl>
<SelectTrigger
className={clsx({
- 'rounded-xl border border-red-600 bg-white/50 backdrop-blur-md dark:border-red-400 dark:bg-neutral-950/50':
+ 'rounded-b-xl rounded-t-none border border-t-0 border-red-600 bg-white/50 backdrop-blur-md dark:border-red-400 dark:bg-neutral-950/50':
form.formState.errors.intention,
- 'rounded-xl border-black/30 bg-white/20 backdrop-blur-md dark:border-white/30 dark:bg-neutral-950/20':
+ 'rounded-b-xl rounded-t-none border-t-0 border-black/30 bg-white/20 backdrop-blur-md dark:border-white/30 dark:bg-neutral-950/20':
!form.formState.errors.intention,
})}
>
@@ -120,16 +120,16 @@ export default function WaitlistForm() {
</SelectTrigger>
</FormControl>
<SelectContent className="rounded-xl bg-white/50 backdrop-blur-md dark:bg-black/50">
- <SelectItem className="cursor-pointer rounded-lg brightness-200" value="user">
+ <SelectItem className="cursor-pointer rounded-lg brightness-150" value="user">
I want to solve type challenges
</SelectItem>
<SelectItem
- className="cursor-pointer rounded-lg brightness-200"
+ className="cursor-pointer rounded-lg brightness-150"
value="builder"
>
I want to build type challenges
</SelectItem>
- <SelectItem className="cursor-pointer rounded-lg brightness-200" value="both">
+ <SelectItem className="cursor-pointer rounded-lg brightness-150" value="both">
Both
</SelectItem>
</SelectContent>
@@ -141,7 +141,7 @@ export default function WaitlistForm() {
<Button
type="submit"
disabled={isSubmitting}
- className="wl-form-button group relative w-full overflow-hidden rounded-xl px-[2px] py-[2px] font-bold transition-shadow duration-300 hover:shadow-[0_0.5rem_2rem_-0.75rem_#3178c6] dark:hover:shadow-[0_0.5rem_2rem_-0.75rem_#5198f6]"
+ className="wl-form-button group relative mt-6 w-full overflow-hidden rounded-xl px-[2px] py-[2px] font-bold transition-shadow duration-300 hover:shadow-[0_0.5rem_2rem_-0.75rem_#3178c6] dark:hover:shadow-[0_0.5rem_2rem_-0.75rem_#5198f6]"
>
<span className="h-full w-full rounded-[10px] bg-white px-4 py-2 text-center font-bold text-black transition-colors duration-300 group-hover:bg-blue-100 dark:bg-black dark:text-white group-hover:dark:bg-cyan-950">
{isSubmitting ? 'Submitting...' : 'Join the waitlist'}