@@ -52,15 +52,14 @@ Object.keys(modes).forEach(mode => require(`brace/mode/${mode}`));
5252
5353export interface Props {
5454 style ?: React . CSSProperties ;
55+ initialContent ?: string ;
56+ initialModePath ?: string ;
5557 fetchContent : ( callback : ( ) => Promise < string > ) => void ;
5658 onContentSaved : ( content : string ) => void ;
5759}
5860
59- export default ( { fetchContent, onContentSaved } : Props ) => {
60- const { location : { hash } } = useRouter ( ) ;
61- const [ content , setContent ] = useState ( '' ) ;
61+ export default ( { style, initialContent, initialModePath, fetchContent, onContentSaved } : Props ) => {
6262 const [ mode , setMode ] = useState ( 'plain_text' ) ;
63- const uuid = ServerContext . useStoreState ( state => state . server . data ! . uuid ) ;
6463
6564 const [ editor , setEditor ] = useState < Editor > ( ) ;
6665 const ref = useCallback ( node => {
@@ -69,30 +68,22 @@ export default ({ fetchContent, onContentSaved }: Props) => {
6968 }
7069 } , [ ] ) ;
7170
72- useEffect ( ( ) => {
73- getFileContents ( uuid , hash . replace ( / ^ # / , '' ) )
74- . then ( setContent )
75- . catch ( error => console . error ( error ) ) ;
76- } , [ uuid , hash ] ) ;
77-
78- useEffect ( ( ) => {
79- if ( ! hash . length ) {
80- return ;
81- }
82-
83- const modelist = ace . acequire ( 'ace/ext/modelist' ) ;
84- if ( modelist ) {
85- setMode ( modelist . getModeForPath ( hash . replace ( / ^ # / , '' ) ) . mode ) ;
86- }
87- } , [ hash ] ) ;
88-
8971 useEffect ( ( ) => {
9072 editor && editor . session . setMode ( mode ) ;
9173 } , [ editor , mode ] ) ;
9274
9375 useEffect ( ( ) => {
94- editor && editor . session . setValue ( content ) ;
95- } , [ editor , content ] ) ;
76+ editor && editor . session . setValue ( initialContent || '' ) ;
77+ } , [ editor , initialContent ] ) ;
78+
79+ useEffect ( ( ) => {
80+ if ( initialModePath ) {
81+ const modelist = ace . acequire ( 'ace/ext/modelist' ) ;
82+ if ( modelist ) {
83+ setMode ( modelist . getModeForPath ( initialModePath ) . mode ) ;
84+ }
85+ }
86+ } , [ initialModePath ] ) ;
9687
9788 useEffect ( ( ) => {
9889 if ( ! editor ) {
@@ -120,7 +111,7 @@ export default ({ fetchContent, onContentSaved }: Props) => {
120111 } , [ editor , fetchContent , onContentSaved ] ) ;
121112
122113 return (
123- < EditorContainer >
114+ < EditorContainer style = { style } >
124115 < div id = { 'editor' } ref = { ref } />
125116 < div className = { 'absolute pin-r pin-t z-50' } >
126117 < div className = { 'm-3 rounded bg-neutral-900 border border-black' } >
0 commit comments