import React, { lazy, useEffect, useState } from 'react'; import { ServerContext } from '@/state/server'; import getFileContents from '@/api/server/files/getFileContents'; import useRouter from 'use-react-router'; const LazyAceEditor = lazy(() => import(/* webpackChunkName: "editor" */'@/components/elements/AceEditor')); export default () => { const { location: { hash } } = useRouter(); const [ content, setContent ] = useState(''); const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); let ref: null| (() => Promise) = null; useEffect(() => { getFileContents(uuid, hash.replace(/^#/, '')) .then(setContent) .catch(error => console.error(error)); }, [ uuid, hash ]); return (
{ ref = value; }} onContentSaved={() => null} />
); };