11import Editor , { DiffEditor } from '@monaco-editor/react' ;
2- import { useStoreState } from '../../state/Hooks' ;
2+ import { useRef } from 'react' ;
3+ import { useStoreActions , useStoreState } from '../../state/Hooks' ;
4+ import DropdownContainer from '../containers/DropdownContainer' ;
35
46const EditorPane = ( ) => {
57 const config = useStoreState ( ( state ) => state . config ) ;
68 const editingConfig = useStoreState ( ( state ) => state . editingConfig ) ;
9+ const loadConfig = useStoreActions ( ( actions ) => actions . loadConfig ) ;
10+ const inputFile = useRef < HTMLInputElement > ( null ) ;
711
812 const configYAML = ( yml : string ) => {
913 const matchSDKComment = yml ?. match ( '# SDK Version: .*\n' ) ;
@@ -24,28 +28,57 @@ const EditorPane = () => {
2428
2529 return (
2630 < div className = "bg-circle-gray-900 h-2/5 w-full flex flex-col" >
27- < div className = "border-b text-xl border-circle-gray-800 font-bold" >
31+ < div className = "border-b text-xl border-circle-gray-800 font-bold flex flex-row " >
2832 < div className = "ml-4 border-b-4 px-3 py-3 w-max text-sm tracking-wide font-bold text-white border-white" >
2933 CONFIG
3034 </ div >
35+ < div className = "p-2 ml-auto" >
36+ < input
37+ type = "file"
38+ accept = ".yml,.yaml"
39+ ref = { inputFile }
40+ className = "hidden"
41+ onChange = { ( e ) => {
42+ if ( ! e . target . files ) {
43+ return ;
44+ }
45+
46+ e . target . files [ 0 ] . text ( ) . then ( ( yml ) => {
47+ loadConfig ( yml ) ;
48+ } ) ;
49+ } }
50+ />
51+ < DropdownContainer className = "rounded-md bg-circle-blue text-white px-2" >
52+ < div className = "bg-white flex-col flex rounded shadow text-base" >
53+ < button
54+ className = "border-b border-circle-gray-300 px-8"
55+ onClick = { ( e ) => {
56+ inputFile . current ?. click ( ) ;
57+ e . stopPropagation ( ) ;
58+ } }
59+ >
60+ Open
61+ </ button >
62+ < button > Save</ button >
63+ </ div >
64+ </ DropdownContainer >
65+ </ div >
3166 </ div >
3267 < div className = "flex-1 overflow-hidden" >
33- {
34- editingConfig ?
35- ( < DiffEditor
36- theme = "vs-dark"
37- language = "yaml"
38- original = { config && configYAML ( config ) }
39- modified = { editingConfig && configYAML ( editingConfig ) }
40- /> )
41- :
42- ( < Editor
43- theme = "vs-dark"
44- language = "yaml"
45- value = { config && configYAML ( config ) }
46- />
47- )
48- }
68+ { editingConfig ? (
69+ < DiffEditor
70+ theme = "vs-dark"
71+ language = "yaml"
72+ original = { config && configYAML ( config ) }
73+ modified = { editingConfig && configYAML ( editingConfig ) }
74+ />
75+ ) : (
76+ < Editor
77+ theme = "vs-dark"
78+ language = "yaml"
79+ value = { config && configYAML ( config ) }
80+ />
81+ ) }
4982 </ div >
5083 </ div >
5184 ) ;
0 commit comments