Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
6ee39a5c
Commit
6ee39a5c
authored
Mar 13, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
select file in the tree
parent
ecb17934
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
13 deletions
+44
-13
CodeEditor.tsx
ui/shared/monaco/CodeEditor.tsx
+4
-7
CodeEditorFileExplorer.tsx
ui/shared/monaco/CodeEditorFileExplorer.tsx
+12
-2
CodeEditorFileTree.tsx
ui/shared/monaco/CodeEditorFileTree.tsx
+6
-4
CodeEditorSideBar.tsx
ui/shared/monaco/CodeEditorSideBar.tsx
+22
-0
No files found.
ui/shared/monaco/CodeEditor.tsx
View file @
6ee39a5c
...
...
@@ -5,7 +5,7 @@ import React from 'react';
import
type
{
File
}
from
'
./types
'
;
import
CodeEditor
FileExplorer
from
'
./CodeEditorFileExplore
r
'
;
import
CodeEditor
SideBar
from
'
./CodeEditorSideBa
r
'
;
import
*
as
themes
from
'
./utils/themes
'
;
export
type
Monaco
=
typeof
monaco
;
...
...
@@ -16,7 +16,7 @@ interface Props {
const
CodeEditor
=
({
data
}:
Props
)
=>
{
const
instance
=
React
.
useRef
<
Monaco
>
();
const
[
index
]
=
React
.
useState
(
0
);
const
[
index
,
setIndex
]
=
React
.
useState
(
0
);
const
{
colorMode
}
=
useColorMode
();
...
...
@@ -35,10 +35,9 @@ const CodeEditor = ({ data }: Props) => {
},
[
]);
return
(
<
Flex
overflow=
"hidden"
borderRadius=
"md"
>
<
Flex
overflow=
"hidden"
borderRadius=
"md"
height=
"500px"
>
<
Box
flexGrow=
{
1
}
>
<
MonacoEditor
height=
"500px"
language=
"sol"
path=
{
data
[
index
].
file_path
}
defaultValue=
{
data
[
index
].
source_code
}
...
...
@@ -46,9 +45,7 @@ const CodeEditor = ({ data }: Props) => {
onMount=
{
handleEditorDidMount
}
/>
</
Box
>
<
Box
w=
"250px"
flexShrink=
{
0
}
bgColor=
"lightpink"
fontSize=
"sm"
>
<
CodeEditorFileExplorer
data=
{
data
}
/>
</
Box
>
<
CodeEditorSideBar
data=
{
data
}
onFileSelect=
{
setIndex
}
/>
</
Flex
>
);
};
...
...
ui/shared/monaco/CodeEditorFileExplorer.tsx
View file @
6ee39a5c
...
...
@@ -8,16 +8,26 @@ import composeFileTree from './utils/composeFileTree';
interface
Props
{
data
:
Array
<
File
>
;
onFileSelect
:
(
index
:
number
)
=>
void
;
}
const
CodeEditorFileExplorer
=
({
data
}:
Props
)
=>
{
const
CodeEditorFileExplorer
=
({
data
,
onFileSelect
}:
Props
)
=>
{
const
tree
=
React
.
useMemo
(()
=>
{
return
composeFileTree
(
data
);
},
[
data
]);
const
handleFileClick
=
React
.
useCallback
((
event
:
React
.
MouseEvent
)
=>
{
const
filePath
=
(
event
.
currentTarget
as
HTMLDivElement
).
getAttribute
(
'
data-file-path
'
);
const
fileIndex
=
data
.
findIndex
((
item
)
=>
item
.
file_path
===
filePath
);
if
(
fileIndex
>
-
1
)
{
onFileSelect
(
fileIndex
);
}
},
[
data
,
onFileSelect
]);
return
(
<
Box
>
<
CodeEditorFileTree
tree=
{
tree
}
/>
<
CodeEditorFileTree
tree=
{
tree
}
onItemClick=
{
handleFileClick
}
/>
</
Box
>
);
};
...
...
ui/shared/monaco/CodeEditorFileTree.tsx
View file @
6ee39a5c
...
...
@@ -7,9 +7,10 @@ import type { FileTree } from './types';
interface
Props
{
tree
:
FileTree
;
level
?:
number
;
onItemClick
:
(
event
:
React
.
MouseEvent
)
=>
void
;
}
const
CodeEditorFileTree
=
({
tree
,
level
=
0
}:
Props
)
=>
{
const
CodeEditorFileTree
=
({
tree
,
level
=
0
,
onItemClick
}:
Props
)
=>
{
const
itemProps
:
ChakraProps
=
{
ml
:
level
?
4
:
0
,
borderWidth
:
'
0px
'
,
...
...
@@ -18,8 +19,9 @@ const CodeEditorFileTree = ({ tree, level = 0 }: Props) => {
},
cursor
:
'
pointer
'
,
};
return
(
<
Accordion
allowMultiple
>
<
Accordion
allowMultiple
defaultIndex=
{
tree
.
map
((
item
,
index
)
=>
index
)
}
reduceMotion
>
{
tree
.
map
((
leaf
,
index
)
=>
{
if
(
'
children
'
in
leaf
)
{
...
...
@@ -30,14 +32,14 @@ const CodeEditorFileTree = ({ tree, level = 0 }: Props) => {
<
span
>
{
leaf
.
name
}
</
span
>
</
AccordionButton
>
<
AccordionPanel
p=
{
0
}
>
<
CodeEditorFileTree
tree=
{
leaf
.
children
}
level=
{
level
+
1
}
/>
<
CodeEditorFileTree
tree=
{
leaf
.
children
}
level=
{
level
+
1
}
onItemClick=
{
onItemClick
}
/>
</
AccordionPanel
>
</
AccordionItem
>
);
}
return
(
<
AccordionItem
key=
{
index
}
{
...
itemProps
}
>
<
AccordionItem
key=
{
index
}
{
...
itemProps
}
onClick=
{
onItemClick
}
data
-
file
-
path=
{
leaf
.
file_path
}
>
{
leaf
.
name
}
</
AccordionItem
>
);
...
...
ui/shared/monaco/CodeEditorSideBar.tsx
0 → 100644
View file @
6ee39a5c
import
{
Box
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
type
{
File
}
from
'
./types
'
;
import
CodeEditorFileExplorer
from
'
./CodeEditorFileExplorer
'
;
interface
Props
{
data
:
Array
<
File
>
;
onFileSelect
:
(
index
:
number
)
=>
void
;
}
const
CodeEditorSideBar
=
({
onFileSelect
,
data
}:
Props
)
=>
{
return
(
<
Box
w=
"250px"
flexShrink=
{
0
}
bgColor=
"lightpink"
fontSize=
"sm"
overflowY=
"scroll"
>
<
Box
fontFamily=
"heading"
pl=
{
3
}
letterSpacing=
{
0.5
}
fontWeight=
{
600
}
>
EXPLORER
</
Box
>
<
CodeEditorFileExplorer
data=
{
data
}
onFileSelect=
{
onFileSelect
}
/>
</
Box
>
);
};
export
default
React
.
memo
(
CodeEditorSideBar
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment