First iteration of a file manager
This commit is contained in:
parent
ac52810ef6
commit
2e32df98ea
8 changed files with 169 additions and 28 deletions
|
@ -8,6 +8,7 @@ env:
|
|||
es6: true
|
||||
plugins:
|
||||
- "@typescript-eslint"
|
||||
- "react-hooks"
|
||||
extends:
|
||||
- "standard"
|
||||
- "plugin:@typescript-eslint/recommended"
|
||||
|
@ -20,6 +21,10 @@ rules:
|
|||
comma-dangle:
|
||||
- error
|
||||
- always-multiline
|
||||
"react-hooks/rules-of-hooks":
|
||||
- error
|
||||
"react-hooks/exhaustive-deps":
|
||||
- warn
|
||||
"@typescript-eslint/explicit-function-return-type": 0
|
||||
"@typescript-eslint/explicit-member-accessibility": 0
|
||||
"@typescript-eslint/no-unused-vars": 0
|
||||
|
|
|
@ -36,6 +36,13 @@ export default class DesignElementsContainer extends React.PureComponent {
|
|||
<label className={'uppercase text-neutral-200'}>Disabled Field</label>
|
||||
<input type={'text'} className={'input-dark'} disabled={true}/>
|
||||
<div className={'mt-6'}/>
|
||||
<label className={'uppercase text-neutral-200'}>Select</label>
|
||||
<select className={'input-dark'}>
|
||||
<option>Option 1</option>
|
||||
<option>Option 2</option>
|
||||
<option>Option 3</option>
|
||||
</select>
|
||||
<div className={'mt-6'}/>
|
||||
<label className={'uppercase text-neutral-200'}>Textarea</label>
|
||||
<textarea className={'input-dark h-32'}></textarea>
|
||||
<div className={'mt-6'}/>
|
||||
|
|
|
@ -12,8 +12,8 @@ import TitledGreyBox from '@/components/elements/TitledGreyBox';
|
|||
|
||||
type PowerAction = 'start' | 'stop' | 'restart' | 'kill';
|
||||
|
||||
const ChunkedConsole = lazy(() => import('@/components/server/Console'));
|
||||
const ChunkedStatGraphs = lazy(() => import('@/components/server/StatGraphs'));
|
||||
const ChunkedConsole = lazy(() => import(/* webpackChunkName: "console" */'@/components/server/Console'));
|
||||
const ChunkedStatGraphs = lazy(() => import(/* webpackChunkName: "graphs" */'@/components/server/StatGraphs'));
|
||||
|
||||
const StopOrKillButton = ({ onPress }: { onPress: (action: PowerAction) => void }) => {
|
||||
const [ clicked, setClicked ] = useState(false);
|
||||
|
|
|
@ -1,25 +1,115 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import useRouter from 'use-react-router';
|
||||
import { ServerContext } from '@/state/server';
|
||||
import getFileContents from '@/api/server/files/getFileContents';
|
||||
import ace, { Editor } from 'brace';
|
||||
import styled from 'styled-components';
|
||||
|
||||
const EditorContainer = styled.div`
|
||||
height: calc(100vh - 16rem);
|
||||
${tw`relative`};
|
||||
|
||||
#editor {
|
||||
${tw`rounded h-full`};
|
||||
}
|
||||
`;
|
||||
|
||||
const modes: { [k: string]: string } = {
|
||||
// eslint-disable-next-line @typescript-eslint/camelcase
|
||||
assembly_x86: 'Assembly (x86)',
|
||||
// eslint-disable-next-line @typescript-eslint/camelcase
|
||||
c_cpp: 'C++',
|
||||
coffee: 'Coffeescript',
|
||||
css: 'CSS',
|
||||
dockerfile: 'Dockerfile',
|
||||
golang: 'Go',
|
||||
html: 'HTML',
|
||||
ini: 'Ini',
|
||||
java: 'Java',
|
||||
javascript: 'Javascript',
|
||||
json: 'JSON',
|
||||
kotlin: 'Kotlin',
|
||||
lua: 'Luascript',
|
||||
perl: 'Perl',
|
||||
php: 'PHP',
|
||||
properties: 'Properties',
|
||||
python: 'Python',
|
||||
ruby: 'Ruby',
|
||||
text: 'Plaintext',
|
||||
toml: 'TOML',
|
||||
typescript: 'Typescript',
|
||||
xml: 'XML',
|
||||
yaml: 'YAML',
|
||||
};
|
||||
|
||||
export default () => {
|
||||
const { location: { hash } } = useRouter();
|
||||
const [content, setContent] = useState('');
|
||||
const [ content, setContent ] = useState('');
|
||||
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
|
||||
|
||||
const [ editor, setEditor ] = useState<Editor>();
|
||||
const ref = useCallback(node => {
|
||||
if (node) {
|
||||
setEditor(ace.edit('editor'));
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
Object.keys(modes).forEach(mode => {
|
||||
import(/* webpackMode: "lazy-once", webpackChunkName: "ace_mode" */`brace/mode/${mode}`);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
getFileContents(uuid, hash.replace(/^#/, ''))
|
||||
.then(setContent)
|
||||
.catch(error => console.error(error));
|
||||
}, []);
|
||||
}, [ uuid, hash ]);
|
||||
|
||||
useEffect(() => {
|
||||
editor && editor.session.setValue(content);
|
||||
}, [ editor, content ]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
|
||||
require('ayu-ace/mirage');
|
||||
editor.setTheme('ace/theme/ayu-mirage');
|
||||
|
||||
editor.$blockScrolling = Infinity;
|
||||
editor.container.style.lineHeight = '1.375rem';
|
||||
editor.container.style.fontWeight = '500';
|
||||
editor.renderer.updateFontSize();
|
||||
editor.renderer.setShowPrintMargin(false);
|
||||
editor.session.setTabSize(4);
|
||||
editor.session.setUseSoftTabs(true);
|
||||
}, [ editor ]);
|
||||
|
||||
return (
|
||||
<div className={'my-10'}>
|
||||
<textarea
|
||||
value={content}
|
||||
className={'rounded bg-black h-32 w-full text-neutral-100 text-sm font-mono'}
|
||||
/>
|
||||
<EditorContainer>
|
||||
<div id={'editor'} ref={ref}/>
|
||||
<div className={'absolute pin-r pin-t z-50'}>
|
||||
<div className={'m-3 rounded bg-neutral-900 border border-black'}>
|
||||
<select
|
||||
className={'input-dark'}
|
||||
onChange={e => {
|
||||
if (editor) {
|
||||
editor.session.setMode(`ace/mode/${e.currentTarget.value}`);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{
|
||||
Object.keys(modes).map(key => (
|
||||
<option key={key} value={key}>{modes[key]}</option>
|
||||
))
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</EditorContainer>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ import { CSSTransition } from 'react-transition-group';
|
|||
import SuspenseSpinner from '@/components/elements/SuspenseSpinner';
|
||||
|
||||
const LazyFileEditContainer = lazy<React.ComponentType<RouteComponentProps<any>>>(
|
||||
() => import('@/components/server/files/FileEditContainer')
|
||||
() => import(/* webpackChunkName: "editor" */'@/components/server/files/FileEditContainer')
|
||||
);
|
||||
|
||||
const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue