perf: modularize comps folder

This commit is contained in:
Mahen 2026-02-06 13:12:16 +07:00
parent 441d6f69e3
commit 4476f4d664
26 changed files with 88 additions and 91 deletions

View File

@ -1,19 +1,18 @@
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button"; import { Button } from "../../../components/ui/button";
import { import {
Card, Card,
CardContent, CardContent,
CardDescription,
CardHeader, CardHeader,
CardTitle, CardTitle,
} from "@/components/ui/card"; } from "../../../components/ui/card";
import { import {
Field, Field,
FieldDescription, FieldDescription,
FieldGroup, FieldGroup,
FieldLabel, FieldLabel,
} from "@/components/ui/field"; } from "../../../components/ui/field";
import { Input } from "@/components/ui/input"; import { Input } from "../../../components/ui/input";
export function LoginPage({ export function LoginPage({
className, className,

View File

@ -7,7 +7,7 @@ import {
trendData, trendData,
wordCloudData, wordCloudData,
} from "./lib/data"; } from "./lib/data";
import { Header } from "@/components/dashboards/Header"; import { Header } from "../../components/dashboards/Header";
import { import {
MessageSquareText, MessageSquareText,
Minus, Minus,
@ -15,17 +15,17 @@ import {
ThumbsUp, ThumbsUp,
TrendingUp, TrendingUp,
} from "lucide-react"; } from "lucide-react";
import { StatCard } from "@/components/dashboards/StatCard"; import { StatCard } from "../../components/dashboards/StatCard";
import { TrendChart } from "@/components/dashboards/TrendChart"; import { TrendChart } from "../../components/dashboards/TrendChart";
import { SentimentChart } from "@/components/dashboards/SentimentChart"; import { SentimentChart } from "../../components/dashboards/SentimentChart";
import { WordCloud } from "@/components/dashboards/WordCloud"; import { WordCloud } from "../../components/dashboards/WordCloud";
import { ModelInfo } from "@/components/dashboards/ModelInfo"; import { ModelInfo } from "../../components/dashboards/ModelInfo";
import { SentimentAnalyzer } from "@/components/dashboards/SentimentAnalyzer"; import { SentimentAnalyzer } from "../../components/dashboards/SentimentAnalyzer";
import { BrandFilter } from "@/components/dashboards/BrandFilter"; import { BrandFilter } from "../../components/dashboards/BrandFilter";
import { ReviewTable } from "@/components/dashboards/ReviewTable"; import { ReviewTable } from "../../components/dashboards/ReviewTable";
import { getClassificationReport } from "./lib/actions"; import { getClassificationReport } from "./lib/actions";
import { ModelDB } from "@/src/types"; import { ModelDB } from "@/src/types";
import { ModelInfoSkeleton } from "@/components/skeletons/ModelInfoSkeleton"; import { ModelInfoSkeleton } from "../../components/skeletons/ModelInfoSkeleton";
export default function DashboardPage() { export default function DashboardPage() {
const [selectedBrand, setSelectedBrand] = useState<string | null>(null); const [selectedBrand, setSelectedBrand] = useState<string | null>(null);

View File

@ -3,11 +3,10 @@ import {
Database, Database,
Laptop, Laptop,
LogOut, LogOut,
RefreshCw,
User, User,
UserCircle, UserCircle,
} from "lucide-react"; } from "lucide-react";
import { Button } from "@/components/ui/button"; import { Button } from "../../components/ui/button";
import { useState } from "react"; import { useState } from "react";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { import {

View File

@ -1,14 +1,13 @@
"use client"; "use client";
import { useState } from "react"; import { Badge } from "../../components/ui/badge";
import { Badge } from "@/components/ui/badge";
import { import {
Select, Select,
SelectContent, SelectContent,
SelectItem, SelectItem,
SelectTrigger, SelectTrigger,
SelectValue, SelectValue,
} from "@/components/ui/select"; } from "../../components/ui/select";
import { ModelDB } from "@/src/types"; import { ModelDB } from "@/src/types";
import { useModelInfo } from "@/src/hooks/useModelInfo"; import { useModelInfo } from "@/src/hooks/useModelInfo";

View File

@ -5,8 +5,8 @@ import {
TableHead, TableHead,
TableHeader, TableHeader,
TableRow, TableRow,
} from "@/components/ui/table"; } from "../../components/ui/table";
import { Badge } from "@/components/ui/badge"; import { Badge } from "../../components/ui/badge";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { Star } from "lucide-react"; import { Star } from "lucide-react";
@ -59,7 +59,7 @@ export function ReviewTable({ reviews }: ReviewTableProps) {
"h-4 w-4", "h-4 w-4",
i < rating i < rating
? "fill-sentiment-neutral text-sentiment-neutral" ? "fill-sentiment-neutral text-sentiment-neutral"
: "fill-muted text-muted" : "fill-muted text-muted",
)} )}
/> />
))} ))}

View File

@ -1,7 +1,7 @@
import { useMemo, useState } from "react"; import { useMemo, useState } from "react";
import { Button } from "@/components/ui/button"; import { Button } from "../../components/ui/button";
import { Textarea } from "@/components/ui/textarea"; import { Textarea } from "../../components/ui/textarea";
import { Badge } from "@/components/ui/badge"; import { Badge } from "../../components/ui/badge";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { import {
Loader2, Loader2,

View File

@ -1,4 +1,4 @@
import { ArrowDown, ChevronDown } from "lucide-react"; import { ChevronDown } from "lucide-react";
export function ModelInfoSkeleton() { export function ModelInfoSkeleton() {
return ( return (

View File

@ -5,13 +5,13 @@ import { Combobox as ComboboxPrimitive } from "@base-ui/react";
import { CheckIcon, ChevronDownIcon, XIcon } from "lucide-react"; import { CheckIcon, ChevronDownIcon, XIcon } from "lucide-react";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button"; import { Button } from "../../components/ui/button";
import { import {
InputGroup, InputGroup,
InputGroupAddon, InputGroupAddon,
InputGroupButton, InputGroupButton,
InputGroupInput, InputGroupInput,
} from "@/components/ui/input-group"; } from "../../components/ui/input-group";
const Combobox = ComboboxPrimitive.Root; const Combobox = ComboboxPrimitive.Root;

View File

@ -1,11 +1,11 @@
"use client" "use client";
import { useMemo } from "react" import { useMemo } from "react";
import { cva, type VariantProps } from "class-variance-authority" import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils" import { cn } from "@/lib/utils";
import { Label } from "@/components/ui/label" import { Label } from "../../components/ui/label";
import { Separator } from "@/components/ui/separator" import { Separator } from "../../components/ui/separator";
function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) { function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
return ( return (
@ -14,11 +14,11 @@ function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
className={cn( className={cn(
"flex flex-col gap-6", "flex flex-col gap-6",
"has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3", "has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
className className,
)} )}
{...props} {...props}
/> />
) );
} }
function FieldLegend({ function FieldLegend({
@ -34,11 +34,11 @@ function FieldLegend({
"mb-3 font-medium", "mb-3 font-medium",
"data-[variant=legend]:text-base", "data-[variant=legend]:text-base",
"data-[variant=label]:text-sm", "data-[variant=label]:text-sm",
className className,
)} )}
{...props} {...props}
/> />
) );
} }
function FieldGroup({ className, ...props }: React.ComponentProps<"div">) { function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
@ -47,11 +47,11 @@ function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
data-slot="field-group" data-slot="field-group"
className={cn( className={cn(
"group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4", "group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4",
className className,
)} )}
{...props} {...props}
/> />
) );
} }
const fieldVariants = cva( const fieldVariants = cva(
@ -75,8 +75,8 @@ const fieldVariants = cva(
defaultVariants: { defaultVariants: {
orientation: "vertical", orientation: "vertical",
}, },
} },
) );
function Field({ function Field({
className, className,
@ -91,7 +91,7 @@ function Field({
className={cn(fieldVariants({ orientation }), className)} className={cn(fieldVariants({ orientation }), className)}
{...props} {...props}
/> />
) );
} }
function FieldContent({ className, ...props }: React.ComponentProps<"div">) { function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
@ -100,11 +100,11 @@ function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
data-slot="field-content" data-slot="field-content"
className={cn( className={cn(
"group/field-content flex flex-1 flex-col gap-1.5 leading-snug", "group/field-content flex flex-1 flex-col gap-1.5 leading-snug",
className className,
)} )}
{...props} {...props}
/> />
) );
} }
function FieldLabel({ function FieldLabel({
@ -118,11 +118,11 @@ function FieldLabel({
"group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50", "group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50",
"has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4", "has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4",
"has-data-[state=checked]:bg-primary/5 has-data-[state=checked]:border-primary dark:has-data-[state=checked]:bg-primary/10", "has-data-[state=checked]:bg-primary/5 has-data-[state=checked]:border-primary dark:has-data-[state=checked]:bg-primary/10",
className className,
)} )}
{...props} {...props}
/> />
) );
} }
function FieldTitle({ className, ...props }: React.ComponentProps<"div">) { function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
@ -131,11 +131,11 @@ function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
data-slot="field-label" data-slot="field-label"
className={cn( className={cn(
"flex w-fit items-center gap-2 text-sm leading-snug font-medium group-data-[disabled=true]/field:opacity-50", "flex w-fit items-center gap-2 text-sm leading-snug font-medium group-data-[disabled=true]/field:opacity-50",
className className,
)} )}
{...props} {...props}
/> />
) );
} }
function FieldDescription({ className, ...props }: React.ComponentProps<"p">) { function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
@ -146,11 +146,11 @@ function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
"text-muted-foreground text-sm leading-normal font-normal group-has-[[data-orientation=horizontal]]/field:text-balance", "text-muted-foreground text-sm leading-normal font-normal group-has-[[data-orientation=horizontal]]/field:text-balance",
"last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5", "last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5",
"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4", "[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
className className,
)} )}
{...props} {...props}
/> />
) );
} }
function FieldSeparator({ function FieldSeparator({
@ -158,7 +158,7 @@ function FieldSeparator({
className, className,
...props ...props
}: React.ComponentProps<"div"> & { }: React.ComponentProps<"div"> & {
children?: React.ReactNode children?: React.ReactNode;
}) { }) {
return ( return (
<div <div
@ -166,7 +166,7 @@ function FieldSeparator({
data-content={!!children} data-content={!!children}
className={cn( className={cn(
"relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2", "relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2",
className className,
)} )}
{...props} {...props}
> >
@ -180,7 +180,7 @@ function FieldSeparator({
</span> </span>
)} )}
</div> </div>
) );
} }
function FieldError({ function FieldError({
@ -189,37 +189,37 @@ function FieldError({
errors, errors,
...props ...props
}: React.ComponentProps<"div"> & { }: React.ComponentProps<"div"> & {
errors?: Array<{ message?: string } | undefined> errors?: Array<{ message?: string } | undefined>;
}) { }) {
const content = useMemo(() => { const content = useMemo(() => {
if (children) { if (children) {
return children return children;
} }
if (!errors?.length) { if (!errors?.length) {
return null return null;
} }
const uniqueErrors = [ const uniqueErrors = [
...new Map(errors.map((error) => [error?.message, error])).values(), ...new Map(errors.map((error) => [error?.message, error])).values(),
] ];
if (uniqueErrors?.length == 1) { if (uniqueErrors?.length == 1) {
return uniqueErrors[0]?.message return uniqueErrors[0]?.message;
} }
return ( return (
<ul className="ml-4 flex list-disc flex-col gap-1"> <ul className="ml-4 flex list-disc flex-col gap-1">
{uniqueErrors.map( {uniqueErrors.map(
(error, index) => (error, index) =>
error?.message && <li key={index}>{error.message}</li> error?.message && <li key={index}>{error.message}</li>,
)} )}
</ul> </ul>
) );
}, [children, errors]) }, [children, errors]);
if (!content) { if (!content) {
return null return null;
} }
return ( return (
@ -231,7 +231,7 @@ function FieldError({
> >
{content} {content}
</div> </div>
) );
} }
export { export {
@ -245,4 +245,4 @@ export {
FieldSet, FieldSet,
FieldContent, FieldContent,
FieldTitle, FieldTitle,
} };

View File

@ -1,12 +1,12 @@
"use client" "use client";
import * as React from "react" import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority" import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils" import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button" import { Button } from "../../components/ui/button";
import { Input } from "@/components/ui/input" import { Input } from "../../components/ui/input";
import { Textarea } from "@/components/ui/textarea" import { Textarea } from "../../components/ui/textarea";
function InputGroup({ className, ...props }: React.ComponentProps<"div">) { function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
return ( return (
@ -29,11 +29,11 @@ function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
// Error state. // Error state.
"has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40", "has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",
className className,
)} )}
{...props} {...props}
/> />
) );
} }
const inputGroupAddonVariants = cva( const inputGroupAddonVariants = cva(
@ -54,8 +54,8 @@ const inputGroupAddonVariants = cva(
defaultVariants: { defaultVariants: {
align: "inline-start", align: "inline-start",
}, },
} },
) );
function InputGroupAddon({ function InputGroupAddon({
className, className,
@ -70,13 +70,13 @@ function InputGroupAddon({
className={cn(inputGroupAddonVariants({ align }), className)} className={cn(inputGroupAddonVariants({ align }), className)}
onClick={(e) => { onClick={(e) => {
if ((e.target as HTMLElement).closest("button")) { if ((e.target as HTMLElement).closest("button")) {
return return;
} }
e.currentTarget.parentElement?.querySelector("input")?.focus() e.currentTarget.parentElement?.querySelector("input")?.focus();
}} }}
{...props} {...props}
/> />
) );
} }
const inputGroupButtonVariants = cva( const inputGroupButtonVariants = cva(
@ -94,8 +94,8 @@ const inputGroupButtonVariants = cva(
defaultVariants: { defaultVariants: {
size: "xs", size: "xs",
}, },
} },
) );
function InputGroupButton({ function InputGroupButton({
className, className,
@ -113,7 +113,7 @@ function InputGroupButton({
className={cn(inputGroupButtonVariants({ size }), className)} className={cn(inputGroupButtonVariants({ size }), className)}
{...props} {...props}
/> />
) );
} }
function InputGroupText({ className, ...props }: React.ComponentProps<"span">) { function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
@ -121,11 +121,11 @@ function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
<span <span
className={cn( className={cn(
"text-muted-foreground flex items-center gap-2 text-sm [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4", "text-muted-foreground flex items-center gap-2 text-sm [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
className className,
)} )}
{...props} {...props}
/> />
) );
} }
function InputGroupInput({ function InputGroupInput({
@ -137,11 +137,11 @@ function InputGroupInput({
data-slot="input-group-control" data-slot="input-group-control"
className={cn( className={cn(
"flex-1 rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0 dark:bg-transparent", "flex-1 rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0 dark:bg-transparent",
className className,
)} )}
{...props} {...props}
/> />
) );
} }
function InputGroupTextarea({ function InputGroupTextarea({
@ -153,11 +153,11 @@ function InputGroupTextarea({
data-slot="input-group-control" data-slot="input-group-control"
className={cn( className={cn(
"flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent", "flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent",
className className,
)} )}
{...props} {...props}
/> />
) );
} }
export { export {
@ -167,4 +167,4 @@ export {
InputGroupText, InputGroupText,
InputGroupInput, InputGroupInput,
InputGroupTextarea, InputGroupTextarea,
} };

View File

@ -3,7 +3,7 @@ import { cva, type VariantProps } from "class-variance-authority"
import { Slot } from "radix-ui" import { Slot } from "radix-ui"
import { cn } from "@/lib/utils" import { cn } from "@/lib/utils"
import { Separator } from "@/components/ui/separator" import { Separator } from "../../components/ui/separator"
function ItemGroup({ className, ...props }: React.ComponentProps<"div">) { function ItemGroup({ className, ...props }: React.ComponentProps<"div">) {
return ( return (