Skip to content

Commit cb02078

Browse files
author
Frederic Lavigne
committed
Merge branch 'react' of https://github.com/IBM-Bluemix/health-blockchain into react
* 'react' of https://github.com/IBM-Bluemix/health-blockchain: #43 show and hide explorer linter #42 refactor css clean up API calls
2 parents 3fd9fce + 8ae2f69 commit cb02078

20 files changed

+576
-461
lines changed

ui-react/.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"no-constant-condition": [2, {"checkLoops": false}],
2929
"react/jsx-filename-extension": [0],
3030
"func-names": [0],
31-
"react/prefer-stateless-function": [1],
31+
"react/prefer-stateless-function": "off",
3232
"no-use-before-define": ["error", { "functions": false, "classes": true }]
3333
}
3434
}

ui-react/src/App.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ sans-serif;*/
3333
width: 100%;
3434
/* border-bottom: 2px solid #384b55;*/
3535
background: #24242c;
36-
height: 100px;
36+
height: 60px;
3737
flex-shrink: 0;
3838
}
3939

@@ -283,7 +283,7 @@ a {
283283

284284
.footer {
285285
width: 100%;
286-
height: 80px;
286+
height: 50px;
287287
background: #24242c;
288288
display: flex;
289289
flex-direction: row;

ui-react/src/App.js

+6-17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Login from './Login';
44
import Profile from './Profile/Profile';
55
import BlockExplorer from './BlockExplorer/BlockExplorer';
66
import './App.css';
7+
import API from './callAPI';
78

89
const Route = {
910
LOGIN: 'login',
@@ -16,7 +17,7 @@ class App extends Component {
1617
constructor(props) {
1718
super(props);
1819
this.state = {
19-
route: Route.LOGIN,
20+
route: Route.LOGIN
2021
};
2122
this.isLoggedIn = this.isLoggedIn.bind(this);
2223
this.isLoggedIn();
@@ -46,25 +47,13 @@ class App extends Component {
4647
}
4748

4849
isLoggedIn() {
49-
fetch('/api/users/isLoggedIn', { credentials: 'include' }).then((response) => {
50-
if (response.ok) {
51-
response.json().then(json => json.outcome === 'success' && this.setState({ route: Route.PROFILE }));
52-
return response;
53-
}
54-
this.setState({ errorMessage: 'Error calling API.' });
55-
return response;
56-
});
50+
API.getRequest('/api/users/isLoggedIn').then(json =>
51+
json.outcome === 'success' && this.setState({ route: Route.PROFILE }));
5752
}
5853

5954
logout() {
60-
fetch('/api/users/logout', { method: 'POST' }).then(response => response.json())
61-
.then((body) => {
62-
if (body.ok) {
63-
this.setState({ route: Route.LOGIN });
64-
} else {
65-
this.setState({ errorMessage: body.message });
66-
}
67-
});
55+
API.postRequest('/api/users/logout')
56+
.then(() => this.setState({ route: Route.LOGIN }));
6857
}
6958

7059
render() {

ui-react/src/BlockExplorer/Block.css

+40-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.blockExplorer {
1+
.BlockExplorerDetailView {
22
padding-left: 30px;
33
border-left-style: dotted;
44
border-color: #4D4E56;
@@ -13,16 +13,12 @@
1313
display: flex;
1414
flex-direction: column;
1515
padding-top: 10px;
16-
1716
animation-name: slideDown;
1817
-webkit-animation-name: slideDown;
19-
2018
animation-duration: 1s;
2119
-webkit-animation-duration: 1s;
22-
2320
animation-timing-function: ease;
2421
-webkit-animation-timing-function: ease;
25-
2622
visibility: visible !important;
2723

2824
}
@@ -137,3 +133,42 @@
137133
width: 2px;
138134
background: white;
139135
}
136+
137+
.blockSmall {
138+
width: 21px;
139+
height: 21px;
140+
border-radius: 5px;
141+
border: 1px solid #393941;
142+
background: linear-gradient(135deg, #1c1c23 0%, #393941 50%, #1c1c23 100%);
143+
cursor: pointer;
144+
animation-name: slideDown;
145+
-webkit-animation-name: slideDown;
146+
animation-duration: 1s;
147+
-webkit-animation-duration: 1s;
148+
animation-timing-function: ease;
149+
-webkit-animation-timing-function: ease;
150+
visibility: visible !important;
151+
}
152+
153+
.blockSmallLink {
154+
height: 10px;
155+
width: 2px;
156+
background: white;
157+
margin: auto;
158+
}
159+
160+
.minimizeSign {
161+
height: 2px;
162+
width: 10px;
163+
background: #393941;
164+
cursor: pointer;
165+
}
166+
167+
.minimizeButton {
168+
cursor: pointer;
169+
padding:10px;
170+
border: solid;
171+
border-width: 1px;
172+
width: 12px;
173+
border-color: #393941;
174+
}

ui-react/src/BlockExplorer/BlockExplorer.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import React, { Component } from 'react';
22
import './Block.css';
3-
import Block from './Block';
3+
import BlockExplorerPreview from './BlockExplorerPreview';
4+
import BlockExplorerDetailView from './BlockExplorerDetailView';
45

56
class BlockExplorer extends Component {
67

78
constructor(props) {
89
super(props);
910
this.state = {
1011
blocks: [],
12+
preview: true
1113
};
1214
this.getBlocks = this.getBlocks.bind(this);
1315
this.getBlocks();
@@ -25,10 +27,18 @@ class BlockExplorer extends Component {
2527

2628
render() {
2729
return (
28-
<div className="blockExplorer">
29-
{this.state.blocks.map((block, index) => (
30-
<Block block={block} />
31-
))}
30+
<div>
31+
{ this.state.preview ?
32+
<BlockExplorerPreview
33+
blocks={this.state.blocks}
34+
onExpand={() => this.setState({ preview: false })}
35+
/>
36+
:
37+
<BlockExplorerDetailView
38+
blocks={this.state.blocks}
39+
onMin={() => this.setState({ preview: true })}
40+
/>
41+
}
3242
</div>
3343
);
3444
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
3+
import './Block.css';
4+
import Block from './Block';
5+
6+
class BlockExplorerDetailView extends Component {
7+
8+
9+
render() {
10+
return (
11+
<div className="BlockExplorerDetailView">
12+
<div className="minimizeButton" role="presentation" onClick={this.props.onMin}>
13+
<div className="minimizeSign" />
14+
</div>
15+
{this.props.blocks.map(block => (
16+
<Block block={block} key={block.id} />
17+
))}
18+
</div>
19+
);
20+
}
21+
}
22+
23+
BlockExplorerDetailView.propTypes = {
24+
blocks: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
25+
onMin: PropTypes.func.isRequired
26+
};
27+
28+
export default BlockExplorerDetailView;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
3+
import './Block.css';
4+
5+
class BlockExplorerPreview extends Component {
6+
7+
8+
render() {
9+
return (
10+
<div role="presentation" onClick={this.props.onExpand}>
11+
{this.props.blocks.map(() => (
12+
<div>
13+
<div className="blockSmallLink" />
14+
<div className="blockSmall" />
15+
</div>
16+
))}
17+
</div>
18+
);
19+
}
20+
}
21+
22+
BlockExplorerPreview.propTypes = {
23+
blocks: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
24+
onExpand: PropTypes.func.isRequired
25+
};
26+
27+
export default BlockExplorerPreview;

ui-react/src/Login.js

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React, { Component } from 'react';
2-
import './Phone/Phone.css';
2+
import PropTypes from 'prop-types';
3+
import './Profile/Profile.css';
4+
import API from './callAPI';
5+
36

47
class Login extends Component {
58

@@ -30,20 +33,9 @@ class Login extends Component {
3033
}
3134

3235
handleSubmit(event) {
33-
event.preventDefault();
34-
36+
event.preventDefault(); // Don't submit the form. We will call the API ourself.
3537
this.setState({ errorMessage: '' });
36-
fetch(this.props.isLogin ? '/api/users/login' : '/api/users/signup', {
37-
headers: {
38-
Accept: 'application/json',
39-
'Content-Type': 'application/json'
40-
},
41-
method: 'POST',
42-
credentials: 'include',
43-
body: JSON.stringify({
44-
email: this.state.email, password: this.state.password
45-
})
46-
}).then(response => response.json())
38+
API.loginOrSignup(this.props.isLogin ? 'login' : 'signup', this.state.email, this.state.password)
4739
.then((body) => {
4840
if (body.ok) {
4941
this.props.onSubmit();
@@ -63,7 +55,9 @@ class Login extends Component {
6355
<img src="images/username.svg" className="icon" alt="user" />
6456
<input
6557
id="email"
66-
className="logininput" type="text" name="email"
58+
className="logininput"
59+
type="text"
60+
name="email"
6761
placeholder="E-mail address"
6862
onChange={this.handleInputChange}
6963
value={this.state.email}
@@ -84,7 +78,11 @@ class Login extends Component {
8478
<button className="loginbutton" onClick={this.submit}>{ this.props.isLogin ? 'Login' : 'Sign Up' }</button>
8579
</div>
8680
</form>
87-
<div className="loginnew" onClick={this.navigate}>
81+
<div
82+
className="loginnew"
83+
onClick={this.navigate}
84+
role="presentation"
85+
>
8886
{ this.props.isLogin ? 'Add a new account' : 'Existing account?' }
8987
</div>
9088
<div className="messagearea" id="messagearea">
@@ -97,4 +95,9 @@ class Login extends Component {
9795
}
9896
}
9997

98+
Login.propTypes = {
99+
isLogin: PropTypes.string.isRequired,
100+
onNavigate: PropTypes.func.isRequired,
101+
onSubmit: PropTypes.func.isRequired
102+
};
100103
export default Login;

0 commit comments

Comments
 (0)