mirror of
https://github.com/wassname/talk.git
synced 2026-07-23 13:10:20 +08:00
remove query from Dashboard component per belen's advice
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
import React from 'react';
|
||||
import styles from './Dashboard.css';
|
||||
import {graphql, compose} from 'react-apollo';
|
||||
import {compose} from 'react-apollo';
|
||||
import {connect} from 'react-redux';
|
||||
import {getMetrics} from 'coral-admin/src/graphql/queries';
|
||||
import FlagWidget from './FlagWidget';
|
||||
import LikeWidget from './LikeWidget';
|
||||
import METRICS from 'coral-admin/src/graphql/queries/metrics.graphql';
|
||||
|
||||
// import MostLikedCommentsWidget from './MostLikedCommentsWidget';
|
||||
import {showBanUserDialog, hideBanUserDialog} from 'coral-admin/src/actions/moderation';
|
||||
import {banUser, setCommentStatus} from 'coral-admin/src/graphql/mutations';
|
||||
|
||||
import {Spinner} from 'coral-ui';
|
||||
|
||||
class Dashboard extends React.Component {
|
||||
@@ -19,49 +17,17 @@ class Dashboard extends React.Component {
|
||||
return <Spinner />;
|
||||
}
|
||||
|
||||
const {data: {assetsByLike, assetsByFlag/* , mostLikedComments*/}} = this.props;
|
||||
|
||||
// const {moderation, settings} = this.props;
|
||||
const {data: {assetsByLike, assetsByFlag}} = this.props;
|
||||
|
||||
return (
|
||||
<div className={styles.Dashboard}>
|
||||
<FlagWidget assets={assetsByFlag} />
|
||||
{/*
|
||||
<MostLikedCommentsWidget
|
||||
comments={mostLikedComments}
|
||||
moderation={moderation}
|
||||
settings={settings}
|
||||
acceptComment={this.props.acceptComment}
|
||||
rejectComment={this.props.rejectComment}
|
||||
handleBanUser={this.props.banUser}
|
||||
showBanUserDialog={this.props.showBanUserDialog}
|
||||
hideBanUserDialog={this.props.hideBanUserDialog} />
|
||||
*/}
|
||||
<LikeWidget assets={assetsByLike} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let then = new Date();
|
||||
then.setMinutes(then.getMinutes() - 5);
|
||||
then = then.toISOString();
|
||||
const now = new Date().toISOString();
|
||||
|
||||
const getMetrics = graphql(METRICS, {
|
||||
options: () => {
|
||||
|
||||
return {
|
||||
variables: {
|
||||
from: then,
|
||||
to: now
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
const DashboardWithData = compose(getMetrics, setCommentStatus, banUser)(Dashboard);
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
settings: state.settings.toJS(),
|
||||
@@ -74,4 +40,7 @@ const mapDispatchToProps = dispatch => ({
|
||||
hideBanUserDialog: () => dispatch(hideBanUserDialog(false))
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(DashboardWithData);
|
||||
export default compose(
|
||||
connect(mapStateToProps, mapDispatchToProps),
|
||||
getMetrics
|
||||
)(Dashboard);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {graphql} from 'react-apollo';
|
||||
|
||||
import MOD_QUEUE_QUERY from './modQueueQuery.graphql';
|
||||
import METRICS from './metrics.graphql';
|
||||
|
||||
export const modQueueQuery = graphql(MOD_QUEUE_QUERY, {
|
||||
options: ({params: {id = null}}) => {
|
||||
@@ -17,6 +18,18 @@ export const modQueueQuery = graphql(MOD_QUEUE_QUERY, {
|
||||
})
|
||||
});
|
||||
|
||||
export const getMetrics = graphql(METRICS, {
|
||||
options: ({settings: {dashboardWindowStart, dashboardWindowEnd}}) => {
|
||||
|
||||
return {
|
||||
variables: {
|
||||
from: dashboardWindowStart,
|
||||
to: dashboardWindowEnd
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
export const modQueueResort = (id, fetchMore) => (sort) => {
|
||||
return fetchMore({
|
||||
query: MOD_QUEUE_QUERY,
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
import {Map, List} from 'immutable';
|
||||
import * as actions from '../actions/settings';
|
||||
|
||||
// this is initialized here because
|
||||
// currently you have to reload the dashboard to get new stats
|
||||
// cleaner updates are planned in the future.
|
||||
const DASHBOARD_WINDOW_MINUTES = 5;
|
||||
let then = new Date();
|
||||
then.setMinutes(then.getMinutes() - DASHBOARD_WINDOW_MINUTES);
|
||||
|
||||
const initialState = Map({
|
||||
wordlist: Map({
|
||||
banned: List(),
|
||||
suspect: List()
|
||||
}),
|
||||
dashboardWindowStart: then.toISOString(),
|
||||
dashboardWindowEnd: new Date().toISOString(),
|
||||
domains: Map({
|
||||
whitelist: List()
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user