5
5
6
6
import actions from 'actions/challenge-listing/filter-panel' ;
7
7
import challengeListingActions from 'actions/challenge-listing' ;
8
+ import communityActions from 'actions/tc-communities' ;
9
+ import shortId from 'shortid' ;
8
10
import FilterPanel from 'components/challenge-listing/Filters/ChallengeFilters' ;
9
11
import PT from 'prop-types' ;
10
12
import React from 'react' ;
@@ -18,6 +20,7 @@ import qs from 'qs';
18
20
* number will be appended to it, when necessary, to keep filter
19
21
* names unique. */
20
22
const DEFAULT_SAVED_FILTER_NAME = 'My Filter' ;
23
+ const MIN = 60 * 1000 ;
21
24
22
25
/**
23
26
* Returns a vacant name for the user saved filter.
@@ -44,7 +47,15 @@ export class Container extends React.Component {
44
47
loadingSubtracks,
45
48
setFilterState,
46
49
filterState,
50
+ communityList,
51
+ getCommunityList,
52
+ auth,
47
53
} = this . props ;
54
+
55
+ if ( communityList && ! communityList . loadingUuid
56
+ && ( Date . now ( ) - communityList . timestamp > 5 * MIN ) ) {
57
+ getCommunityList ( auth ) ;
58
+ }
48
59
if ( ! loadingSubtracks ) getSubtracks ( ) ;
49
60
if ( ! loadingKeywords ) getKeywords ( ) ;
50
61
@@ -119,6 +130,15 @@ Container.propTypes = {
119
130
activeBucket : PT . string . isRequired ,
120
131
communityFilters : PT . arrayOf ( PT . object ) . isRequired ,
121
132
defaultCommunityId : PT . string . isRequired ,
133
+ getCommunityList : PT . func . isRequired ,
134
+ communityList : PT . shape ( {
135
+ data : PT . arrayOf ( PT . shape ( {
136
+ communityId : PT . string . isRequired ,
137
+ communityName : PT . string . isRequired ,
138
+ } ) ) . isRequired ,
139
+ loadingUuid : PT . string . isRequired ,
140
+ timestamp : PT . number . isRequired ,
141
+ } ) . isRequired ,
122
142
filterState : PT . shape ( ) . isRequired ,
123
143
challenges : PT . arrayOf ( PT . shape ( ) ) ,
124
144
selectedCommunityId : PT . string . isRequired ,
@@ -145,6 +165,11 @@ function mapDispatchToProps(dispatch) {
145
165
dispatch ( cla . getChallengeSubtracksInit ( ) ) ;
146
166
dispatch ( cla . getChallengeSubtracksDone ( ) ) ;
147
167
} ,
168
+ getCommunityList : ( auth ) => {
169
+ const uuid = shortId ( ) ;
170
+ dispatch ( communityActions . tcCommunity . getListInit ( uuid ) ) ;
171
+ dispatch ( communityActions . tcCommunity . getListDone ( uuid , auth ) ) ;
172
+ } ,
148
173
getKeywords : ( ) => {
149
174
dispatch ( cla . getChallengeTagsInit ( ) ) ;
150
175
dispatch ( cla . getChallengeTagsDone ( ) ) ;
@@ -167,6 +192,7 @@ function mapStateToProps(state, ownProps) {
167
192
...state . challengeListing . filterPanel ,
168
193
activeBucket : cl . sidebar . activeBucket ,
169
194
communityFilters : tc . list . data ,
195
+ communityList : tc . list ,
170
196
defaultCommunityId : ownProps . defaultCommunityId ,
171
197
filterState : cl . filter ,
172
198
loadingKeywords : cl . loadingChallengeTags ,
0 commit comments