Skip to content

Commit b12307a

Browse files
authored
Merge pull request #7 from crypto-stats/ri/feature/subgraph-editor
Ri/feature/subgraph editor
2 parents 6a84e17 + ced6c7c commit b12307a

32 files changed

+2668
-19
lines changed

components/CodeEditor.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface EditorProps {
1111
defaultValue: string
1212
fileId: string
1313
onMount?: (editor: any, monaco: any) => void
14+
defaultLanguage?: 'typescript' | 'graphql'
1415
}
1516

1617
const Editor: React.FC<EditorProps> = ({
@@ -19,6 +20,7 @@ const Editor: React.FC<EditorProps> = ({
1920
defaultValue,
2021
fileId,
2122
onMount,
23+
defaultLanguage = 'typescript',
2224
}) => {
2325
const code = useRef(defaultValue)
2426
const monaco = useMonaco()
@@ -64,12 +66,13 @@ const Editor: React.FC<EditorProps> = ({
6466
return (
6567
<MonacoEditor
6668
theme="vs-dark"
67-
defaultLanguage="typescript"
69+
defaultLanguage={defaultLanguage}
6870
defaultValue={defaultValue}
6971
path={fileId}
7072
options={{
7173
tabSize: 2,
7274
insertSpaces: true,
75+
minimap: { enabled: false },
7376
}}
7477
onMount={(editor: any) => {
7578
if (onMount) {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React from 'react'
2+
import styled from 'styled-components'
3+
import { Top } from 'react-spaces'
4+
import CloseIcon from 'components/CloseIcon'
5+
import { useConsole } from 'hooks/console'
6+
7+
const Header = styled(Top)`
8+
background: #2f2f2f;
9+
border-bottom: solid 1px #4a4a4d;
10+
border-top: solid 1px #4a4a4d;
11+
display: flex;
12+
padding: 0 4px;
13+
align-items: center;
14+
justify-content: space-between;
15+
color: #ffffff;
16+
`
17+
18+
const CloseButton = styled.button`
19+
border: none;
20+
background: transparent;
21+
margin-left: 10px;
22+
cursor: pointer;
23+
width: 20px;
24+
height: 20px;
25+
padding: 0;
26+
27+
& svg {
28+
fill: #888888;
29+
}
30+
&:hover svg {
31+
fill: #666666;
32+
}
33+
`
34+
35+
const ClearButton = styled.button`
36+
height: 20px;
37+
padding: 3px 0 2px;
38+
border-radius: 4px;
39+
border: solid 1px #ffffff;
40+
background-color: transparent;
41+
margin: 16px 0 6px;
42+
color: white;
43+
padding: 2px 16px;
44+
margin-left: 8px;
45+
46+
&:hover {
47+
background: #363636;
48+
}
49+
`
50+
51+
export enum BottomView {
52+
NONE,
53+
ERRORS,
54+
CONSOLE,
55+
}
56+
57+
interface BottomTitleBarProps {
58+
view: BottomView
59+
onSetView: (newView: BottomView) => void
60+
}
61+
62+
const BottomTitleBar: React.FC<BottomTitleBarProps> = ({ view, onSetView }) => {
63+
const { clear: clearConsole } = useConsole()
64+
65+
return (
66+
<Header size={40}>
67+
<div>
68+
{view === BottomView.ERRORS ? 'Errors' : 'Console'}
69+
{view === BottomView.CONSOLE && <ClearButton onClick={clearConsole}>Clear</ClearButton>}
70+
</div>
71+
72+
<CloseButton onClick={() => onSetView(BottomView.NONE)}>
73+
<CloseIcon />
74+
</CloseButton>
75+
</Header>
76+
)
77+
}
78+
79+
export default BottomTitleBar
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { useLayoutEffect, useRef } from 'react'
2+
import styled from 'styled-components'
3+
import { Fill } from 'react-spaces'
4+
import { useConsole, Line } from 'hooks/console'
5+
import { LOG_LEVEL } from '@cryptostats/sdk'
6+
7+
const ConsoleView = styled(Fill)`
8+
padding: 8px;
9+
color: #ffffff;
10+
font-size: 12px;
11+
`
12+
13+
const ConsoleLine = styled.div<{ level: string }>`
14+
font-family: monospace;
15+
white-space: pre-wrap;
16+
word-break: break-all;
17+
18+
${({ level }) => (level === LOG_LEVEL.ERROR.toString() ? 'color: red;' : '')}
19+
`
20+
21+
const Console: React.FC = () => {
22+
const { lines } = useConsole()
23+
const bottomRef = useRef<any>(null)
24+
25+
useLayoutEffect(() => {
26+
bottomRef.current?.scrollIntoView({ behavior: 'smooth' })
27+
}, [bottomRef.current, lines])
28+
29+
return (
30+
<ConsoleView scrollable={true}>
31+
{lines.map((line: Line, i: number) => (
32+
<ConsoleLine key={i} level={line.level}>
33+
{line.value}
34+
</ConsoleLine>
35+
))}
36+
<div ref={bottomRef} />
37+
</ConsoleView>
38+
)
39+
}
40+
41+
export default Console

0 commit comments

Comments
 (0)