Max Red - created activity-list component [skip ci]

This commit is contained in:
ivan 2017-01-05 16:10:38 -03:00
parent 53aa8cc7f6
commit e0b10f5cae
4 changed files with 98 additions and 65 deletions

View File

@ -0,0 +1,94 @@
import React from 'react';
import API from 'lib-app/api-call';
import i18n from 'lib-app/i18n';
import ActivityRow from 'app-components/activity-row';
import SubmitButton from 'core-components/submit-button';
class ActivityList extends React.Component {
static propTypes = {
mode: React.PropTypes.oneOf(['staff', 'system'])
};
static childContextTypes = {
loading: React.PropTypes.bool
};
getChildContext() {
return {
loading: this.state.loading
};
}
state = {
activities: [],
page: 1,
limit: false,
loading: false
};
componentDidMount() {
this.retrieveNextPage();
}
render() {
if (this.props.mode === 'staff') {
return (
<div>
{this.state.activities.map(this.renderRow.bind(this))}
{(!this.state.limit) ? this.renderButton() : null}
</div>
);
}
else {
return (
<div>
{this.state.activities.map(this.renderRow.bind(this))}
{(!this.state.limit) ? this.renderButton() : null}
</div>
);
}
}
renderButton() {
return (
<SubmitButton type="secondary" onClick={this.retrieveNextPage.bind(this)}>
{i18n('LOAD_MORE')}
</SubmitButton>
);
}
renderRow(row) {
return (
<ActivityRow {...row} />
);
}
retrieveNextPage() {
this.setState({loading: true});
API.call({
path: '/staff/last-events',
data: {
page: this.state.page
}
}).then(this.onRetrieveSuccess.bind(this)).catch(this.onRetrieveFail.bind(this))
}
onRetrieveSuccess(result) {
this.setState({
activities: this.state.activities.concat(result.data),
page: this.state.page + 1,
limit: (result.data.length !== 10),
loading: false
});
}
onRetrieveFail() {
}
}
export default ActivityList;

View File

@ -1,60 +1,23 @@
import React from 'react';
import API from 'lib-app/api-call';
import i18n from 'lib-app/i18n';
import ActivityRow from 'app-components/activity-row';
import Header from 'core-components/header';
import SubmitButton from 'core-components/submit-button';
import Menu from 'core-components/menu';
import ActivityList from 'app/admin/panel/dashboard/activity-list';
class AdminPanelActivity extends React.Component {
static childContextTypes = {
loading: React.PropTypes.bool
};
getChildContext() {
return {
loading: this.state.loading
};
}
state = {
activities: [],
page: 1,
limit: false,
loading: false
};
componentDidMount() {
this.retrieveNextPage();
}
render() {
return (
<div className="admin-panel-activity">
<Header title={i18n('LAST_ACTIVITY')} />
<Menu {...this.getMenuProps()} />
{this.state.activities.map(this.renderRow.bind(this))}
{(!this.state.limit) ? this.renderButton() : null}
<ActivityList />
</div>
);
}
renderButton() {
return (
<SubmitButton type="secondary" onClick={this.retrieveNextPage.bind(this)}>
{i18n('LOAD_MORE')}
</SubmitButton>
);
}
renderRow(row) {
return (
<ActivityRow {...row} />
);
}
getMenuProps() {
return {
@ -72,30 +35,6 @@ class AdminPanelActivity extends React.Component {
]
}
}
retrieveNextPage() {
this.setState({loading: true});
API.call({
path: '/staff/last-events',
data: {
page: this.state.page
}
}).then(this.onRetrieveSuccess.bind(this)).catch(this.onRetrieveFail.bind(this))
}
onRetrieveSuccess(result) {
this.setState({
activities: this.state.activities.concat(result.data),
page: this.state.page + 1,
limit: (result.data.length !== 10),
loading: false
});
}
onRetrieveFail() {
}
}
export default AdminPanelActivity;

View File

@ -1060,7 +1060,7 @@ module.exports = [
},
{
path: '/staff/last-events',
time: 430,
time: 30,
response: function(data) {
if(data.page > 5) {