1
+ import { Editor as MonacoEditor } from "@monaco-editor/react" ;
2
+ import {
3
+ CheckIcon ,
4
+ ChevronDownIcon ,
5
+ CopyIcon ,
6
+ FileJsonIcon ,
7
+ SettingsIcon ,
8
+ ZapIcon ,
9
+ } from "lucide-react" ;
10
+ import { type FC , useEffect , useState } from "react" ;
1
11
import { Button } from "@/client/components/Button" ;
2
12
import {
3
13
DropdownMenu ,
@@ -13,21 +23,11 @@ import {
13
23
TooltipContent ,
14
24
TooltipTrigger ,
15
25
} from "@/client/components/Tooltip" ;
16
- import { useTheme } from "@/client/contexts/theme" ;
17
- import { snippets , type SnippetFunc } from "@/client/snippets" ;
18
- import { cn } from "@/utils/cn" ;
19
- import { Editor as MonacoEditor } from "@monaco-editor/react" ;
20
- import {
21
- CheckIcon ,
22
- ChevronDownIcon ,
23
- CopyIcon ,
24
- FileJsonIcon ,
25
- SettingsIcon ,
26
- ZapIcon ,
27
- } from "lucide-react" ;
28
- import { type FC , useEffect , useRef , useState } from "react" ;
29
26
import { useEditor } from "@/client/contexts/editor" ;
27
+ import { useTheme } from "@/client/contexts/theme" ;
28
+ import { type SnippetFunc , snippets } from "@/client/snippets" ;
30
29
import type { ParameterWithSource } from "@/gen/types" ;
30
+ import { cn } from "@/utils/cn" ;
31
31
32
32
type EditorProps = {
33
33
code : string ;
@@ -42,9 +42,6 @@ export const Editor: FC<EditorProps> = ({ code, setCode, parameters }) => {
42
42
const [ tab , setTab ] = useState ( ( ) => "code" ) ;
43
43
44
44
const [ codeCopied , setCodeCopied ] = useState ( ( ) => false ) ;
45
- const copyTimeoutId = useRef < ReturnType < typeof setTimeout > | undefined > (
46
- undefined ,
47
- ) ;
48
45
49
46
const onCopy = ( ) => {
50
47
navigator . clipboard . writeText ( code ) ;
@@ -65,13 +62,11 @@ export const Editor: FC<EditorProps> = ({ code, setCode, parameters }) => {
65
62
return ;
66
63
}
67
64
68
- clearTimeout ( copyTimeoutId . current ) ;
69
-
70
- copyTimeoutId . current = setTimeout ( ( ) => {
65
+ const copyTimeoutId = setTimeout ( ( ) => {
71
66
setCodeCopied ( ( ) => false ) ;
72
67
} , 1000 ) ;
73
68
74
- return ( ) => clearTimeout ( copyTimeoutId . current ) ;
69
+ return ( ) => clearTimeout ( copyTimeoutId ) ;
75
70
} , [ codeCopied ] ) ;
76
71
77
72
return (
0 commit comments