diff --git a/app/api/r/themes/[id]/route.ts b/app/r/themes/[id]/route.ts similarity index 81% rename from app/api/r/themes/[id]/route.ts rename to app/r/themes/[id]/route.ts index 7783c3e1..a1d2a7a6 100644 --- a/app/api/r/themes/[id]/route.ts +++ b/app/r/themes/[id]/route.ts @@ -4,18 +4,24 @@ import { getTheme } from "@/actions/themes"; import { generateThemeRegistryItemFromStyles } from "@/utils/registry/themes"; import { registryItemSchema } from "shadcn/registry"; -// THIS IMPLEMENTATION WON'T WORK FOR PUBLIC THEMES. -// since the user session is necessary to get the theme from the database -export async function GET(_req: Request, { params }: { params: Promise<{ id: string }> }) { +export async function GET( + _req: Request, + { params }: { params: Promise<{ id: string }> } +) { const { id } = await params; try { const theme = await getTheme(id); - const generatedRegistryItem = generateThemeRegistryItemFromStyles(theme.name, theme.styles); + const generatedRegistryItem = generateThemeRegistryItemFromStyles( + theme.name, + theme.styles + ); // Validate the generated registry item against the official shadcn registry item schema // https://ui.shadcn.com/docs/registry/registry-item-json - const parsedRegistryItem = registryItemSchema.safeParse(generatedRegistryItem); + const parsedRegistryItem = registryItemSchema.safeParse( + generatedRegistryItem + ); if (!parsedRegistryItem.success) { console.error( "Could not parse the registry item from the database:", diff --git a/components/editor/code-panel.tsx b/components/editor/code-panel.tsx index 5b745f92..89ad7b71 100644 --- a/components/editor/code-panel.tsx +++ b/components/editor/code-panel.tsx @@ -1,6 +1,6 @@ -import React, { useState } from "react"; +import { useState } from "react"; import { Button } from "@/components/ui/button"; -import { Copy, Check, AlertTriangle } from "lucide-react"; +import { Copy, Check } from "lucide-react"; import { ThemeEditorState } from "@/types/editor"; import { ScrollArea, ScrollBar } from "../ui/scroll-area"; import { ColorFormat } from "../../types"; @@ -16,7 +16,6 @@ import { useEditorStore } from "@/store/editor-store"; import { usePreferencesStore } from "@/store/preferences-store"; import { generateThemeCode } from "@/utils/theme-style-generator"; import { useThemePresetStore } from "@/store/theme-preset-store"; -import { Alert, AlertDescription, AlertTitle } from "../ui/alert"; interface CodePanelProps { themeEditorState: ThemeEditorState; @@ -50,7 +49,9 @@ const CodePanel: React.FC = ({ themeEditorState }) => { ); const getRegistryCommand = (preset: string) => { - const url = `https://tweakcn.com/r/themes/${preset}.json`; + const url = isSavedPreset + ? `https://tweakcn.com/r/themes/${preset}` + : `https://tweakcn.com/r/themes/${preset}.json`; switch (packageManager) { case "pnpm": return `pnpm dlx shadcn@latest add ${url}`; @@ -102,7 +103,7 @@ const CodePanel: React.FC = ({ themeEditorState }) => {

Theme Code

- {preset && preset !== "default" && !isSavedPreset && ( + {preset && preset !== "default" && (
{(["pnpm", "npm", "yarn", "bun"] as const).map((pm) => ( @@ -147,20 +148,6 @@ const CodePanel: React.FC = ({ themeEditorState }) => {
)} - {isSavedPreset && ( - - - - Registry commands are not supported for saved themes yet - - Coming Soon - - - - You can still copy and use the theme code directly. - - - )}