Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ exports[`Matches shallow shapshot 2`] = `
Joining...
</span>
<ThemedLoadingIndicator
className=""
composeAdhocTheme="deeply"
composeContextTheme="softly"
mapThemrProps={[Function]}
Expand Down
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,5 +467,6 @@ module.exports = {
TIMELINE: {
REJECTION_EVENT_REASONS: ['Duplicate Event', 'Violates the Topcoder terms', 'Inaccurate or Invalid'],
ALLOWED_FILETYPES: ['image/jpeg', 'image/png', 'video/mp4', 'video/x-msvideo', 'video/webm'],
FETCHING_PENDING_APPROVAL_EVENTS_INTERVAL: 5 * 60 * 1000, // 5 minutes
},
};
10 changes: 8 additions & 2 deletions src/shared/components/LoadingIndicator/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import PT from 'prop-types';
import React from 'react';
import { themr } from 'react-css-super-themr';
import cn from 'classnames';
import style from './styles.scss';

const LoadingIndicator = ({ theme }) => (
const LoadingIndicator = ({ theme, className }) => (
<svg
className={theme.container}
className={cn(theme.container, className)}
viewBox="0 0 64 64"
>
<circle
Expand All @@ -32,8 +33,13 @@ const LoadingIndicator = ({ theme }) => (
</svg>
);

LoadingIndicator.defaultProps = {
className: '',
};

LoadingIndicator.propTypes = {
theme: PT.shape().isRequired,
className: PT.string,
};

export default themr('LoadingIndicator', style)(LoadingIndicator);
41 changes: 35 additions & 6 deletions src/shared/containers/timeline-wall/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { useState, useEffect, useMemo } from 'react';
import React, {
useState, useEffect, useRef, useMemo,
} from 'react';
import PT from 'prop-types';
import { connect } from 'react-redux';
import TopBanner from 'assets/images/timeline-wall/top-banner.png';
Expand All @@ -10,15 +12,19 @@ import cn from 'classnames';
import moment from 'moment';
import { useMediaQuery } from 'react-responsive';
import _ from 'lodash';
import { config } from 'topcoder-react-utils';
import timelineActions from 'actions/timelineWall';
import LoadingIndicator from 'components/LoadingIndicator';
import TimelineEvents from './timeline-events';
import PendingApprovals from './pending-approvals';

import './styles.scss';


const FETCHING_PENDING_APPROVAL_EVENTS_INTERVAL = _.get(config, 'TIMELINE.FETCHING_PENDING_APPROVAL_EVENTS_INTERVAL', 0);
function TimelineWallContainer(props) {
const [tab, setTab] = useState(0);
const fetchingApprovalsInterval = useRef(null);
const [showRightFilterMobile, setShowRightFilterMobile] = useState(false);
const [selectedFilterValue, setSelectedFilterValue] = useState({
year: 0,
Expand All @@ -37,6 +43,7 @@ function TimelineWallContainer(props) {
getAvatar,
userAvatars,
pendingApprovals,
loadingApprovals,
uploading,
uploadResult,
} = props;
Expand All @@ -56,9 +63,25 @@ function TimelineWallContainer(props) {
}, []);

useEffect(() => {
if (authToken && isAdmin && !pendingApprovals.length) {
if (fetchingApprovalsInterval.current) {
clearInterval(fetchingApprovalsInterval.current);
fetchingApprovalsInterval.current = null;
}
if (authToken && isAdmin) {
getPendingApprovals(authToken);
if (FETCHING_PENDING_APPROVAL_EVENTS_INTERVAL) {
fetchingApprovalsInterval.current = setInterval(() => {
getPendingApprovals(authToken);
}, FETCHING_PENDING_APPROVAL_EVENTS_INTERVAL);
}
}

return () => {
if (fetchingApprovalsInterval.current) {
clearInterval(fetchingApprovalsInterval.current);
fetchingApprovalsInterval.current = null;
}
};
}, [isAdmin]);

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

useEffect(() => {
if ((pendingApprovals || []).length) {
if (pendingApprovals.length) {
_.uniqBy(pendingApprovals, 'createdBy').forEach((eventItem) => {
const photoURL = _.get(userAvatars, eventItem.createdBy);
if (!photoURL) {
Expand Down Expand Up @@ -229,8 +252,10 @@ function TimelineWallContainer(props) {
/>
<React.Fragment>
{
loading ? (
<LoadingIndicator />
loadingApprovals ? (
<LoadingIndicator
styleName={cn({ hide: tab === 0 })}
/>
) : (
<PendingApprovals
events={pendingApprovals}
Expand All @@ -256,6 +281,7 @@ TimelineWallContainer.defaultProps = {
auth: null,
isAdmin: false,
loading: false,
loadingApprovals: false,
uploading: false,
uploadResult: '',
events: [],
Expand All @@ -270,6 +296,7 @@ TimelineWallContainer.propTypes = {
auth: PT.shape(),
isAdmin: PT.bool,
loading: PT.bool,
loadingApprovals: PT.bool,
uploading: PT.bool,
uploadResult: PT.string,
events: PT.arrayOf(PT.shape()),
Expand All @@ -288,11 +315,13 @@ const mapStateToProps = state => ({
},
isAdmin: state.timelineWall.isAdmin,
loading: state.timelineWall.loading,
loadingApprovals: state.timelineWall.loadingApprovals
&& !(state.timelineWall.pendingApprovals || []).length,
uploading: state.timelineWall.uploading,
uploadResult: state.timelineWall.uploadResult,
events: state.timelineWall.events,
userAvatars: state.timelineWall.userAvatars,
pendingApprovals: state.timelineWall.pendingApprovals,
pendingApprovals: state.timelineWall.pendingApprovals || [],
});

function mapDispatchToProps(dispatch) {
Expand Down
5 changes: 2 additions & 3 deletions src/shared/reducers/timelineWall.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ function onEventsDone(state, { payload }) {
function onPendingApprovalInit(state) {
return {
...state,
loading: true,
pendingApprovals: [],
loadingApprovals: true,
};
}

Expand All @@ -74,7 +73,7 @@ function onPendingApprovalDone(state, { payload }) {
const approvals = _.isArray(payload) ? payload : [];
return {
...state,
loading: false,
loadingApprovals: false,
pendingApprovals: approvals,
};
}
Expand Down