1
- import React , { FC , PropsWithChildren , useState , useEffect } from "react" ;
2
- import { getApiKey } from "api/api" ;
3
- import { VSCodeIcon } from "components/Icons/VSCodeIcon" ;
4
- import { VSCodeInsidersIcon } from "components/Icons/VSCodeInsidersIcon" ;
5
- import { PrimaryAgentButton } from "components/Resources/AgentButton" ;
6
- import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown" ;
1
+ import React , { FC , PropsWithChildren , useState , useEffect } from "react"
2
+ import { getApiKey } from "api/api"
3
+ import { VSCodeIcon } from "components/Icons/VSCodeIcon"
4
+ import { VSCodeInsidersIcon } from "components/Icons/VSCodeInsidersIcon"
5
+ import { PrimaryAgentButton } from "components/Resources/AgentButton"
6
+ import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown"
7
7
8
8
export interface VSCodeDesktopButtonProps {
9
- userName : string ;
10
- workspaceName : string ;
11
- agentName ?: string ;
12
- folderPath ?: string ;
9
+ userName : string
10
+ workspaceName : string
11
+ agentName ?: string
12
+ folderPath ?: string
13
13
}
14
14
15
15
enum VSCodeVariant {
@@ -18,69 +18,69 @@ enum VSCodeVariant {
18
18
}
19
19
20
20
const getSelectedVariantFromLocalStorage = ( ) : VSCodeVariant | null => {
21
- const storedVariant = localStorage . getItem ( "selectedVariant" ) ;
21
+ const storedVariant = localStorage . getItem ( "selectedVariant" )
22
22
if (
23
23
storedVariant &&
24
24
Object . values ( VSCodeVariant ) . includes ( storedVariant as VSCodeVariant )
25
25
) {
26
- return storedVariant as VSCodeVariant ;
26
+ return storedVariant as VSCodeVariant
27
27
}
28
- return null ;
29
- } ;
28
+ return null
29
+ }
30
30
31
31
export const VSCodeDesktopButton : FC <
32
32
PropsWithChildren < VSCodeDesktopButtonProps >
33
33
> = ( { userName, workspaceName, agentName, folderPath } ) => {
34
- const [ loading , setLoading ] = useState ( false ) ;
34
+ const [ loading , setLoading ] = useState ( false )
35
35
const [ selectedVariant , setSelectedVariant ] = useState < VSCodeVariant | null > (
36
- getSelectedVariantFromLocalStorage ( )
37
- ) ;
38
- const [ dropdownOpen , setDropdownOpen ] = useState ( false ) ;
36
+ getSelectedVariantFromLocalStorage ( ) ,
37
+ )
38
+ const [ dropdownOpen , setDropdownOpen ] = useState ( false )
39
39
40
40
useEffect ( ( ) => {
41
41
if ( selectedVariant ) {
42
- localStorage . setItem ( "selectedVariant" , selectedVariant ) ;
42
+ localStorage . setItem ( "selectedVariant" , selectedVariant )
43
43
} else {
44
- localStorage . removeItem ( "selectedVariant" ) ;
44
+ localStorage . removeItem ( "selectedVariant" )
45
45
}
46
- } , [ selectedVariant ] ) ;
46
+ } , [ selectedVariant ] )
47
47
48
48
const handleButtonClick = ( ) => {
49
- setLoading ( true ) ;
49
+ setLoading ( true )
50
50
getApiKey ( )
51
51
. then ( ( { key } ) => {
52
52
const query = new URLSearchParams ( {
53
53
owner : userName ,
54
54
workspace : workspaceName ,
55
55
url : location . origin ,
56
56
token : key ,
57
- } ) ;
57
+ } )
58
58
if ( agentName ) {
59
- query . set ( "agent" , agentName ) ;
59
+ query . set ( "agent" , agentName )
60
60
}
61
61
if ( folderPath ) {
62
- query . set ( "folder" , folderPath ) ;
62
+ query . set ( "folder" , folderPath )
63
63
}
64
64
65
65
const vscodeCommand =
66
66
selectedVariant === VSCodeVariant . VSCode
67
67
? "vscode://"
68
- : "vscode-insiders://" ;
68
+ : "vscode-insiders://"
69
69
70
- location . href = `${ vscodeCommand } coder.coder-remote/open?${ query . toString ( ) } ` ;
70
+ location . href = `${ vscodeCommand } coder.coder-remote/open?${ query . toString ( ) } `
71
71
} )
72
72
. catch ( ( ex ) => {
73
- console . error ( ex ) ;
73
+ console . error ( ex )
74
74
} )
75
75
. finally ( ( ) => {
76
- setLoading ( false ) ;
77
- } ) ;
78
- } ;
76
+ setLoading ( false )
77
+ } )
78
+ }
79
79
80
80
const handleVariantChange = ( variant : VSCodeVariant ) => {
81
- setSelectedVariant ( variant ) ;
82
- setDropdownOpen ( false ) ;
83
- } ;
81
+ setSelectedVariant ( variant )
82
+ setDropdownOpen ( false )
83
+ }
84
84
85
85
return (
86
86
< div style = { { position : "relative" , display : "inline-flex" } } >
@@ -99,9 +99,7 @@ export const VSCodeDesktopButton: FC<
99
99
? "VS Code Desktop"
100
100
: "VS Code Insiders" }
101
101
</ PrimaryAgentButton >
102
- < PrimaryAgentButton
103
- onClick = { ( ) => setDropdownOpen ( ! dropdownOpen ) }
104
- >
102
+ < PrimaryAgentButton onClick = { ( ) => setDropdownOpen ( ! dropdownOpen ) } >
105
103
< KeyboardArrowDownIcon
106
104
style = { {
107
105
transition : "transform 0.3s ease-in-out" ,
@@ -134,5 +132,5 @@ export const VSCodeDesktopButton: FC<
134
132
</ div >
135
133
) }
136
134
</ div >
137
- ) ;
138
- } ;
135
+ )
136
+ }
0 commit comments