Connect, collaborate, and grow with a community of TypeScript developers
feat(web): reduce bundle size (#616)
Tom Lienardce0ffa2419ec
diff --git a/apps/admin/src/app/_components/challenge-reviews/index.tsx b/apps/admin/src/app/_components/challenge-reviews/index.tsxindex cc8d418e..d6877eb1 100644--- a/apps/admin/src/app/_components/challenge-reviews/index.tsx+++ b/apps/admin/src/app/_components/challenge-reviews/index.tsx@@ -1,6 +1,6 @@'use client';-import { DataTable } from '@repo/ui';+import { DataTable } from '@repo/ui/components/data-table';import { useQuery } from '@tanstack/react-query';import { getPendingChallenges } from './challenge-reviews.action';import { columns } from './columns';diff --git a/apps/admin/src/app/_components/tracks/index.tsx b/apps/admin/src/app/_components/tracks/index.tsxindex 4aad8ceb..bda2aabf 100644--- a/apps/admin/src/app/_components/tracks/index.tsx+++ b/apps/admin/src/app/_components/tracks/index.tsx@@ -1,6 +1,6 @@'use client';-import { DataTable } from '@repo/ui';+import { DataTable } from '@repo/ui/components/data-table';import { useQuery } from '@tanstack/react-query';import { ActionBar } from './action-bar';import { columns } from './columns';diff --git a/apps/web/src/app/[locale]/_components/feature-card.tsx b/apps/web/src/app/[locale]/_components/feature-card.tsxindex 33499a4d..fbda5c19 100644--- a/apps/web/src/app/[locale]/_components/feature-card.tsx+++ b/apps/web/src/app/[locale]/_components/feature-card.tsx@@ -15,7 +15,6 @@ import { useTheme } from 'next-themes';import Image, { type StaticImageData } from 'next/image';import { useEffect, useState, type MouseEvent } from 'react';import { useInView } from 'react-intersection-observer';-import { z } from 'zod';import { Steps } from '~/components/wizard/Steps';import { useIsMobile } from '~/utils/useIsMobile';import { TrackChallenge } from '../tracks/_components/track-challenge-card';@@ -161,6 +160,13 @@ export function ImageCard({);}+const steps = [+ { id: '1', name: 'π³' },+ { id: '2', name: 'π' },+ { id: '3', name: 'π' },+ { id: '4', name: 'π' },+];+export function ChallengeCreationCard({image,step1img1Class,@@ -191,12 +197,7 @@ export function ChallengeCreationCard({}) {const { resolvedTheme } = useTheme();const { currentNumber: step, increment } = useNumberCycler();- const steps = [- { id: '1', name: 'π³', schema: z.any() },- { id: '2', name: 'π', schema: z.any() },- { id: '3', name: 'π', schema: z.any() },- { id: '4', name: 'π', schema: z.any() },- ];+return (<FeatureCard {...props}><divdiff --git a/apps/web/src/components/wizard/index.tsx b/apps/web/src/components/wizard/index.tsxindex 4086c091..7a363b9f 100644--- a/apps/web/src/components/wizard/index.tsx+++ b/apps/web/src/components/wizard/index.tsx@@ -51,13 +51,19 @@ const createTestCasesSchema = z.object({export const createChallengeSchema = createExploreCardSchema.merge(createDescriptionSchema).merge(createTestCasesSchema);-const steps = [++const steps: Step[] = [{ id: '1', name: 'Challenge Card', schema: createExploreCardSchema },{ id: '2', name: 'Description', schema: createDescriptionSchema },{ id: '3', name: 'Test Cases', schema: createTestCasesSchema },- { id: '4', name: 'Summary', schema: z.any() },+ { id: '4', name: 'Summary' },];-export type Step = (typeof steps)[0];++export interface Step {+ id: string;+ name: string;+ schema?: z.ZodSchema;+}export type CreateChallengeSchema = z.infer<typeof createChallengeSchema>;@@ -92,7 +98,9 @@ export function Wizard() {}, []);const handleNextClick = async () => {- const { success } = steps[step]!.schema.safeParse(form.getValues());+ const schema = steps[step]!.schema;+ const success = schema ? schema.safeParse(form.getValues()).success : true;+if (success) {// if they are currently on test cases do not let them go to next step// until a type error existsdiff --git a/packages/ui/package.json b/packages/ui/package.jsonindex ef571d67..54b3776a 100644--- a/packages/ui/package.json+++ b/packages/ui/package.json@@ -5,7 +5,8 @@"exports": {".": "./src/index.ts","./types": "./src/types.ts",- "./icons": "./src/icons.ts"+ "./icons": "./src/icons.ts",+ "./components": "./src/components"},"typesVersions": {"*": {@@ -17,6 +18,9 @@],"icons": ["./src/icons.ts"+ ],+ "components/*": [+ "./src/components/*"]}},@@ -49,7 +53,6 @@"@tanstack/react-table": "^8.9.3","class-variance-authority": "^0.7.0","clsx": "^2.0.0",- "cmdk": "^0.2.0","lucide-react": "^0.260.0","next-themes": "^0.2.1","react": "^18.2.0",diff --git a/packages/ui/src/components/command.tsx b/packages/ui/src/components/command.tsxdeleted file mode 100644index f6b9310c..00000000--- a/packages/ui/src/components/command.tsx+++ /dev/null@@ -1,143 +0,0 @@-'use client';-import * as React from 'react';-import type { DialogProps } from '@radix-ui/react-dialog';-import { Command as CommandPrimitive } from 'cmdk';-import { Search } from 'lucide-react';-import { cn } from '../cn';-import { Dialog, DialogContent } from './dialog';--const Command = React.forwardRef<- React.ElementRef<typeof CommandPrimitive>,- React.ComponentPropsWithoutRef<typeof CommandPrimitive>->(({ className, ...props }, ref) => (- <CommandPrimitive- className={cn(- 'bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md',- className,- )}- ref={ref}- {...props}- />-));-Command.displayName = CommandPrimitive.displayName;--type CommandDialogProps = DialogProps;--function CommandDialog({ children, ...props }: CommandDialogProps) {- return (- <Dialog {...props}>- <DialogContent className="overflow-hidden p-0 shadow-lg">- <Command className="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">- {children}- </Command>- </DialogContent>- </Dialog>- );-}--const CommandInput = React.forwardRef<- React.ElementRef<typeof CommandPrimitive.Input>,- React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>->(({ className, ...props }, ref) => (- <div className="flex items-center border-b px-3" cmdk-input-wrapper="">- <Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />- <CommandPrimitive.Input- className={cn(- 'placeholder:text-muted-foreground flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none disabled:cursor-not-allowed disabled:opacity-50',- className,- )}- ref={ref}- {...props}- />- </div>-));--CommandInput.displayName = CommandPrimitive.Input.displayName;--const CommandList = React.forwardRef<- React.ElementRef<typeof CommandPrimitive.List>,- React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>->(({ className, ...props }, ref) => (- <CommandPrimitive.List- className={cn('max-h-[300px] overflow-y-auto overflow-x-hidden', className)}- ref={ref}- {...props}- />-));--CommandList.displayName = CommandPrimitive.List.displayName;--const CommandEmpty = React.forwardRef<- React.ElementRef<typeof CommandPrimitive.Empty>,- React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>->((props, ref) => (- <CommandPrimitive.Empty className="py-6 text-center text-sm" ref={ref} {...props} />-));--CommandEmpty.displayName = CommandPrimitive.Empty.displayName;--const CommandGroup = React.forwardRef<- React.ElementRef<typeof CommandPrimitive.Group>,- React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>->(({ className, ...props }, ref) => (- <CommandPrimitive.Group- className={cn(- 'text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium',- className,- )}- ref={ref}- {...props}- />-));--CommandGroup.displayName = CommandPrimitive.Group.displayName;--const CommandSeparator = React.forwardRef<- React.ElementRef<typeof CommandPrimitive.Separator>,- React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>->(({ className, ...props }, ref) => (- <CommandPrimitive.Separator- className={cn('bg-border -mx-1 h-px', className)}- ref={ref}- {...props}- />-));-CommandSeparator.displayName = CommandPrimitive.Separator.displayName;--const CommandItem = React.forwardRef<- React.ElementRef<typeof CommandPrimitive.Item>,- React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>->(({ className, ...props }, ref) => (- <CommandPrimitive.Item- className={cn(- 'aria-selected:bg-accent aria-selected:text-accent-foreground relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50',- className,- )}- ref={ref}- {...props}- />-));--CommandItem.displayName = CommandPrimitive.Item.displayName;--function CommandShortcut({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) {- return (- <span- className={cn('text-muted-foreground ml-auto text-xs tracking-widest', className)}- {...props}- />- );-}-CommandShortcut.displayName = 'CommandShortcut';--export {- Command,- CommandDialog,- CommandInput,- CommandList,- CommandEmpty,- CommandGroup,- CommandItem,- CommandShortcut,- CommandSeparator,-};diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.tsindex 491f2adf..e00276a5 100644--- a/packages/ui/src/index.ts+++ b/packages/ui/src/index.ts@@ -4,12 +4,8 @@ export * from './components/alert-dialog';export * from './components/avatar';export * from './components/badge';export * from './components/button';-export * from './components/calendar';export * from './components/card';export * from './components/checkbox';-export * from './components/command';-export * from './components/data-table';-export * from './components/data-table-pagination';export * from './components/dialog';export * from './components/difficulty-badge';export * from './components/dropdown-menu';diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 3f8deb70..22330ffd 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -628,9 +628,6 @@ importers:clsx:specifier: ^2.0.0version: 2.0.0- cmdk:- specifier: ^0.2.0lucide-react:specifier: ^0.260.0version: 0.260.0([email protected])@@ -1562,7 +1559,7 @@ packages:eslint: ^6.0.0 || ^7.0.0 || >=8.0.0dependencies:eslint: 8.48.0- eslint-visitor-keys: 3.4.3+ eslint-visitor-keys: 3.4.1dev: true/@eslint-community/[email protected]: