Skip to content

Commit eabbe63

Browse files
authored
Merge pull request #126 from corgicode/feature/loading-compo
Closes #83 - Creates a <loading> component that displays while waiting for data as a generic way
2 parents 2aaf84a + 53a4c79 commit eabbe63

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

src/components/loading/Large.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
3+
import TintedHeader from '../../components/misc/TintedHeader';
4+
5+
class LoadingLarge extends Component {
6+
static propTypes = {
7+
children: PropTypes.oneOfType([
8+
PropTypes.node,
9+
PropTypes.arrayOf(PropTypes.node),
10+
]).isRequired,
11+
loading: PropTypes.bool,
12+
data: PropTypes.any,
13+
title: PropTypes.string,
14+
minimun: PropTypes.number,
15+
};
16+
17+
static defaultProps = {
18+
title: 'Loading...',
19+
minimun: 800,
20+
}
21+
22+
constructor(props) {
23+
super(props);
24+
this.state = {
25+
minimunElapsed: false,
26+
};
27+
}
28+
29+
componentDidMount() {
30+
setTimeout(() => {
31+
this.setState({
32+
minimunElapsed: true,
33+
});
34+
}, this.props.minimun);
35+
}
36+
37+
render() {
38+
return(
39+
<div>
40+
{
41+
(this.state.minimunElapsed && (!this.props.loading || this.props.data)) ?
42+
this.props.children :
43+
<TintedHeader title={ this.props.title } />
44+
}
45+
</div>
46+
);
47+
}
48+
}
49+
50+
export default LoadingLarge;

src/containers/profile/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { bindActionCreators } from 'redux';
88
import E404 from '../404/';
99
import ProfileComponent from '../../components/profile';
1010
import _get from 'lodash/get';
11+
import LoadingLarge from '../../components/loading/Large';
1112

1213
class Profile extends React.Component {
1314
static propTypes = {
@@ -37,12 +38,14 @@ class Profile extends React.Component {
3738
}
3839

3940
render() {
40-
const { profile, self, submits } = this.props;
41+
const { profile, self, submits, username } = this.props;
42+
4143
return(
42-
<div>
43-
{!this.state.loading && this.props.profile && <ProfileComponent profile={profile} self={self} submits={ submits }/>}
44-
{!this.state.loading && !this.props.profile && <E404 />}
45-
</div>);
44+
<LoadingLarge loading={ this.state.loading } title={username ? `Loading profile for ${username}` : '' }>
45+
{this.props.profile && <ProfileComponent profile={profile} self={self} submits={ submits }/>}
46+
{!this.props.profile && <E404 />}
47+
</LoadingLarge>
48+
);
4649
}
4750
}
4851

0 commit comments

Comments
 (0)