From a7655ad2c97ee0d9eec28e332cd523bc0d9b9082 Mon Sep 17 00:00:00 2001 From: WK Date: Fri, 5 Dec 2025 03:59:57 +0800 Subject: [PATCH] chore(docs): remove chat linkage (#5959) * chore: remove unused globalEnv * chore(docs): remove chat links --- apps/docs/.env.example | 5 - apps/docs/actions/open-in-chat.ts | 100 ------------------ .../docs/components/code-demo/code-demo.tsx | 92 +--------------- apps/docs/components/heroui-chat-banner.tsx | 92 ---------------- apps/docs/components/random-banner.tsx | 26 ----- turbo.json | 5 +- 6 files changed, 3 insertions(+), 317 deletions(-) delete mode 100644 apps/docs/actions/open-in-chat.ts delete mode 100644 apps/docs/components/heroui-chat-banner.tsx delete mode 100644 apps/docs/components/random-banner.tsx diff --git a/apps/docs/.env.example b/apps/docs/.env.example index 41fa30874..9cc4d57fe 100644 --- a/apps/docs/.env.example +++ b/apps/docs/.env.example @@ -22,8 +22,3 @@ NEXT_PUBLIC_FB_FEEDBACK_URL= # PostHog NEXT_PUBLIC_POSTHOG_KEY=your-posthog-key NEXT_PUBLIC_POSTHOG_HOST=your-posthog-host - -# Chat -IMPORT_API_KEY=your-import-api-key -CHAT_API_URL= -CHAT_URL= diff --git a/apps/docs/actions/open-in-chat.ts b/apps/docs/actions/open-in-chat.ts deleted file mode 100644 index 3032069c8..000000000 --- a/apps/docs/actions/open-in-chat.ts +++ /dev/null @@ -1,100 +0,0 @@ -"use server"; - -import {toKebabCase, toPascalCase} from "@/components/docs/components/code-demo/utils"; - -const importReact = 'import React from "react";'; - -export const openInChat = async ({ - component, - title, - content, - dependencies, - useWrapper, -}: { - component: string; - title?: string; - content: string; - dependencies: {name: string; version: string}[]; - useWrapper: boolean; -}) => { - try { - // Check if the file content includes 'React' import statements, if not, add it - if ( - content.includes("React.") && - !content.includes("from 'react'") && - !content.includes('from "react"') - ) { - content = `${importReact}\n${content}\n`; - } - - let files: Record = { - "src/App.tsx": content, - }; - - const fullName = `${component.charAt(0).toUpperCase() + component.slice(1)} - ${title}`; - - if (useWrapper) { - files = getFilesWithWrapper(fullName, content); - } - - const response = await fetch(`${process.env.CHAT_API_URL}/import`, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${process.env.IMPORT_API_KEY}`, - }, - body: JSON.stringify({ - title: `${component.charAt(0).toUpperCase() + component.slice(1)} - ${title}`, - files, - dependencies, - }), - }); - - const result = await response.json(); - - if (result.error || !result.path) { - return { - error: result.error ?? "Unknown error", - data: null, - }; - } - - return { - error: null, - data: `${process.env.CHAT_URL}${ - result.path - }&utm_source=heroui.com&utm_medium=open-in-chat&utm_content=${encodeURIComponent( - title ?? "unknown", - )}`, - }; - } catch (error) { - return {error: error, data: null}; - } -}; - -const getFilesWithWrapper = (name: string, content: string) => { - const pascalName = toPascalCase(name); - const kebabName = toKebabCase(name); - - // Replace the export default function name - const updatedContent = content.replace( - "export default function App()", - `export default function ${pascalName}()`, - ); - - const wrapperContent = `import ${pascalName} from "./components/${kebabName}"; - -export default function App() { - return ( -
- <${pascalName} /> -
- ); -} -`; - - return { - [`src/components/${kebabName}.tsx`]: updatedContent, - [`src/App.tsx`]: wrapperContent, - }; -}; diff --git a/apps/docs/components/docs/components/code-demo/code-demo.tsx b/apps/docs/components/docs/components/code-demo/code-demo.tsx index 2644f0732..728a533bf 100644 --- a/apps/docs/components/docs/components/code-demo/code-demo.tsx +++ b/apps/docs/components/docs/components/code-demo/code-demo.tsx @@ -4,18 +4,13 @@ import type {UseCodeDemoProps} from "./use-code-demo"; import type {WindowResizerProps} from "./window-resizer"; import type {GradientBoxProps} from "@/components/gradient-box"; -import React, {useCallback, useMemo, useRef, useState} from "react"; +import React, {useCallback, useMemo, useRef} from "react"; import dynamic from "next/dynamic"; -import {addToast, Button, Skeleton, Spinner, Tab, Tabs} from "@heroui/react"; +import {Skeleton, Tab, Tabs} from "@heroui/react"; import {useInView} from "framer-motion"; -import {usePostHog} from "posthog-js/react"; -import {usePathname} from "next/navigation"; import {useCodeDemo} from "./use-code-demo"; import WindowResizer from "./window-resizer"; -import {parseDependencies} from "./parse-dependencies"; - -import {openInChat} from "@/actions/open-in-chat"; const DynamicReactLiveDemo = dynamic( () => import("./react-live-demo").then((m) => m.ReactLiveDemo), @@ -82,11 +77,6 @@ export const CodeDemo: React.FC = ({ margin: "600px", }); - const pathname = usePathname(); - const posthog = usePostHog(); - - const [isLoading, setIsLoading] = useState(false); - const {noInline, code} = useCodeDemo({ files, }); @@ -178,64 +168,6 @@ export const CodeDemo: React.FC = ({ return true; }, [showTabs, showPreview, showEditor]); - const isComponentsPage = pathname.includes("/components/"); - - const handleOpenInChat = useCallback(async () => { - setIsLoading(true); - - // assume doc demo files are all App.jsx - const content = files["/App.jsx"]; - - if (!content || typeof content !== "string") { - addToast({ - title: "Error", - description: "Invalid demo content", - color: "danger", - }); - - return; - } - - const component = pathname.split("/components/")[1]; - const dependencies = parseDependencies(content); - - posthog.capture("CodeDemo - Open in Chat", { - component, - demo: title, - }); - - const newTab = window.open(undefined, "_blank"); - - const {data, error} = await openInChat({ - component, - title, - content, - dependencies, - useWrapper: !asIframe, - }); - - setIsLoading(false); - - if (error || !data) { - if (newTab) newTab.close(); - posthog.capture("CodeDemo - Open in Chat Error", { - component, - demo: title, - error: error ?? "Unknown error", - }); - - addToast({ - title: "Error", - description: error ?? "Unknown error", - color: "danger", - }); - - return; - } - - if (newTab) newTab.location.href = data; - }, [pathname, title, files, posthog]); - return (
{shouldRenderTabs ? ( @@ -255,26 +187,6 @@ export const CodeDemo: React.FC = ({ {editorContent} - {isComponentsPage && ( - - )} ) : ( <> diff --git a/apps/docs/components/heroui-chat-banner.tsx b/apps/docs/components/heroui-chat-banner.tsx deleted file mode 100644 index 543e9263c..000000000 --- a/apps/docs/components/heroui-chat-banner.tsx +++ /dev/null @@ -1,92 +0,0 @@ -"use client"; - -import {Icon} from "@iconify/react/dist/offline"; -import arrowRightIcon from "@iconify/icons-solar/arrow-right-linear"; -import {usePathname} from "next/navigation"; -import {useEffect} from "react"; -import {usePostHog} from "posthog-js/react"; - -import emitter from "@/libs/emitter"; - -const hideOnPaths = ["examples"]; - -export const HeroUIChatBanner = () => { - const posthog = usePostHog(); - - const handleClick = () => { - posthog.capture("HeroUI Chat Banner", { - action: "click", - category: "landing-page", - }); - }; - - const pathname = usePathname(); - const shouldBeVisible = !hideOnPaths.some((path) => pathname.includes(path)); - - useEffect(() => { - if (!shouldBeVisible) return; - - // listen to scroll event, dispatch an event when scroll is at the top < 48 px - const handleScroll = () => { - if (window.scrollY < 48) { - emitter.emit("proBannerVisibilityChange", "visible"); - } else { - emitter.emit("proBannerVisibilityChange", "hidden"); - } - }; - - window.addEventListener("scroll", handleScroll); - - return () => { - window.removeEventListener("scroll", handleScroll); - }; - }, [shouldBeVisible]); - - if (!shouldBeVisible) return null; - - return ( - - ); -}; diff --git a/apps/docs/components/random-banner.tsx b/apps/docs/components/random-banner.tsx deleted file mode 100644 index 3466f6103..000000000 --- a/apps/docs/components/random-banner.tsx +++ /dev/null @@ -1,26 +0,0 @@ -"use client"; - -import {useState, useEffect} from "react"; - -import {HeroUIChatBanner} from "@/components/heroui-chat-banner"; -import {ProBanner} from "@/components/pro-banner"; - -export const RandomBanner = () => { - const [showChatBanner, setShowChatBanner] = useState(null); - - useEffect(() => { - const bannerCount = parseInt(sessionStorage.getItem("bannerCount") || "0", 10); - - const shouldShowChat = bannerCount % 2 === 0; - - setShowChatBanner(shouldShowChat); - - sessionStorage.setItem("bannerCount", String(bannerCount + 1)); - }, []); - - if (showChatBanner === null) { - return
; - } - - return showChatBanner ? : ; -}; diff --git a/turbo.json b/turbo.json index bae9c64f5..49efd9cd8 100644 --- a/turbo.json +++ b/turbo.json @@ -6,10 +6,7 @@ "IS_PREVIEW", "IS_VA_ENABLED", "ENABLE_EXPERIMENTAL_COREPACK", - "PLAIN_USER_AUTHENTICATED", - "IMPORT_API_KEY", - "CHAT_URL", - "CHAT_API_URL" + "PLAIN_USER_AUTHENTICATED" ], "tasks": { "build": {