@@ -5,34 +5,47 @@ import { UserContext } from "../user-context";
5
5
import { SettingsPage } from "./SettingsPage" ;
6
6
7
7
export default function Preferences ( ) {
8
- const { user } = useContext ( UserContext ) ;
9
- const [ defaultIde , setDefaultIde ] = useState < string > ( user ?. additionalData ?. ideSettings ?. defaultIde || 'code' ) ;
10
8
const [ hasIDESettingsPermissions , setHasIDESettingsPermissions ] = useState < boolean | undefined > ( undefined ) ;
11
9
if ( hasIDESettingsPermissions === undefined ) {
12
10
getGitpodService ( ) . server . hasPermission ( 'ide-settings' ) . then ( hasPermission => setHasIDESettingsPermissions ( hasPermission ) ) ;
13
11
}
14
12
13
+ const { user } = useContext ( UserContext ) ;
14
+ const [ defaultIde , setDefaultIde ] = useState < string > ( user ?. additionalData ?. ideSettings ?. defaultIde || 'theia' ) ;
15
+ const actuallySetDefaultIde = async ( value : string ) => {
16
+ const additionalData = user ?. additionalData || { } ;
17
+ const settings = additionalData . ideSettings || { } ;
18
+ if ( value === 'theia' ) {
19
+ delete settings . defaultIde ;
20
+ } else {
21
+ settings . defaultIde = value ;
22
+ }
23
+ additionalData . ideSettings = settings ;
24
+ await getGitpodService ( ) . server . updateLoggedInUser ( { additionalData } ) ;
25
+ setDefaultIde ( value ) ;
26
+ }
27
+
15
28
return < div >
16
29
< SettingsPage title = 'Preferences' subtitle = 'Configure your Default IDE for all workspaces.' >
17
30
< h3 > Default IDE</ h3 >
18
- < p className = "text-base" > Choose which IDE your workspaces should use.</ p >
31
+ < p className = "text-base" > Choose which IDE you want to use.</ p >
19
32
< div className = "mt-4 space-x-4 flex" >
20
- < SelectableCard className = "w-36 h-40" title = "VS Code" selected = { defaultIde === 'code' } onClick = { ( ) => setDefaultIde ( 'code' ) } >
33
+ < SelectableCard className = "w-36 h-40" title = "VS Code" selected = { defaultIde === 'code' } onClick = { ( ) => actuallySetDefaultIde ( 'code' ) } >
21
34
< div className = "flex-grow flex justify-center align-center" >
22
35
< img className = "w-16 filter-grayscale" src = "/images/vscode.svg" />
23
36
</ div >
24
37
</ SelectableCard >
25
- < SelectableCard className = "w-36 h-40" title = "Theia" selected = { defaultIde === 'theia' } onClick = { ( ) => setDefaultIde ( 'theia' ) } >
38
+ < SelectableCard className = "w-36 h-40" title = "Theia" selected = { defaultIde === 'theia' } onClick = { ( ) => actuallySetDefaultIde ( 'theia' ) } >
26
39
< div className = "flex-grow flex justify-center align-center" >
27
40
< img className = "w-16" src = "/images/theia-gray.svg" />
28
41
</ div >
29
42
</ SelectableCard >
30
- < SelectableCard className = { `w-36 h-40 ${ hasIDESettingsPermissions ? '' : 'invisible' } ` } title = "Custom" selected = { ! [ 'code' , 'theia' ] . includes ( defaultIde ) } onClick = { ( ) => setDefaultIde ( '' ) } > </ SelectableCard >
43
+ < SelectableCard className = { `w-36 h-40 ${ hasIDESettingsPermissions ? '' : 'invisible' } ` } title = "Custom" selected = { ! [ 'code' , 'theia' ] . includes ( defaultIde ) } onClick = { ( ) => setDefaultIde ( '' ) } > </ SelectableCard >
31
44
</ div >
32
- < div className = { `mt-4 ${ hasIDESettingsPermissions ? '' : 'invisible' } ` } >
33
- < label className = { [ 'code' , 'theia' ] . includes ( defaultIde ) ? 'opacity-0 ' : 'opacity-100 ' } >
45
+ < div className = { `mt-4` } >
46
+ < label className = { hasIDESettingsPermissions && ! [ 'code' , 'theia' ] . includes ( defaultIde ) ? 'opacity-100 ' : 'opacity-0 ' } >
34
47
< p className = "text-base text-gray-600 font-bold leading-5" > Custom IDE image name</ p >
35
- < input className = "w-80 mt-1" type = "text" />
48
+ < input className = "w-80 mt-1" type = "text" value = { defaultIde } onChange = { ( e ) => setDefaultIde ( e . target . value ) } onBlur = { ( e ) => actuallySetDefaultIde ( e . target . value ) } />
36
49
</ label >
37
50
</ div >
38
51
</ SettingsPage >
0 commit comments