diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-11-20 11:13:33 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-11-20 11:13:33 -0600 |
| commit | 928d053a72cb96010b6611486b2c1caf397b2827 (patch) | |
| tree | bdaf86aa38dddd0d145b8030d45235fcaddab726 /src/web | |
| parent | 8fa0ac8e5d58394b92ddf65200458db8a4702cda (diff) | |
| download | slskd-928d053a72cb96010b6611486b2c1caf397b2827.tar.gz | |
tweak display of options/yaml
Diffstat (limited to 'src/web')
| -rw-r--r-- | src/web/src/components/System/Options/CodeEditor.js | 19 | ||||
| -rw-r--r-- | src/web/src/components/System/Options/Edit.js | 25 | ||||
| -rw-r--r-- | src/web/src/components/System/Options/View.js | 22 | ||||
| -rw-r--r-- | src/web/src/components/System/System.css | 6 |
4 files changed, 43 insertions, 29 deletions
diff --git a/src/web/src/components/System/Options/CodeEditor.js b/src/web/src/components/System/Options/CodeEditor.js new file mode 100644 index 00000000..77867a12 --- /dev/null +++ b/src/web/src/components/System/Options/CodeEditor.js @@ -0,0 +1,19 @@ +import React from 'react'; + +import CodeMirror from '@uiw/react-codemirror'; +import { StreamLanguage } from '@codemirror/stream-parser'; +import { yaml } from '@codemirror/legacy-modes/mode/yaml'; +import { defaultHighlightStyle } from '@codemirror/highlight'; + +const CodeEditor = ({ value, onChange = () => {}, ...rest}) => { + return ( + <CodeMirror + value={value} + extensions={[StreamLanguage.define(yaml), defaultHighlightStyle.fallback]} + onChange={(value, _) => onChange(value)} + { ...rest} + /> + ); +} + +export default CodeEditor;
\ No newline at end of file diff --git a/src/web/src/components/System/Options/Edit.js b/src/web/src/components/System/Options/Edit.js index dfcb0072..0092279a 100644 --- a/src/web/src/components/System/Options/Edit.js +++ b/src/web/src/components/System/Options/Edit.js @@ -1,7 +1,7 @@ import React, { useState, useEffect } from 'react'; import { Button, Icon, Message } from 'semantic-ui-react'; -import CodeEditor from '@uiw/react-textarea-code-editor'; +import CodeEditor from './CodeEditor'; import { getYaml, validateYaml, updateYaml } from '../../../lib/options'; import PlaceholderSegment from '../../Shared/PlaceholderSegment'; @@ -56,20 +56,15 @@ const Edit = ({ cancelAction }) => { return ( <> - <CodeEditor - value={yaml} - language='yaml' - onChange={(e) => update(e.target.value)} - padding={10} - style={{ - border: '1px solid #d4d4d5', - backgroundColor: 'rgb(250, 250, 250)', - fontSize: '1em', - fontFamily: 'ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace', - overflow: 'auto', - height: yamlError ? 'calc(100vh - 316px)' : 'calc(100vh - 254px)' - }} - /> + <div + className='code-container' + style={{height: yamlError ? 'calc(100vh - 316px)' : undefined}} + > + <CodeEditor + value={yaml} + onChange={(value) => update(value)} + /> + </div> {yamlError && <Message className='yaml-error' icon='x' negative>{yamlError}</Message>} <div className='footer-buttons'> <Button primary disabled={!isDirty} onClick={() => save(yaml)}><Icon name='save'/>Save</Button> diff --git a/src/web/src/components/System/Options/View.js b/src/web/src/components/System/Options/View.js index 980a90d8..61651f8d 100644 --- a/src/web/src/components/System/Options/View.js +++ b/src/web/src/components/System/Options/View.js @@ -2,7 +2,7 @@ import React from 'react'; import yaml from 'yaml'; import { Icon, Button } from 'semantic-ui-react'; -import CodeEditor from '@uiw/react-textarea-code-editor'; +import CodeEditor from './CodeEditor'; const View = ({ options, editAction }) => { const { remoteConfiguration } = options; @@ -14,19 +14,13 @@ const View = ({ options, editAction }) => { return ( <> - <CodeEditor - value={optionsAsYaml} - language='yaml' - disabled={true} - padding={10} - style={{ - border: '1px solid #d4d4d5', - fontSize: '1em', - fontFamily: 'ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace', - overflow: 'auto', - height: 'calc(100vh - 254px)' - }} - /> + <div className='code-container'> + <CodeEditor + value={optionsAsYaml} + basicSetup={false} + editable={false} + /> + </div> <div className='footer-buttons'> {remoteConfiguration ? <Button primary onClick={() => editAction()}><Icon name='edit'/>Edit</Button> : diff --git a/src/web/src/components/System/System.css b/src/web/src/components/System/System.css index 3a930667..23f05221 100644 --- a/src/web/src/components/System/System.css +++ b/src/web/src/components/System/System.css @@ -36,4 +36,10 @@ .footer-buttons { margin-top: 14px; text-align: right; +} + +.code-container { + border: 1px solid #d4d4d5; + overflow: auto; + height: calc(100vh - 254px); }
\ No newline at end of file |
