Skip to content

Commit 32b4708

Browse files
authored
Merge pull request #6726 from topcoder-platform/timeline-wall-api-issues-18
fix: approvals number should increase automatically
2 parents 394fcf9 + bb083c5 commit 32b4708

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

__tests__/shared/components/tc-communities/__snapshots__/JoinCommunity.jsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ exports[`Matches shallow shapshot 2`] = `
6565
Joining...
6666
</span>
6767
<ThemedLoadingIndicator
68+
className=""
6869
composeAdhocTheme="deeply"
6970
composeContextTheme="softly"
7071
mapThemrProps={[Function]}

config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,5 +467,6 @@ module.exports = {
467467
TIMELINE: {
468468
REJECTION_EVENT_REASONS: ['Duplicate Event', 'Violates the Topcoder terms', 'Inaccurate or Invalid'],
469469
ALLOWED_FILETYPES: ['image/jpeg', 'image/png', 'video/mp4', 'video/x-msvideo', 'video/webm'],
470+
FETCHING_PENDING_APPROVAL_EVENTS_INTERVAL: 5 * 60 * 1000, // 5 minutes
470471
},
471472
};

src/shared/components/LoadingIndicator/index.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
import PT from 'prop-types';
99
import React from 'react';
1010
import { themr } from 'react-css-super-themr';
11+
import cn from 'classnames';
1112
import style from './styles.scss';
1213

13-
const LoadingIndicator = ({ theme }) => (
14+
const LoadingIndicator = ({ theme, className }) => (
1415
<svg
15-
className={theme.container}
16+
className={cn(theme.container, className)}
1617
viewBox="0 0 64 64"
1718
>
1819
<circle
@@ -32,8 +33,13 @@ const LoadingIndicator = ({ theme }) => (
3233
</svg>
3334
);
3435

36+
LoadingIndicator.defaultProps = {
37+
className: '',
38+
};
39+
3540
LoadingIndicator.propTypes = {
3641
theme: PT.shape().isRequired,
42+
className: PT.string,
3743
};
3844

3945
export default themr('LoadingIndicator', style)(LoadingIndicator);

src/shared/containers/timeline-wall/index.jsx

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import React, { useState, useEffect, useMemo } from 'react';
1+
import React, {
2+
useState, useEffect, useRef, useMemo,
3+
} from 'react';
24
import PT from 'prop-types';
35
import { connect } from 'react-redux';
46
import TopBanner from 'assets/images/timeline-wall/top-banner.png';
@@ -10,15 +12,19 @@ import cn from 'classnames';
1012
import moment from 'moment';
1113
import { useMediaQuery } from 'react-responsive';
1214
import _ from 'lodash';
15+
import { config } from 'topcoder-react-utils';
1316
import timelineActions from 'actions/timelineWall';
1417
import LoadingIndicator from 'components/LoadingIndicator';
1518
import TimelineEvents from './timeline-events';
1619
import PendingApprovals from './pending-approvals';
1720

1821
import './styles.scss';
1922

23+
24+
const FETCHING_PENDING_APPROVAL_EVENTS_INTERVAL = _.get(config, 'TIMELINE.FETCHING_PENDING_APPROVAL_EVENTS_INTERVAL', 0);
2025
function TimelineWallContainer(props) {
2126
const [tab, setTab] = useState(0);
27+
const fetchingApprovalsInterval = useRef(null);
2228
const [showRightFilterMobile, setShowRightFilterMobile] = useState(false);
2329
const [selectedFilterValue, setSelectedFilterValue] = useState({
2430
year: 0,
@@ -37,6 +43,7 @@ function TimelineWallContainer(props) {
3743
getAvatar,
3844
userAvatars,
3945
pendingApprovals,
46+
loadingApprovals,
4047
uploading,
4148
uploadResult,
4249
} = props;
@@ -56,9 +63,25 @@ function TimelineWallContainer(props) {
5663
}, []);
5764

5865
useEffect(() => {
59-
if (authToken && isAdmin && !pendingApprovals.length) {
66+
if (fetchingApprovalsInterval.current) {
67+
clearInterval(fetchingApprovalsInterval.current);
68+
fetchingApprovalsInterval.current = null;
69+
}
70+
if (authToken && isAdmin) {
6071
getPendingApprovals(authToken);
72+
if (FETCHING_PENDING_APPROVAL_EVENTS_INTERVAL) {
73+
fetchingApprovalsInterval.current = setInterval(() => {
74+
getPendingApprovals(authToken);
75+
}, FETCHING_PENDING_APPROVAL_EVENTS_INTERVAL);
76+
}
6177
}
78+
79+
return () => {
80+
if (fetchingApprovalsInterval.current) {
81+
clearInterval(fetchingApprovalsInterval.current);
82+
fetchingApprovalsInterval.current = null;
83+
}
84+
};
6285
}, [isAdmin]);
6386

6487
useEffect(() => {
@@ -73,7 +96,7 @@ function TimelineWallContainer(props) {
7396
}, [events]);
7497

7598
useEffect(() => {
76-
if ((pendingApprovals || []).length) {
99+
if (pendingApprovals.length) {
77100
_.uniqBy(pendingApprovals, 'createdBy').forEach((eventItem) => {
78101
const photoURL = _.get(userAvatars, eventItem.createdBy);
79102
if (!photoURL) {
@@ -229,8 +252,10 @@ function TimelineWallContainer(props) {
229252
/>
230253
<React.Fragment>
231254
{
232-
loading ? (
233-
<LoadingIndicator />
255+
loadingApprovals ? (
256+
<LoadingIndicator
257+
styleName={cn({ hide: tab === 0 })}
258+
/>
234259
) : (
235260
<PendingApprovals
236261
events={pendingApprovals}
@@ -256,6 +281,7 @@ TimelineWallContainer.defaultProps = {
256281
auth: null,
257282
isAdmin: false,
258283
loading: false,
284+
loadingApprovals: false,
259285
uploading: false,
260286
uploadResult: '',
261287
events: [],
@@ -270,6 +296,7 @@ TimelineWallContainer.propTypes = {
270296
auth: PT.shape(),
271297
isAdmin: PT.bool,
272298
loading: PT.bool,
299+
loadingApprovals: PT.bool,
273300
uploading: PT.bool,
274301
uploadResult: PT.string,
275302
events: PT.arrayOf(PT.shape()),
@@ -288,11 +315,13 @@ const mapStateToProps = state => ({
288315
},
289316
isAdmin: state.timelineWall.isAdmin,
290317
loading: state.timelineWall.loading,
318+
loadingApprovals: state.timelineWall.loadingApprovals
319+
&& !(state.timelineWall.pendingApprovals || []).length,
291320
uploading: state.timelineWall.uploading,
292321
uploadResult: state.timelineWall.uploadResult,
293322
events: state.timelineWall.events,
294323
userAvatars: state.timelineWall.userAvatars,
295-
pendingApprovals: state.timelineWall.pendingApprovals,
324+
pendingApprovals: state.timelineWall.pendingApprovals || [],
296325
});
297326

298327
function mapDispatchToProps(dispatch) {

src/shared/reducers/timelineWall.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ function onEventsDone(state, { payload }) {
6060
function onPendingApprovalInit(state) {
6161
return {
6262
...state,
63-
loading: true,
64-
pendingApprovals: [],
63+
loadingApprovals: true,
6564
};
6665
}
6766

@@ -74,7 +73,7 @@ function onPendingApprovalDone(state, { payload }) {
7473
const approvals = _.isArray(payload) ? payload : [];
7574
return {
7675
...state,
77-
loading: false,
76+
loadingApprovals: false,
7877
pendingApprovals: approvals,
7978
};
8079
}

0 commit comments

Comments
 (0)