From 9ef8b39c167eac6c80001bedc576d330d2c125ef Mon Sep 17 00:00:00 2001 From: MananTank Date: Tue, 26 Nov 2024 18:32:56 +0000 Subject: [PATCH] Improve loading state for code block (#5520) DASH-473 --- .../components/blocks/code-segment.client.tsx | 1 - .../components/ui/code/CodeBlockContainer.tsx | 50 ++++++++++++++ .../src/@/components/ui/code/RenderCode.tsx | 69 +++---------------- .../src/@/components/ui/code/code.client.tsx | 23 +++---- .../@/components/ui/code/plaintext-code.tsx | 49 +++---------- .../[contractAddress]/embed/embed-setup.tsx | 6 +- .../src/components/connect/CodePlayground.tsx | 1 - .../published-contract/markdown-renderer.tsx | 10 +-- .../shared/sources-accordion.tsx | 12 +--- 9 files changed, 90 insertions(+), 131 deletions(-) create mode 100644 apps/dashboard/src/@/components/ui/code/CodeBlockContainer.tsx diff --git a/apps/dashboard/src/@/components/blocks/code-segment.client.tsx b/apps/dashboard/src/@/components/blocks/code-segment.client.tsx index 4789ca76888..594a088bb1d 100644 --- a/apps/dashboard/src/@/components/blocks/code-segment.client.tsx +++ b/apps/dashboard/src/@/components/blocks/code-segment.client.tsx @@ -109,7 +109,6 @@ export const CodeSegment: React.FC = ({ <> + + {props.children} + + + + + ); +} diff --git a/apps/dashboard/src/@/components/ui/code/RenderCode.tsx b/apps/dashboard/src/@/components/ui/code/RenderCode.tsx index dad2918b8e9..8a0197c2409 100644 --- a/apps/dashboard/src/@/components/ui/code/RenderCode.tsx +++ b/apps/dashboard/src/@/components/ui/code/RenderCode.tsx @@ -1,70 +1,23 @@ -import { ScrollShadow } from "@/components/ui/ScrollShadow/ScrollShadow"; -import { Button } from "@/components/ui/button"; -import { ToolTipLabel } from "@/components/ui/tooltip"; -import { cn } from "@/lib/utils"; -import { CheckIcon, CopyIcon } from "lucide-react"; -import { useState } from "react"; +import { CodeBlockContainer } from "./CodeBlockContainer"; export function RenderCode(props: { code: string; html: string; className?: string; scrollableClassName?: string; + copyButtonClassName?: string; }) { return ( -
- -
- - -
- ); -} - -function CopyButton(props: { - text: string; - className?: string; - iconClassName?: string; -}) { - const [isCopied, setIsCopied] = useState(false); - return ( - - - + ); } diff --git a/apps/dashboard/src/@/components/ui/code/code.client.tsx b/apps/dashboard/src/@/components/ui/code/code.client.tsx index 927181c597b..d36da1075f6 100644 --- a/apps/dashboard/src/@/components/ui/code/code.client.tsx +++ b/apps/dashboard/src/@/components/ui/code/code.client.tsx @@ -1,19 +1,17 @@ "use client"; - -import { cn } from "@/lib/utils"; import { keepPreviousData, useQuery } from "@tanstack/react-query"; import type { BundledLanguage } from "shiki"; -import { Spinner } from "../../ui/Spinner/Spinner"; import { RenderCode } from "./RenderCode"; import { getCodeHtml } from "./getCodeHtml"; +import { PlainTextCodeBlock } from "./plaintext-code"; export type CodeProps = { code: string; lang: BundledLanguage; className?: string; scrollableClassName?: string; - loadingClassName?: string; keepPreviousDataOnCodeChange?: boolean; + copyButtonClassName?: string; }; export const CodeClient: React.FC = ({ @@ -21,8 +19,8 @@ export const CodeClient: React.FC = ({ lang, className, scrollableClassName, - loadingClassName, keepPreviousDataOnCodeChange = false, + copyButtonClassName, }) => { const codeQuery = useQuery({ queryKey: ["html", code], @@ -35,14 +33,12 @@ export const CodeClient: React.FC = ({ if (!codeQuery.data) { return ( -
- -
+ ); } @@ -52,6 +48,7 @@ export const CodeClient: React.FC = ({ html={codeQuery.data.html} className={className} scrollableClassName={scrollableClassName} + copyButtonClassName={copyButtonClassName} /> ); }; diff --git a/apps/dashboard/src/@/components/ui/code/plaintext-code.tsx b/apps/dashboard/src/@/components/ui/code/plaintext-code.tsx index 595714d58a1..9d5f6111ca2 100644 --- a/apps/dashboard/src/@/components/ui/code/plaintext-code.tsx +++ b/apps/dashboard/src/@/components/ui/code/plaintext-code.tsx @@ -1,10 +1,5 @@ -"use client"; - import { cn } from "@/lib/utils"; -import { useClipboard } from "hooks/useClipboard"; -import { CheckIcon, CopyIcon } from "lucide-react"; -import { ScrollShadow } from "../ScrollShadow/ScrollShadow"; -import { Button } from "../button"; +import { CodeBlockContainer } from "./CodeBlockContainer"; export function PlainTextCodeBlock(props: { code: string; @@ -13,40 +8,16 @@ export function PlainTextCodeBlock(props: { scrollableClassName?: string; codeClassName?: string; }) { - const { hasCopied, onCopy } = useClipboard(props.code); - return ( -
- - - {props.code} - - - - -
+ + {props.code} + + ); } diff --git a/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/embed/embed-setup.tsx b/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/embed/embed-setup.tsx index 69c8e49bbd7..d21b2d46eb9 100644 --- a/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/embed/embed-setup.tsx +++ b/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/embed/embed-setup.tsx @@ -529,11 +529,7 @@ export const EmbedSetup: React.FC = ({ Embed Code - +