Connect, collaborate, and grow with a community of TypeScript developers
init (#1191)
bautistaaa6285f38d0a4b
diff --git a/apps/web/src/app/[locale]/aot-2023/_components/card-grid.tsx b/apps/web/src/app/[locale]/aot-2023/_components/card-grid.tsxindex 36d42248..a1463485 100644--- a/apps/web/src/app/[locale]/aot-2023/_components/card-grid.tsx+++ b/apps/web/src/app/[locale]/aot-2023/_components/card-grid.tsx@@ -4,7 +4,7 @@ import { auth, type Session } from '@repo/auth/server';export async function CardGrid() {const session = await auth();- const challenges = await getChallenges(session);+ const challenges = await getTrackChallenges(session);const challengesToReveal = revealItems(challenges);return (@@ -18,33 +18,49 @@ export async function CardGrid() {);}-export type Challenges = NonNullable<Awaited<ReturnType<typeof getChallenges>>>;-async function getChallenges(session: Session | null) {- const challenges = await prisma.challenge.findMany({- take: 25,+export type Challenges = NonNullable<Awaited<ReturnType<typeof getTrackChallenges>>>;+async function getTrackChallenges(session: Session | null) {+ const track = await prisma.track.findFirstOrThrow({+ where: {+ slug: 'advent-of-typescript-2023',+ },include: {- submission: {- where: {- userId: session?.user.id ?? '',- isSuccessful: true,+ trackChallenges: {+ include: {+ challenge: {+ include: {+ submission: {+ where: {+ userId: session?.user.id || '',+ isSuccessful: true,+ },+ select: {+ isSuccessful: true,+ },+ take: 1,+ },+ },+ },},- select: {- isSuccessful: true,+ orderBy: {+ orderId: 'asc',},- take: 1,},},});- return challenges.map((challenge) => ({- ...challenge,- hasSolved: challenge.submission.length > 0,- }));+ return track?.trackChallenges.map((trackChallenge) => {+ const { submission, ...challenge } = trackChallenge.challenge;+ return {+ ...challenge,+ hasSolved: trackChallenge.challenge.submission.length > 0,+ };+ });}const MS_PER_DAY = 24 * 60 * 60 * 1000;function revealItems(items: Challenges) {- const startDate: Date = new Date('2023-11-17');+ const startDate: Date = new Date('2023-12-01');const today: Date = new Date();const daysPassed = Math.floor((today.getTime() - startDate.getTime()) / MS_PER_DAY);diff --git a/apps/web/src/app/[locale]/challenge/[slug]/aot-slugs.ts b/apps/web/src/app/[locale]/challenge/[slug]/aot-slugs.tsnew file mode 100644index 00000000..1e260927--- /dev/null+++ b/apps/web/src/app/[locale]/challenge/[slug]/aot-slugs.ts@@ -0,0 +1,27 @@+export const AOT_CHALLENGES = [+ 'day-1',+ 'day-2',+ 'day-3',+ 'day-4',+ 'day-5',+ 'day-6',+ 'day-7',+ 'day-8',+ 'day-9',+ 'day-10',+ 'day-11',+ 'day-12',+ 'day-13',+ 'day-14',+ 'day-15',+ 'day-16',+ 'day-17',+ 'day-18',+ 'day-19',+ 'day-20',+ 'day-21',+ 'day-22',+ 'day-23',+ 'day-24',+ 'day-25',+];diff --git a/apps/web/src/app/[locale]/challenge/[slug]/left-wrapper.tsx b/apps/web/src/app/[locale]/challenge/[slug]/left-wrapper.tsxindex f346cd46..d84a5630 100644--- a/apps/web/src/app/[locale]/challenge/[slug]/left-wrapper.tsx+++ b/apps/web/src/app/[locale]/challenge/[slug]/left-wrapper.tsx@@ -12,6 +12,7 @@ import { FlaskConical, History, Text } from '@repo/ui/icons';import type { ChallengeRouteData } from './getChallengeRouteData';import { useTrackNavigationVisiblity } from './use-track-visibility.hook';+import { AOT_CHALLENGES } from './aot-slugs';type Tab = 'description' | 'solutions' | 'submissions';interface Props {@@ -29,6 +30,7 @@ export function LeftWrapper({ children, challenge, track, expandPanel, isDesktopconst featureFlags = useContext(FeatureFlagContext);+ const isAotChallenge = useMemo(() => AOT_CHALLENGES.includes(challenge.slug), [challenge.slug]);const isCollapsedRef = useRef(isCollapsed);const isDesktopRef = useRef(isDesktop);isDesktopRef.current = isDesktop;@@ -96,7 +98,10 @@ export function LeftWrapper({ children, challenge, track, expandPanel, isDesktopconst isTrackFeatureEnabled = featureFlags?.enableInChallengeTrack;const hasEnrolledTrackForChallenge = track !== null;const isTrackVisible =- isTrackFeatureEnabled && hasEnrolledTrackForChallenge && (!isCollapsed || isDesktop);+ isTrackFeatureEnabled &&+ hasEnrolledTrackForChallenge &&+ (!isCollapsed || isDesktop) &&+ !isAotChallenge;const isIconOnly = isCollapsed && isDesktop;const { setIsTrackTitleVisible } = useTrackNavigationVisiblity();@@ -127,6 +132,8 @@ export function LeftWrapper({ children, challenge, track, expandPanel, isDesktop'grid-rows-3 gap-2': isIconOnly,'grid-cols-3 gap-0.5': !isIconOnly,'rounded-tl-xl': !isTrackVisible,+ 'grid-cols-2 gap-0.5': isAotChallenge && !isIconOnly,+ 'grid-rows-2 gap-2': isAotChallenge && isIconOnly,},)}ref={tabsListRef}@@ -148,19 +155,21 @@ export function LeftWrapper({ children, challenge, track, expandPanel, isDesktop>{isIconOnly ? <Text className="h-4 w-4" /> : 'Description'}</TabsTrigger>- <TabsTrigger- className={cn(- 'rounded-md duration-300 hover:bg-neutral-200/50 data-[state=active]:bg-neutral-200 dark:hover:bg-neutral-700/50 dark:data-[state=active]:bg-neutral-700',- { 'p-4': isIconOnly },- )}- onClick={() => {- router.push(`/challenge/${challenge.slug}/solutions`);- isCollapsed && expandPanel();- }}- value="solutions"- >- {isIconOnly ? <FlaskConical className="h-4 w-4" /> : 'Solutions'}- </TabsTrigger>+ {!isAotChallenge ? (+ <TabsTrigger+ className={cn(+ 'rounded-md duration-300 hover:bg-neutral-200/50 data-[state=active]:bg-neutral-200 dark:hover:bg-neutral-700/50 dark:data-[state=active]:bg-neutral-700',+ { 'p-4': isIconOnly },+ )}+ onClick={() => {+ router.push(`/challenge/${challenge.slug}/solutions`);+ isCollapsed && expandPanel();+ }}+ value="solutions"+ >+ {isIconOnly ? <FlaskConical className="h-4 w-4" /> : 'Solutions'}+ </TabsTrigger>+ ) : null}<TabsTriggerclassName={cn('rounded-md rounded-tr-lg duration-300 hover:bg-neutral-200/50 data-[state=active]:bg-neutral-200 dark:hover:bg-neutral-700/50 dark:data-[state=active]:bg-neutral-700',diff --git a/apps/web/src/app/[locale]/challenge/[slug]/page.tsx b/apps/web/src/app/[locale]/challenge/[slug]/page.tsxindex 4fbff708..60373714 100644--- a/apps/web/src/app/[locale]/challenge/[slug]/page.tsx+++ b/apps/web/src/app/[locale]/challenge/[slug]/page.tsx@@ -1,11 +1,13 @@import { auth, type Session } from '@repo/auth/server';-import { redirect } from 'next/navigation';+import { notFound, redirect } from 'next/navigation';import { buildMetaForChallenge } from '~/app/metadata';import { getRelativeTime } from '~/utils/relativeTime';import { isBetaUser } from '~/utils/server/is-beta-user';import { Comments } from '../_components/comments';import { Description } from '../_components/description';import { getChallengeRouteData } from './getChallengeRouteData';+import { getAllFlags } from '~/utils/feature-flags';+import { AOT_CHALLENGES } from './aot-slugs';interface Props {params: {@@ -35,12 +37,24 @@ export default async function Challenges({ params: { slug } }: Props) {return redirect('/claim');}+ const { enableHolidayEvent } = await getAllFlags();+ const isAotChallenge = AOT_CHALLENGES.includes(slug);++ if (enableHolidayEvent && isAotChallenge) {+ const [, day = '1'] = slug.split('-');+ const daysPassed = daysAfterDecemberFirst();++ if (parseInt(day) > daysPassed) {+ return notFound();+ }+ }+const { challenge } = await getChallengeRouteData(slug, session);return (<div className="relative h-full "><Description challenge={challenge} />- <Comments rootId={challenge.id} type="CHALLENGE" />+ {!isAotChallenge ? <Comments rootId={challenge.id} type="CHALLENGE" /> : null}</div>);}@@ -48,3 +62,13 @@ export default async function Challenges({ params: { slug } }: Props) {export function isAuthor(session: Session | null, userId?: string | null) {return userId && session?.user?.id && userId === session?.user?.id;}++const MS_PER_DAY = 24 * 60 * 60 * 1000;+function daysAfterDecemberFirst() {+ const startDate: Date = new Date('2023-12-01');+ const today: Date = new Date();++ const daysPassed = Math.floor((today.getTime() - startDate.getTime()) / MS_PER_DAY) + 1;++ return daysPassed;+}diff --git a/apps/web/src/app/[locale]/challenge/[slug]/solutions/page.tsx b/apps/web/src/app/[locale]/challenge/[slug]/solutions/page.tsxindex b003d585..c672e459 100644--- a/apps/web/src/app/[locale]/challenge/[slug]/solutions/page.tsx+++ b/apps/web/src/app/[locale]/challenge/[slug]/solutions/page.tsx@@ -1,6 +1,8 @@import { buildMetaForDefault } from '~/app/metadata';import { getChallengeRouteData } from '../getChallengeRouteData';import { Solutions } from './_components';+import { AOT_CHALLENGES } from '../aot-slugs';+import { notFound } from 'next/navigation';interface Props {params: {@@ -17,5 +19,6 @@ export async function generateMetadata({ params: { slug } }: Props) {}export default async function SolutionPage({ params: { slug } }: Props) {+ if (AOT_CHALLENGES.includes(slug)) return notFound();return <Solutions slug={slug} />;}diff --git a/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/_components/overview.tsx b/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/_components/overview.tsxindex d576275e..30c6c709 100644--- a/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/_components/overview.tsx+++ b/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/_components/overview.tsx@@ -2,13 +2,14 @@ import { Button } from '@repo/ui/components/button';import { Markdown } from '@repo/ui/components/markdown';import { Tooltip, TooltipContent, TooltipTrigger } from '@repo/ui/components/tooltip';import { toast } from '@repo/ui/components/use-toast';-import { CheckCircle2, Copy, Plus, X, XCircle } from '@repo/ui/icons';+import { CheckCircle2, Copy, Plus, Twitter, X, XCircle } from '@repo/ui/icons';import { useQuery } from '@tanstack/react-query';import Link from 'next/link';import { useParams, useSearchParams } from 'next/navigation';import { getRelativeTime } from '~/utils/relativeTime';import { getChallengeSubmissionById } from '../getChallengeSubmissions';import { Suggestions } from './suggestions';+import { AOT_CHALLENGES } from '../../../aot-slugs';interface Props {submissionId: string;@@ -22,6 +23,8 @@ export function SubmissionOverview({ submissionId }: Props) {const { slug } = useParams();const searchParams = useSearchParams();+ const isAotChallenge = AOT_CHALLENGES.includes(slug as string);+const showSuggestions = searchParams.get('success') === 'true';const { data: submission } = useQuery({queryKey: [`submission`, submissionId],@@ -82,16 +85,18 @@ export function SubmissionOverview({ submissionId }: Props) {Submitted {getRelativeTime(submission.createdAt)}</div></div>- <div>- <Link- className="bg-primary flex h-8 items-center gap-1 rounded-lg px-3 py-2 text-sm"- href={`/challenge/${slug}/solutions`}- >- <Plus size={16} /> Solution- </Link>- </div>+ {!isAotChallenge && (+ <div>+ <Link+ className="bg-primary flex h-8 items-center gap-1 rounded-lg px-3 py-2 text-sm"+ href={`/challenge/${slug}/solutions`}+ >+ <Plus size={16} /> Solution+ </Link>+ </div>+ )}</div>- {showSuggestions ? (+ {showSuggestions && !isAotChallenge ? (<div className="flex w-full items-start"><Suggestions track={track} challengeId={submission.challengeId} /></div>@@ -99,6 +104,34 @@ export function SubmissionOverview({ submissionId }: Props) {<div className="mb-3 px-3"><Markdown>{code}</Markdown></div>+ {isAotChallenge ? (+ <div className="mb-3 flex gap-2 px-3">+ <Button+ asChild+ className="flex items-center gap-2 rounded-xl border-2 px-4 py-2 dark:text-white"+ variant="outline"+ >+ <a+ target="_blank"+ rel="noreferrer"+ className="gap-1 md:inline-flex"+ href={`https://twitter.com/intent/tweet?text=${encodeURIComponent(+ `I've completed ${submission.challenge.name} - Advent of TypeScript 2023`,+ )}&url=https://typehero.dev/challenge/${slug}&hashtags=AdventOfTypescript`}+ >+ <Twitter className="h-4 w-4" />+ Share on Twitter+ </a>+ </Button>+ <Button+ asChild+ variant="outline"+ className="fancy-border-gradient relative border-none"+ >+ <Link href="/aot-2023">Back to Advent of TypeScript</Link>+ </Button>+ </div>+ ) : null}</div></>);diff --git a/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/getChallengeSubmissions.ts b/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/getChallengeSubmissions.tsindex 90c55c10..a3add10f 100644--- a/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/getChallengeSubmissions.ts+++ b/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/getChallengeSubmissions.ts@@ -8,5 +8,12 @@ export const getChallengeSubmissionById = cache((id: string) => {where: {id: Number(id),},+ include: {+ challenge: {+ select: {+ name: true,+ },+ },+ },});});diff --git a/apps/web/src/app/[locale]/challenge/_components/description/index.tsx b/apps/web/src/app/[locale]/challenge/_components/description/index.tsxindex 90a7cd33..90555b95 100644--- a/apps/web/src/app/[locale]/challenge/_components/description/index.tsx+++ b/apps/web/src/app/[locale]/challenge/_components/description/index.tsx@@ -1,32 +1,33 @@'use client';import { useSession } from '@repo/auth/react';+import { cn } from '@repo/ui/cn';+import { ActionMenu } from '@repo/ui/components/action-menu';+import { Button, buttonVariants } from '@repo/ui/components/button';+import {+ Dialog,+ DialogContent,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+} from '@repo/ui/components/dialog';+import { DifficultyBadge } from '@repo/ui/components/difficulty-badge';+import { Markdown } from '@repo/ui/components/markdown';+import { Tooltip, TooltipContent, TooltipTrigger } from '@repo/ui/components/tooltip';+import { TypographyH3 } from '@repo/ui/components/typography/h3';+import { UserBadge } from '@repo/ui/components/user-badge';import { Bookmark as BookmarkIcon, Calendar, CheckCircle, Flag, Share } from '@repo/ui/icons';import clsx from 'clsx';import { debounce } from 'lodash';import Link from 'next/link';-import { useRef, useState } from 'react';+import { useMemo, useRef, useState } from 'react';import { type ChallengeRouteData } from '~/app/[locale]/challenge/[slug]/getChallengeRouteData';import { ReportDialog } from '~/components/ReportDialog';import { getRelativeTime } from '~/utils/relativeTime';import { addOrRemoveBookmark } from '../bookmark.action';import { ShareForm } from '../share-form';import { Vote } from '../vote';-import { ActionMenu } from '@repo/ui/components/action-menu';-import { TypographyH3 } from '@repo/ui/components/typography/h3';-import { UserBadge } from '@repo/ui/components/user-badge';-import { DifficultyBadge } from '@repo/ui/components/difficulty-badge';-import {- Dialog,- DialogContent,- DialogHeader,- DialogTitle,- DialogTrigger,-} from '@repo/ui/components/dialog';-import { Tooltip, TooltipContent, TooltipTrigger } from '@repo/ui/components/tooltip';-import { Markdown } from '@repo/ui/components/markdown';-import { Button, buttonVariants } from '@repo/ui/components/button';-import { cn } from '@repo/ui/cn';+import { AOT_CHALLENGES } from '../../[slug]/aot-slugs';interface Props {challenge: ChallengeRouteData['challenge'];@@ -43,6 +44,8 @@ export function Description({ challenge }: Props) {const [hasBookmarked, setHasBookmarked] = useState(challenge.bookmark.length > 0);const session = useSession();+ const isAotChallenge = useMemo(() => AOT_CHALLENGES.includes(challenge.slug), [challenge.slug]);+const debouncedBookmark = useRef(debounce(async (challengeId: number, userId: string, shouldBookmark: boolean) => {try {@@ -87,7 +90,7 @@ export function Description({ challenge }: Props) {</div>{/* Difficulty & Action Buttons */}<div className="mt-3 flex items-center gap-3">- <DifficultyBadge difficulty={challenge.difficulty} />+ {!isAotChallenge ? <DifficultyBadge difficulty={challenge.difficulty} /> : null}{challenge.hasSolved ? (<Tooltip><TooltipTrigger asChild>diff --git a/apps/web/src/app/[locale]/claim/page.tsx b/apps/web/src/app/[locale]/claim/page.tsxindex fcc7f7d3..1d0ffd01 100644--- a/apps/web/src/app/[locale]/claim/page.tsx+++ b/apps/web/src/app/[locale]/claim/page.tsx@@ -1,10 +1,10 @@import { auth } from '@repo/auth/server';-import { LoginButton } from '../login/_components/LoginButton';-import { ClaimForm, type FormSchema } from './claim-form';import Image from 'next/image';-import { isBetaUser } from '~/utils/server/is-beta-user';import { redirect } from 'next/navigation';+import { isBetaUser } from '~/utils/server/is-beta-user';+import { LoginButton } from '../login/_components/LoginButton';import { isValidToken } from './_actions';+import { ClaimForm } from './claim-form';interface Props {searchParams?: { token: string };diff --git a/challenges/default-generic-arguments/prompt.md b/challenges/default-generic-arguments/prompt.mdindex eaae5e95..c5a4fb90 100644--- a/challenges/default-generic-arguments/prompt.md+++ b/challenges/default-generic-arguments/prompt.md@@ -57,12 +57,8 @@ Your goal is to create some types that have have the correct default argument.The second type, `TSConfig`, should feel a bit difficult, but if you get stuck, feel free to check out the little hint below:-<details>--<summary>small hint</summary>+### small hint1. Start with a literal object as the parameter default.1. Use [indexed types](https://typehero.dev/challenge/indexed-types).1. The error you'll see is because of a missing [generic constraint](https://typehero.dev/challenge/generic-type-constraints).--</details>