Skip to content

Commit dfc1800

Browse files
committed
new feature version dropdown
1 parent 3816e9c commit dfc1800

File tree

14 files changed

+374
-86
lines changed

14 files changed

+374
-86
lines changed

src/client/App.js

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Form from './components/Form/Form';
99
import Tab from './components/Tab/Tab';
1010
import MessageComp from './components/MessageComp/MessageComp';
1111
import SettingsBar from './components/SettingsBar/SettingsBar';
12+
import Dropdown from './components/Dropdown/Dropdown';
13+
import Version from './components/Version/Version';
1214

1315
import styles from './styles/App.scss';
1416
import fade from './styles/transitions/fade.scss';
@@ -40,11 +42,11 @@ class App extends React.Component {
4042
parameter: '',
4143
fetchRequestStatus: undefined,
4244
contracts: [],
43-
settingsVisible: false,
4445
}
46+
}
4547

46-
this.handleMenuItemIconClick = this.handleMenuItemIconClick.bind(this);
47-
this.handleOutsideClick = this.handleOutsideClick.bind(this);
48+
componentDidMount() {
49+
this.fetchData('http://localhost:9090/solc/list');
4850
}
4951

5052
handleMenuItemIconClick(index) {
@@ -74,13 +76,14 @@ class App extends React.Component {
7476
settingsVisible: false,
7577
});
7678

77-
this.fetchData(parameter);
79+
const url = `http://localhost:9090/files/${encodeURIComponent(parameter) || ' '}?extension=sol`;
80+
this.fetchData(url);
7881
}
7982

80-
fetchData(parameter) {
83+
fetchData(url) {
8184
this.handleRequestPending();
8285

83-
fetch(`http://localhost:9090/files/${encodeURIComponent(parameter) || ' '}?extension=sol`)
86+
fetch(url)
8487
.then(res => res.json())
8588
.then(data => {
8689
data.error
@@ -96,10 +99,18 @@ class App extends React.Component {
9699
}
97100

98101
handleRequestSuccess(response) {
99-
this.setState({
100-
fetchRequestStatus: 'success',
101-
contracts: response,
102-
});
102+
103+
if(response.some(item => item.version)) {
104+
this.setState({
105+
fetchRequestStatus: 'success',
106+
versions: response,
107+
});
108+
} else {
109+
this.setState({
110+
fetchRequestStatus: 'success',
111+
contracts: response,
112+
});
113+
}
103114

104115
this.props.loadingMessageOff();
105116
}
@@ -110,50 +121,16 @@ class App extends React.Component {
110121
this.props.getErrorMessage(message);
111122
}
112123

113-
handleSettingsiconClick() {
114-
this.toggleOutsideClick();
115-
116-
this.setState(prevState => ({
117-
settingsVisible: !prevState.settingsVisible,
118-
}))
119-
}
120-
121-
handleSettingsSaveButtonClick() {
122-
this.toggleOutsideClick();
123-
124-
this.setState({
125-
settingsVisible: false,
126-
});
127-
}
128-
129-
toggleOutsideClick() {
130-
if (!this.state.settingsVisible) {
131-
document.addEventListener('click', this.handleOutsideClick);
132-
} else {
133-
document.removeEventListener('click', this.handleOutsideClick);
134-
}
135-
}
136-
137-
handleOutsideClick(e) {
138-
if (this.node.contains(e.target)) {
139-
return;
140-
}
141-
142-
document.removeEventListener('click', this.handleOutsideClick);
143-
144-
this.setState({
145-
settingsVisible: false,
146-
});
147-
}
148-
149124
render() {
150125

151-
const { fetchRequestStatus, contracts, settingsVisible, configPlaceholder } = this.state;
126+
const { fetchRequestStatus, contracts, versions } = this.state;
152127
const { children, showLoadingMessage, showErrorMessage, errorMessage } = this.props;
153128

154129
return (
155130
<div className={styles['app']}>
156-
<TopNavBar onIconClick={() => this.handleSettingsiconClick()}>
131+
<TopNavBar
132+
fetchRequestStatus={fetchRequestStatus}
133+
versions={versions}>
157134
<Form
158135
submitButton={true}
159136
inputTypes={[{ name: 'contractsPath', placeholder: 'Insert contracts path'}]}
@@ -163,12 +140,6 @@ class App extends React.Component {
163140
onInputKeyUp={() => this.handleInputSubmit()}
164141
/>
165142
</TopNavBar>
166-
<div ref={node => { this.node = node; }}>
167-
<SettingsBar
168-
active={!!settingsVisible}
169-
onSaveButtonClick={() => this.handleSettingsSaveButtonClick()}
170-
/>
171-
</div>
172143
<CSSTransitionGroup
173144
transitionName={fade}
174145
transitionAppear={true}
@@ -202,7 +173,7 @@ class App extends React.Component {
202173
trnasitionEnterTimeout={300}
203174
transitionLeaveTimeout={300}
204175
>
205-
{fetchRequestStatus === 'success' &&
176+
{fetchRequestStatus === 'success' && contracts.length &&
206177
<Tab data={contracts} onMenuItemIconClick={this.handleMenuItemIconClick}>
207178
{children}
208179
</Tab>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import classnames from 'classnames/bind';
3+
4+
import styles from './Dropdown.scss';
5+
6+
const cx = classnames.bind(styles);
7+
8+
const Dropdown = ({ active, children, versions, settings, onClick }) => {
9+
10+
const dropdownClasses = cx({
11+
'dropdown': true,
12+
'dropdown--active': !!active,
13+
'dropdown--versions': !!versions,
14+
'dropdown--settings': !!settings
15+
});
16+
17+
return (
18+
<div className={dropdownClasses} onClick={onClick}>
19+
{ children }
20+
</div>
21+
)
22+
}
23+
24+
export default Dropdown;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.dropdown {
2+
width: 100%;
3+
position: absolute;
4+
right: 0;
5+
top: -262px;
6+
background: $color-dark-grey;
7+
z-index: -3;
8+
opacity: 0;
9+
padding: 20px 10px 20px 10px;
10+
transition: top 0.3s, opacity 0.4s;
11+
12+
&--settings {
13+
width: 300px;
14+
}
15+
16+
&--active {
17+
opacity: 1;
18+
top: 100%;
19+
}
20+
}

src/client/components/Icon/Icon.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import Cogs from './SVG/cogs.svg';
1111

1212
import styles from './Icon.scss';
1313

14-
const Icon = ({ iconName }) => {
14+
const Icon = ({ iconName, onClick }) => {
1515

1616
const icons = { CircleLeft, CircleRight, Menu, Cross, Spinner, Cogs };
1717

1818
return (
19-
<div className={styles['icon']}>
19+
<div onClick={onClick} className={styles['icon']}>
2020
<SVGInline svg={icons[iconName]} />
2121
</div>
2222
);

src/client/components/SettingsBar/SettingsBar.scss

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
.settings-bar {
2-
width: 50%;
2+
width: 100%;
33
background: $color-dark-grey;
4-
position: absolute;
54
padding: 0 5px 10px 5px;
6-
top: -262px;
7-
right: 0;
8-
transition: top 0.3s;
9-
z-index: 2;
10-
11-
&--active {
12-
top: 29px;
13-
}
145

156
&__buttons {
167
padding: 5px 10px;

src/client/components/Store/Actions.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SELECT_EDITOR_LINES, SHOW_EVM_STATE,
22
SHOW_LOADING_MESSAGE, HIDE_LOADING_MESSAGE,
33
SHOW_ERROR_MESSAGE, HIDE_ERROR_MESSAGE,
4-
HIDE_EVM_STATE, GET_ERROR_MESSAGE } from './Constants.js';
4+
HIDE_EVM_STATE, GET_ERROR_MESSAGE, GET_VERSION_NUM } from './Constants.js';
55

66
export function selectEditorLines(lines) {
77
return {
@@ -58,3 +58,10 @@ export function getErrorMessage(message) {
5858
message,
5959
}
6060
}
61+
62+
export function getVersionNumber(version) {
63+
return {
64+
type: GET_VERSION_NUM,
65+
version,
66+
}
67+
}

src/client/components/Store/Constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const GET_ERROR_MESSAGE = 'GET_ERROR_MESSAGE';
99
export const GET_HOST = 'GET_HOST';
1010
export const GET_PROTOCOL = 'GET_PROTOCOL';
1111
export const GET_USERNAME = 'GET_USERNAME';
12-
export const GET_PASSWORD = 'GET_PASSWORD';
12+
export const GET_PASSWORD = 'GET_PASSWORD';
13+
export const GET_VERSION_NUM = 'GET_VERSION_NUM';

src/client/components/Store/Reducers/Reducers.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SELECT_EDITOR_LINES, SHOW_EVM_STATE, SHOW_LOADING_MESSAGE,
22
HIDE_LOADING_MESSAGE, SHOW_ERROR_MESSAGE, HIDE_ERROR_MESSAGE,
3-
HIDE_EVM_STATE, GET_ERROR_MESSAGE } from '../Constants.js';
3+
HIDE_EVM_STATE, GET_ERROR_MESSAGE, GET_VERSION_NUM } from '../Constants.js';
44

55

66
export function selectLines(state = [0, 0], action) {
@@ -33,4 +33,11 @@ export function toggleErrorMessage(state = false, action) {
3333
case GET_ERROR_MESSAGE: return action.message;
3434
default: return state;
3535
}
36+
}
37+
38+
export function displayVersionNumber(state = '', action) {
39+
switch(action.type) {
40+
case GET_VERSION_NUM: return action.version;
41+
default: return state;
42+
}
3643
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { combineReducers } from 'redux';
22

3-
import { selectLines, selectEVMState, toggleLoadingMessage, toggleErrorMessage } from './Reducers.js';
3+
import { selectLines, selectEVMState, toggleLoadingMessage, toggleErrorMessage, displayVersionNumber } from './Reducers.js';
44

55
export default combineReducers({
66
selectLines,
77
selectEVMState,
88
toggleLoadingMessage,
99
toggleErrorMessage,
10+
displayVersionNumber
1011
});

0 commit comments

Comments
 (0)